Skip to content

Commit

Permalink
rebase fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
UkoeHB committed Oct 4, 2024
1 parent df31682 commit 140d5cd
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 53 deletions.
73 changes: 33 additions & 40 deletions examples/animation/animation_masks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,18 +157,15 @@ fn setup_scene(
// Creates the UI.
fn setup_ui(mut commands: Commands) {
// Add help text.
commands.spawn(
TextBundle::from_section(
"Click on a button to toggle animations for its associated bones",
TextStyle::default(),
)
.with_style(Style {
commands.spawn((
TextNEW::new("Click on a button to toggle animations for its associated bones"),
Style {
position_type: PositionType::Absolute,
left: Val::Px(12.0),
top: Val::Px(12.0),
..default()
}),
);
},
));

// Add the buttons that allow the user to toggle mask groups on and off.
commands
Expand Down Expand Up @@ -287,14 +284,14 @@ fn add_mask_group_control(parent: &mut ChildBuilder, label: &str, width: Val, ma
background_color: Color::BLACK.into(),
..default()
})
.with_child(TextBundle {
text: Text::from_section(label, label_text_style.clone()),
style: Style {
.with_child((
TextNEW::new(label),
label_text_style.clone(),
Style {
margin: UiRect::vertical(Val::Px(3.0)),
..default()
},
..default()
});
));

builder
.spawn(NodeBundle {
Expand Down Expand Up @@ -338,29 +335,24 @@ fn add_mask_group_control(parent: &mut ChildBuilder, label: &str, width: Val, ma
border_color: BorderColor(Color::WHITE),
..default()
})
.with_child(
TextBundle {
style: Style {
flex_grow: 1.0,
margin: UiRect::vertical(Val::Px(3.0)),
..default()
},
text: Text::from_section(
format!("{:?}", label),
if index > 0 {
button_text_style.clone()
} else {
selected_button_text_style.clone()
},
),
.with_child((
TextNEW(format!("{:?}", label)),
if index > 0 {
button_text_style.clone()
} else {
selected_button_text_style.clone()
},
TextBlock::new_with_justify(JustifyText::Center),
Style {
flex_grow: 1.0,
margin: UiRect::vertical(Val::Px(3.0)),
..default()
}
.with_text_justify(JustifyText::Center),
)
.insert(AnimationControl {
group_id: mask_group_id,
label: *label,
});
},
AnimationControl {
group_id: mask_group_id,
label: *label,
},
));
}
});
});
Expand Down Expand Up @@ -481,7 +473,8 @@ fn handle_button_toggles(
// A system that updates the UI based on the current app state.
fn update_ui(
mut animation_controls: Query<(&AnimationControl, &mut BackgroundColor, &Children)>,
mut texts: Query<&mut Text>,
texts: Query<Entity, With<TextNEW>>,
mut writer: UiTextWriter,
app_state: Res<AppState>,
) {
for (animation_control, mut background_color, kids) in animation_controls.iter_mut() {
Expand All @@ -495,13 +488,13 @@ fn update_ui(
};

for &kid in kids {
let Ok(mut text) = texts.get_mut(kid) else {
let Ok(text) = texts.get(kid) else {
continue;
};

for section in &mut text.sections {
section.style.color = if enabled { Color::BLACK } else { Color::WHITE };
}
writer.for_each_style(text, |mut style| {
style.color = if enabled { Color::BLACK } else { Color::WHITE };
});
}
}
}
Expand Down
29 changes: 16 additions & 13 deletions examples/picking/simple_picking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,15 @@ fn setup(
mut materials: ResMut<Assets<StandardMaterial>>,
) {
commands
.spawn(TextBundle {
text: Text::from_section("Click Me to get a box", TextStyle::default()),
style: Style {
.spawn((
TextNEW::new("Click Me to get a box"),
Style {
position_type: PositionType::Absolute,
top: Val::Percent(12.0),
left: Val::Percent(12.0),
..default()
},
..Default::default()
})
))
.observe(
|_click: Trigger<Pointer<Click>>,
mut commands: Commands,
Expand All @@ -42,14 +41,18 @@ fn setup(
*num += 1;
},
)
.observe(|evt: Trigger<Pointer<Out>>, mut texts: Query<&mut Text>| {
let mut text = texts.get_mut(evt.entity()).unwrap();
text.sections[0].style.color = WHITE.into();
})
.observe(|evt: Trigger<Pointer<Over>>, mut texts: Query<&mut Text>| {
let mut text = texts.get_mut(evt.entity()).unwrap();
text.sections[0].style.color = BLUE.into();
});
.observe(
|evt: Trigger<Pointer<Out>>, mut texts: Query<&mut TextStyle>| {
let mut style = texts.get_mut(evt.entity()).unwrap();
style.color = WHITE.into();
},
)
.observe(
|evt: Trigger<Pointer<Over>>, mut texts: Query<&mut TextStyle>| {
let mut style = texts.get_mut(evt.entity()).unwrap();
style.color = BLUE.into();
},
);
// circular base
commands.spawn((
Mesh3d(meshes.add(Circle::new(4.0))),
Expand Down

0 comments on commit 140d5cd

Please sign in to comment.