Skip to content

Commit

Permalink
mark: only every_option example to go
Browse files Browse the repository at this point in the history
  • Loading branch information
ActuallyHappening committed Dec 5, 2024
1 parent fe5bbe0 commit 72ff489
Show file tree
Hide file tree
Showing 7 changed files with 76 additions and 118 deletions.
70 changes: 28 additions & 42 deletions examples/font_per_widget.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,57 +156,43 @@ fn setup(mut commands: Commands, mut font_system: ResMut<CosmicFontSystem>) {
),
];

let cosmic_edit_1 =
commands
.spawn(CosmicEditBundle {
buffer: CosmicEditBuffer::new(&mut font_system, Metrics::new(18., 22.))
.with_rich_text(&mut font_system, lines, attrs),
commands.entity(root).with_children(|parent| {
parent.spawn((
CosmicEditBuffer::new(&mut font_system, Metrics::new(18., 22.)).with_rich_text(
&mut font_system,
lines,
attrs,
),
ImageNode::default(),
Button,
Node {
width: Val::Percent(50.),
height: Val::Percent(100.),
..default()
})
.id();
},
BackgroundColor(Color::WHITE),
));
});

let mut attrs_2 = Attrs::new();
attrs_2 = attrs_2.family(Family::Name("Times New Roman"));
attrs_2.color_opt = Some(bevy::color::palettes::css::PURPLE.to_cosmic());

