From 16cd7458167d8523c00046f9b95bb04acd66c499 Mon Sep 17 00:00:00 2001 From: sam edelsten <samedelsten1@gmail.com> Date: Wed, 25 Oct 2023 08:03:12 +0100 Subject: [PATCH] use ButtonBundle for UI layout --- examples/basic_ui.rs | 19 ++++++++-------- examples/bevy_api_testing.rs | 19 +++++++--------- examples/every_option.rs | 23 +++++++++----------- examples/font_per_widget.rs | 26 +++++++++------------- examples/image_background.rs | 19 +++++++--------- examples/readonly.rs | 13 +++++------ examples/text_input.rs | 42 ++++++++++++++++-------------------- src/lib.rs | 20 ----------------- 8 files changed, 68 insertions(+), 113 deletions(-) diff --git a/examples/basic_ui.rs b/examples/basic_ui.rs index 6630283..1688f79 100644 --- a/examples/basic_ui.rs +++ b/examples/basic_ui.rs @@ -1,7 +1,7 @@ use bevy::{core_pipeline::clear_color::ClearColorConfig, prelude::*, window::PrimaryWindow}; use bevy_cosmic_edit::{ - AttrsOwned, CosmicAttrs, CosmicEditBundle, CosmicEditPlugin, CosmicEditUiBundle, CosmicEditor, - CosmicFontConfig, CosmicMetrics, CosmicText, CosmicTextPosition, Focus, + AttrsOwned, CosmicAttrs, CosmicEditBundle, CosmicEditPlugin, CosmicEditor, CosmicFontConfig, + CosmicMetrics, CosmicText, CosmicTextPosition, Focus, }; fn setup(mut commands: Commands, windows: Query<&Window, With<PrimaryWindow>>) { @@ -32,16 +32,15 @@ fn setup(mut commands: Commands, windows: Query<&Window, With<PrimaryWindow>>) { text_setter: CosmicText::OneStyle("馃榾馃榾馃榾 x => y".to_string()), ..default() }, - CosmicEditUiBundle { - node_bundle: NodeBundle { - style: Style { - width: Val::Percent(100.), - height: Val::Percent(100.), - ..default() - }, - background_color: Color::WHITE.into(), + // Use buttonbundle for layout + ButtonBundle { + style: Style { + width: Val::Percent(100.), + height: Val::Percent(100.), ..default() }, + // Needs to be set to prevent a bug where nothing is displayed + background_color: Color::WHITE.into(), ..default() }, ); diff --git a/examples/bevy_api_testing.rs b/examples/bevy_api_testing.rs index 4d1b1a8..892ccb0 100644 --- a/examples/bevy_api_testing.rs +++ b/examples/bevy_api_testing.rs @@ -13,20 +13,17 @@ fn setup(mut commands: Commands) { max_lines: CosmicMaxLines(1), ..default() }) - .insert(CosmicEditUiBundle { - node_bundle: NodeBundle { - style: Style { - // Size and position of text box - width: Val::Px(300.), - height: Val::Px(50.), - left: Val::Px(100.), - top: Val::Px(100.), - ..default() - }, + .insert(ButtonBundle { + style: Style { + // Size and position of text box + width: Val::Px(300.), + height: Val::Px(50.), + left: Val::Px(100.), + top: Val::Px(100.), // needs to be set to prevent a bug where nothing is displayed - background_color: BackgroundColor(Color::WHITE), ..default() }, + background_color: BackgroundColor(Color::WHITE), ..default() }) .insert(CosmicEditPlaceholderBundle { diff --git a/examples/every_option.rs b/examples/every_option.rs index edc58f2..28dbbae 100644 --- a/examples/every_option.rs +++ b/examples/every_option.rs @@ -28,21 +28,18 @@ fn setup(mut commands: Commands, windows: Query<&Window, With<PrimaryWindow>>) { mode: CosmicMode::Wrap, canvas: Default::default(), }) - .insert(CosmicEditUiBundle { - node_bundle: NodeBundle { - border_color: Color::LIME_GREEN.into(), - style: Style { - // Size and position of text box - border: UiRect::all(Val::Px(4.)), - width: Val::Percent(20.), - height: Val::Px(50.), - left: Val::Percent(40.), - top: Val::Px(100.), - ..default() - }, - background_color: Color::WHITE.into(), + .insert(ButtonBundle { + border_color: Color::LIME_GREEN.into(), + style: Style { + // Size and position of text box + border: UiRect::all(Val::Px(4.)), + width: Val::Percent(20.), + height: Val::Px(50.), + left: Val::Percent(40.), + top: Val::Px(100.), ..default() }, + background_color: Color::WHITE.into(), ..default() }) .insert(CosmicEditPlaceholderBundle { diff --git a/examples/font_per_widget.rs b/examples/font_per_widget.rs index fa74f1e..a5cc79f 100644 --- a/examples/font_per_widget.rs +++ b/examples/font_per_widget.rs @@ -219,16 +219,13 @@ fn setup(mut commands: Commands, windows: Query<&Window, With<PrimaryWindow>>) { text_setter: CosmicText::MultiStyle(lines), ..default() }, - CosmicEditUiBundle { - node_bundle: NodeBundle { - style: Style { - width: Val::Percent(50.), - height: Val::Percent(100.), - ..default() - }, - background_color: BackgroundColor(Color::WHITE), + ButtonBundle { + style: Style { + width: Val::Percent(50.), + height: Val::Percent(100.), ..default() }, + background_color: BackgroundColor(Color::WHITE), ..default() }, ); @@ -249,14 +246,11 @@ fn setup(mut commands: Commands, windows: Query<&Window, With<PrimaryWindow>>) { text_setter: CosmicText::OneStyle("Widget 2.\nClick on me =>".to_string()), ..default() }, - CosmicEditUiBundle { - node_bundle: NodeBundle { - background_color: BackgroundColor(Color::WHITE.with_a(0.8)), - style: Style { - width: Val::Percent(50.), - height: Val::Percent(100.), - ..default() - }, + ButtonBundle { + background_color: BackgroundColor(Color::WHITE.with_a(0.8)), + style: Style { + width: Val::Percent(50.), + height: Val::Percent(100.), ..default() }, ..default() diff --git a/examples/image_background.rs b/examples/image_background.rs index 8f2d994..8d700ae 100644 --- a/examples/image_background.rs +++ b/examples/image_background.rs @@ -14,19 +14,16 @@ fn setup(mut commands: Commands, asset_server: Res<AssetServer>) { background_image: CosmicBackground(Some(bg_image_handle)), ..default() }) - .insert(CosmicEditUiBundle { - node_bundle: NodeBundle { - style: Style { - // Size and position of text box - width: Val::Px(300.), - height: Val::Px(50.), - left: Val::Px(100.), - top: Val::Px(100.), - ..default() - }, - background_color: Color::WHITE.into(), + .insert(ButtonBundle { + style: Style { + // Size and position of text box + width: Val::Px(300.), + height: Val::Px(50.), + left: Val::Px(100.), + top: Val::Px(100.), ..default() }, + background_color: Color::WHITE.into(), ..default() }) .id(); diff --git a/examples/readonly.rs b/examples/readonly.rs index 118cdfe..e218b09 100644 --- a/examples/readonly.rs +++ b/examples/readonly.rs @@ -32,16 +32,13 @@ fn setup(mut commands: Commands, windows: Query<&Window, With<PrimaryWindow>>) { text_setter: CosmicText::OneStyle("馃榾馃榾馃榾 x => y\nRead only widget".to_string()), ..default() }, - CosmicEditUiBundle { - node_bundle: NodeBundle { - style: Style { - width: Val::Percent(100.), - height: Val::Percent(100.), - ..default() - }, - background_color: BackgroundColor(Color::WHITE), + ButtonBundle { + style: Style { + width: Val::Percent(100.), + height: Val::Percent(100.), ..default() }, + background_color: BackgroundColor(Color::WHITE), ..default() }, ); diff --git a/examples/text_input.rs b/examples/text_input.rs index 0b0f45e..7ba06f1 100644 --- a/examples/text_input.rs +++ b/examples/text_input.rs @@ -24,20 +24,17 @@ fn create_editable_widget(commands: &mut Commands, scale_factor: f32, text: Stri mode: CosmicMode::InfiniteLine, ..default() }, - CosmicEditUiBundle { - node_bundle: NodeBundle { - border_color: Color::hex("#ededed").unwrap().into(), - style: Style { - border: UiRect::all(Val::Px(3.)), - width: Val::Percent(20.), - height: Val::Px(50.), - left: Val::Percent(40.), - top: Val::Px(100.), - ..default() - }, - background_color: Color::WHITE.into(), + ButtonBundle { + border_color: Color::hex("#ededed").unwrap().into(), + style: Style { + border: UiRect::all(Val::Px(3.)), + width: Val::Percent(20.), + height: Val::Px(50.), + left: Val::Percent(40.), + top: Val::Px(100.), ..default() }, + background_color: Color::WHITE.into(), ..default() }, CosmicEditPlaceholderBundle { @@ -65,20 +62,17 @@ fn create_readonly_widget(commands: &mut Commands, scale_factor: f32, text: Stri mode: CosmicMode::AutoHeight, ..default() }, - CosmicEditUiBundle { - node_bundle: NodeBundle { - border_color: Color::hex("#ededed").unwrap().into(), - style: Style { - border: UiRect::all(Val::Px(3.)), - width: Val::Percent(20.), - height: Val::Px(50.), - left: Val::Percent(40.), - top: Val::Px(100.), - ..default() - }, - background_color: Color::WHITE.into(), + ButtonBundle { + border_color: Color::hex("#ededed").unwrap().into(), + style: Style { + border: UiRect::all(Val::Px(3.)), + width: Val::Percent(20.), + height: Val::Px(50.), + left: Val::Percent(40.), + top: Val::Px(100.), ..default() }, + background_color: Color::WHITE.into(), ..default() }, ReadOnly, diff --git a/src/lib.rs b/src/lib.rs index 9cc36b2..a13ee14 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -232,26 +232,6 @@ pub struct CosmicEditBundle { pub canvas: CosmicCanvas, } -#[derive(Bundle)] -pub struct CosmicEditUiBundle { - pub node_bundle: NodeBundle, - pub image: UiImage, - pub interaction: Interaction, -} - -impl Default for CosmicEditUiBundle { - fn default() -> Self { - Self { - node_bundle: NodeBundle { - background_color: BackgroundColor(Color::WHITE), - ..default() - }, - image: Default::default(), - interaction: Default::default(), - } - } -} - #[derive(Bundle)] pub struct CosmicEditPlaceholderBundle { /// set this to update placeholder text -- GitLab