pub fn button_system(
    button_materials: Res<ButtonStyle>,
    mut interaction_query: Query<
        (&Interaction, &mut Handle<ColorMaterial>, &Children),
        (Changed<Interaction>, With<Button>),
    >,
    mut text_query: Query<&mut Text>,
) {
    for (interaction, mut material, children) in interaction_query.iter_mut() {
        let mut text = text_query.get_mut(children[0]).unwrap();
        match *interaction {
            Interaction::Clicked => {
                text.sections[0].value = "Press".to_string();
                *material = button_materials.material_pressed.clone();
            }
            Interaction::Hovered => {
                *material = button_materials.material_hovered.clone();
            }
            Interaction::None => {
                *material = button_materials.material_normal.clone();
            }
        }
    }
}
/// Handles the state transition (think colors) of buttons
Handles the state transition (think colors) of buttons
Handles the state transition ( think colors ) of buttons
pub fn button_system(
    button_materials: Res<ButtonStyle>,
    mut interaction_query: Query<
        (&Interaction, &mut Handle<ColorMaterial>, &Children),
        (Changed<Interaction>, With<Button>),
    >,
    mut text_query: Query<&mut Text>,
) {
    for (interaction, mut material, children) in interaction_query.iter_mut() {
        let mut text = text_query.get_mut(children[0]).unwrap();
        match *interaction {
            Interaction::Clicked => {
                text.sections[0].value = "Press".to_string();
                *material = button_materials.material_pressed.clone();
            }
            Interaction::Hovered => {
                *material = button_materials.material_hovered.clone();
            }
            Interaction::None => {
                *material = button_materials.material_normal.clone();
            }
        }
    }
}
pub fn button_system ( button_materials : Res < ButtonStyle > , mut interaction_query : Query < ( & Interaction , & mut Handle < ColorMaterial > , & Children ) , ( Changed < Interaction > , With < Button > ) , > , mut text_query : Query < & mut Text > , ) { for ( interaction , mut material , children ) in interaction_query . iter_mut ( ) { let mut text = text_query . get_mut ( children [ 0 ] ) . unwrap ( ) ; match * interaction { Interaction :: Clicked => { text . sections [ 0 ] . value = " " . to_string ( ) ; * material = button_materials . material_pressed . clone ( ) ; } Interaction :: Hovered => { * material = button_materials . material_hovered . clone ( ) ; } Interaction :: None => { * material = button_materials . material_normal . clone ( ) ; } } } }
Handles the state transition (think colors) of buttons
Handles the state transition ( think colors ) of buttons
button_materials
Res<ButtonStyle>
interaction_query
Query<
        (&Interaction, &mut Handle<ColorMaterial>, &Children),
        (Changed<Interaction>, With<Button>),
    >
text_query
Query<&mut Text>
button_materials
Res<ButtonStyle>
interaction_query
Query<
        (&Interaction, &mut Handle<ColorMaterial>, &Children),
        (Changed<Interaction>, With<Button>),
    >
text_query
Query<&mut Text>