let cosmic_edit_2 = commands
.spawn(CosmicEditBundle {
buffer: CosmicEditBuffer::new(&mut font_system, Metrics::new(28., 36.)).with_text(
commands.entity(root).with_children(|parent| {
parent.spawn((
CosmicEditBuffer::new(&mut font_system, Metrics::new(28., 36.)).with_text(
&mut font_system,
"Widget 2.\nClick on me =>",
attrs_2,
),
..default()
})
.id();

// Spawn the CosmicEditUiBundles as children of root
commands.entity(root).with_children(|parent| {
parent
.spawn((
ImageNode::default(),
Button,
Node {
width: Val::Percent(50.),
height: Val::Percent(100.),
..default()
},
BackgroundColor(Color::WHITE),
))
.insert(CosmicSource(cosmic_edit_1));

parent
.spawn((
ImageNode::default(),
Button,
Node {
width: Val::Percent(50.),
height: Val::Percent(100.),
..default()
},
BackgroundColor(Color::WHITE.with_alpha(0.8)),
))
.insert(CosmicSource(cosmic_edit_2));
ImageNode::default(),
Button,
Node {
width: Val::Percent(50.),
height: Val::Percent(100.),
..default()
},
BackgroundColor(Color::WHITE.with_alpha(0.8)),
));
});
}

Expand Down
39 changes: 16 additions & 23 deletions examples/image_background.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,30 +10,23 @@ fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {

let bg_image_handle = asset_server.load("img/bevy_logo_light.png");

let editor = commands
.spawn(CosmicEditBundle {
default_attrs: DefaultAttrs(AttrsOwned::new(
Attrs::new().color(bevy::color::palettes::basic::LIME.to_cosmic()),
)),
background_image: CosmicBackgroundImage(Some(bg_image_handle)),
commands.spawn((
CosmicEditBuffer::default(),
DefaultAttrs(AttrsOwned::new(
Attrs::new().color(bevy::color::palettes::basic::LIME.to_cosmic()),
)),
CosmicBackgroundImage(Some(bg_image_handle)),
Node {
// Size and position of text box
width: Val::Px(300.),
height: Val::Px(50.),
left: Val::Px(100.),
top: Val::Px(100.),
..default()
})
.id();

commands
.spawn((
Node {
// Size and position of text box
width: Val::Px(300.),
height: Val::Px(50.),
left: Val::Px(100.),
top: Val::Px(100.),
..default()
},
ImageNode::default(),
Button,
))
.insert(CosmicSource(editor));
},
ImageNode::default(),
Button,
));
}

fn main() {
Expand Down
54 changes: 22 additions & 32 deletions examples/multiple_sprites.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,44 +25,34 @@ fn setup(
attrs = attrs.color(bevy::color::palettes::basic::PURPLE.to_cosmic());

commands.spawn((
CosmicEditBundle {
fill_color: CosmicBackgroundColor(bevy::color::palettes::css::ALICE_BLUE.into()),
buffer: CosmicEditBuffer::new(&mut font_system, Metrics::new(14., 18.)).with_text(
&mut font_system,
"😀😀😀 x => y",
attrs,
),
sprite: Sprite {
custom_size: Some(Vec2 {
x: primary_window.width() / 2.,
y: primary_window.height(),
}),
..default()
},
visibility: Visibility::Inherited,
CosmicEditBuffer::new(&mut font_system, Metrics::new(14., 18.)).with_text(
&mut font_system,
"😀😀😀 x => y",
attrs,
),
CosmicBackgroundColor(bevy::color::palettes::css::ALICE_BLUE.into()),
Sprite {
custom_size: Some(Vec2 {
x: primary_window.width() / 2.,
y: primary_window.height(),
}),
..default()
},
Transform::from_translation(Vec3::new(-primary_window.width() / 4., 0., 1.)),
));

commands.spawn((
CosmicEditBundle {
fill_color: CosmicBackgroundColor(
bevy::color::palettes::basic::GRAY.with_alpha(0.5).into(),
),
buffer: CosmicEditBuffer::new(&mut font_system, Metrics::new(14., 18.)).with_text(
&mut font_system,
"Widget_2. Click on me",
attrs,
),
sprite: Sprite {
custom_size: Some(Vec2 {
x: primary_window.width() / 2.,
y: primary_window.height() / 2.,
}),
..default()
},
visibility: Visibility::Inherited,
CosmicEditBuffer::new(&mut font_system, Metrics::new(14., 18.)).with_text(
&mut font_system,
"Widget_2. Click on me",
attrs,
),
CosmicBackgroundColor(bevy::color::palettes::basic::GRAY.with_alpha(0.5).into()),
Sprite {
custom_size: Some(Vec2 {
x: primary_window.width() / 2.,
y: primary_window.height() / 2.,
}),
..default()
},
Transform::from_translation(Vec3::new(
Expand Down
15 changes: 6 additions & 9 deletions examples/password.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,12 @@ fn setup(mut commands: Commands) {

// Sprite editor
commands.spawn((
CosmicEditBundle {
max_lines: MaxLines(1),
mode: CosmicWrap::InfiniteLine,
// Sets size of text box
sprite: Sprite {
custom_size: Some(Vec2::new(300., 100.)),
..default()
},
visibility: Visibility::Visible,
CosmicEditBuffer::default(),
MaxLines(1),
CosmicWrap::InfiniteLine,
// Sets size of text box
Sprite {
custom_size: Some(Vec2::new(300., 100.)),
..default()
},
// Position of text box
Expand Down
10 changes: 1 addition & 9 deletions examples/readonly.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ fn setup(mut commands: Commands, mut font_system: ResMut<CosmicFontSystem>) {
..default()
},
BackgroundColor(Color::WHITE),
Name::new("Readonly editor"),
));
}

Expand All @@ -42,13 +41,6 @@ fn main() {
.add_plugins(DefaultPlugins)
.add_plugins(CosmicEditPlugin { font_config })
.add_systems(Startup, setup)
.add_systems(
Update,
(
change_active_editor_ui,
deselect_editor_on_esc,
print_editor_sizes,
),
)
.add_systems(Update, (change_active_editor_ui, deselect_editor_on_esc))
.run();
}
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ pub mod prelude {
pub use crate::primary::{CosmicEditPlugin, CosmicFontConfig, CosmicPrimaryCamera};
pub use crate::utils::{
change_active_editor_sprite, change_active_editor_ui, deselect_editor_on_esc,
print_editor_sizes, print_editor_text, ColorExtras as _,
print_editor_text, ColorExtras as _,
};
#[doc(no_inline)]
pub use bevy::text::cosmic_text::{
Expand Down
4 changes: 2 additions & 2 deletions src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ pub fn print_editor_text(

/// Quick utility to print the name of an entity if available
#[derive(QueryData)]
pub struct DebugName {
pub(in crate::utils) struct DebugName {
name: Option<&'static Name>,
entity: Entity,
}
Expand All @@ -169,7 +169,7 @@ impl std::fmt::Debug for DebugNameItem<'_> {
}
}

pub fn print_editor_sizes(
pub(in crate::utils) fn print_editor_sizes(
editors: Query<
(CosmicWidgetSize, DebugName),
(With<CosmicEditBuffer>, ChangedCosmicWidgetSize),
Expand Down

0 comments on commit 72ff489

Please sign in to comment.