From 9034a0297bf707a56f3f0387b9aa981f0d55a5b7 Mon Sep 17 00:00:00 2001 From: StaffEngineer <velo.app1@gmail.com> Date: Wed, 4 Oct 2023 12:27:11 +0100 Subject: [PATCH] style example a bit --- examples/text_input.rs | 31 +++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/examples/text_input.rs b/examples/text_input.rs index 5c83d7b..75d5ee3 100644 --- a/examples/text_input.rs +++ b/examples/text_input.rs @@ -2,12 +2,13 @@ use bevy::{prelude::*, window::PrimaryWindow}; use bevy_cosmic_edit::*; fn create_editable_widget(commands: &mut Commands, scale_factor: f32, text: String) -> Entity { - let attrs = AttrsOwned::new(Attrs::new().color(CosmicColor::rgb(0, 0, 0))); + let attrs = + AttrsOwned::new(Attrs::new().color(bevy_color_to_cosmic(Color::hex("4d4d4d").unwrap()))); commands .spawn(CosmicEditUiBundle { - border_color: Color::LIME_GREEN.into(), + border_color: Color::hex("#ededed").unwrap().into(), style: Style { - border: UiRect::all(Val::Px(4.)), + border: UiRect::all(Val::Px(3.)), width: Val::Percent(20.), height: Val::Px(50.), left: Val::Percent(40.), @@ -16,8 +17,8 @@ fn create_editable_widget(commands: &mut Commands, scale_factor: f32, text: Stri }, cosmic_attrs: CosmicAttrs(attrs.clone()), cosmic_metrics: CosmicMetrics { - font_size: 16., - line_height: 16., + font_size: 18., + line_height: 18. * 1.2, scale_factor, }, max_lines: CosmicMaxLines(1), @@ -30,13 +31,14 @@ fn create_editable_widget(commands: &mut Commands, scale_factor: f32, text: Stri } fn create_readonly_widget(commands: &mut Commands, scale_factor: f32, text: String) -> Entity { - let attrs = AttrsOwned::new(Attrs::new().color(CosmicColor::rgb(0, 0, 0))); + let attrs = + AttrsOwned::new(Attrs::new().color(bevy_color_to_cosmic(Color::hex("4d4d4d").unwrap()))); commands .spawn(( CosmicEditUiBundle { - border_color: Color::LIME_GREEN.into(), + border_color: Color::hex("#ededed").unwrap().into(), style: Style { - border: UiRect::all(Val::Px(4.)), + border: UiRect::all(Val::Px(3.)), width: Val::Percent(20.), height: Val::Px(50.), left: Val::Percent(40.), @@ -45,8 +47,8 @@ fn create_readonly_widget(commands: &mut Commands, scale_factor: f32, text: Stri }, cosmic_attrs: CosmicAttrs(attrs.clone()), cosmic_metrics: CosmicMetrics { - font_size: 16., - line_height: 16., + font_size: 18., + line_height: 18. * 1.2, scale_factor, }, text_setter: CosmicText::OneStyle(text), @@ -92,6 +94,15 @@ fn handle_enter( } } +fn bevy_color_to_cosmic(color: bevy::prelude::Color) -> CosmicColor { + cosmic_text::Color::rgba( + (color.r() * 255.) as u8, + (color.g() * 255.) as u8, + (color.b() * 255.) as u8, + (color.a() * 255.) as u8, + ) +} + fn main() { App::new() .add_plugins(DefaultPlugins) -- GitLab