From 140d5cd0a502d6a2f6dcc053ffccc498631b9cbe Mon Sep 17 00:00:00 2001 From: koe Date: Fri, 4 Oct 2024 18:12:24 -0500 Subject: [PATCH] rebase fixes --- examples/animation/animation_masks.rs | 73 ++++++++++++--------------- examples/picking/simple_picking.rs | 29 ++++++----- 2 files changed, 49 insertions(+), 53 deletions(-) diff --git a/examples/animation/animation_masks.rs b/examples/animation/animation_masks.rs index 4a9177074dd062..75605c55e5a95e 100644 --- a/examples/animation/animation_masks.rs +++ b/examples/animation/animation_masks.rs @@ -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 @@ -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 { @@ -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, + }, + )); } }); }); @@ -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>, + mut writer: UiTextWriter, app_state: Res, ) { for (animation_control, mut background_color, kids) in animation_controls.iter_mut() { @@ -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 }; + }); } } } diff --git a/examples/picking/simple_picking.rs b/examples/picking/simple_picking.rs index a2cf63c611b13f..46eab070facc98 100644 --- a/examples/picking/simple_picking.rs +++ b/examples/picking/simple_picking.rs @@ -18,16 +18,15 @@ fn setup( mut materials: ResMut>, ) { 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>, mut commands: Commands, @@ -42,14 +41,18 @@ fn setup( *num += 1; }, ) - .observe(|evt: Trigger>, mut texts: Query<&mut Text>| { - let mut text = texts.get_mut(evt.entity()).unwrap(); - text.sections[0].style.color = WHITE.into(); - }) - .observe(|evt: Trigger>, mut texts: Query<&mut Text>| { - let mut text = texts.get_mut(evt.entity()).unwrap(); - text.sections[0].style.color = BLUE.into(); - }); + .observe( + |evt: Trigger>, mut texts: Query<&mut TextStyle>| { + let mut style = texts.get_mut(evt.entity()).unwrap(); + style.color = WHITE.into(); + }, + ) + .observe( + |evt: Trigger>, 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))),