From 8d66f4a09444beb26d64537f9f235dbed6773e15 Mon Sep 17 00:00:00 2001 From: IDEDARY Date: Mon, 8 Jul 2024 22:09:01 +0200 Subject: [PATCH 1/3] Update Cargo.toml --- Cargo.toml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 8e6c1a6..8ce87a7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -41,5 +41,5 @@ "bevy_gizmos", ] } - bevy_kira_audio = { version = "^0.20.0-rc.1" } - bevy_mod_picking = { version = "^0.20.0-rc.0", default_features = false, features = ["selection", "backend_raycast"] } \ No newline at end of file + bevy_kira_audio = { version = "^0.20.0" } + bevy_mod_picking = { version = "^0.20.0", default_features = false, features = ["selection", "backend_raycast"] } \ No newline at end of file From f37a3e166dcdec61ec0b78a4826a3cefe39b8077 Mon Sep 17 00:00:00 2001 From: IDEDARY Date: Tue, 9 Jul 2024 21:03:10 +0200 Subject: [PATCH 2/3] Fixed text size --- crates/bevy_lunex/src/structs.rs | 23 +++++++++++++++++++++++ crates/bevy_lunex/src/systems.rs | 21 ++++++++++++++++++--- crates/lunex_engine/src/core/mod.rs | 2 +- crates/lunex_engine/src/core/value.rs | 20 ++++++++++++++++++++ docs/src/advanced/4_text.md | 11 ++++++++--- docs/src/advanced/8_2d_and_3d.md | 1 + 6 files changed, 71 insertions(+), 7 deletions(-) diff --git a/crates/bevy_lunex/src/structs.rs b/crates/bevy_lunex/src/structs.rs index 9ad60be..13e30da 100644 --- a/crates/bevy_lunex/src/structs.rs +++ b/crates/bevy_lunex/src/structs.rs @@ -97,6 +97,29 @@ impl UiContent { } +/// This struct is used to specify size of the font in UI. +#[derive(Component, Debug, Clone, Copy, PartialEq)] +pub struct UiTextSize { + /// The unit type and scale value of the text height + pub size: UiValueType, +} +impl Default for UiTextSize { + fn default() -> Self { + Self { size: Rh(1.0).into() } + } +} +impl UiTextSize { + /// Creates new instance from default + pub fn new() -> Self { + Default::default() + } + /// Specify the height of the font + pub fn size(mut self, size: impl Into>) -> Self { + self.size = size.into(); + self + } +} + // #=======================# // #=== MAIN COMPONENTS ===# diff --git a/crates/bevy_lunex/src/systems.rs b/crates/bevy_lunex/src/systems.rs index 3687cba..8c29e41 100644 --- a/crates/bevy_lunex/src/systems.rs +++ b/crates/bevy_lunex/src/systems.rs @@ -442,13 +442,28 @@ pub fn element_reconstruct_mesh( /// ## 📦 Types /// * Generic `(T)` - Marker component grouping entities into one widget type pub fn element_text_size_to_layout( - mut query: Query<(&mut UiLayout, &TextLayoutInfo), (With>, With, Changed)>, + mut query: Query<(&mut UiLayout, &TextLayoutInfo, &Text, Option<&UiTextSize>), (With>, With, Changed)>, ) { - for (mut layout, text_info) in &mut query { + for (mut layout, text_info, text, optional_text_size) in &mut query { #[cfg(feature = "verbose")] info!("{} {} - Converted text size into Layout", "--".yellow(), "ELEMENT".red()); match &mut layout.layout { - Layout::Window(window) => {window.size = Rh(text_info.logical_size).into()}, + Layout::Window(window) => { + let font_size = text.sections[0].style.font_size; + window.size = if let Some(text_size) = optional_text_size { + match text_size.size { + UiValueType::Ab(t) => Ab(text_info.logical_size/font_size * t.0).into(), + UiValueType::Rl(t) => Rl(text_info.logical_size/font_size * t.0).into(), + UiValueType::Rw(t) => Rw(text_info.logical_size/font_size * t.0).into(), + UiValueType::Rh(t) => Rh(text_info.logical_size/font_size * t.0).into(), + UiValueType::Em(t) => Em(text_info.logical_size/font_size * t.0).into(), + UiValueType::Sp(t) => Sp(text_info.logical_size/font_size * t.0).into(), + UiValueType::Vp(t) => Vp(text_info.logical_size/font_size * t.0).into(), + UiValueType::Vw(t) => Vw(text_info.logical_size/font_size * t.0).into(), + UiValueType::Vh(t) => Vh(text_info.logical_size/font_size * t.0).into(), + } + } else { Rh(text_info.logical_size).into() }; + }, Layout::Solid(solid) => {solid.size = Ab(text_info.logical_size).into()}, _ => {}, } diff --git a/crates/lunex_engine/src/core/mod.rs b/crates/lunex_engine/src/core/mod.rs index 7cfd956..7cf0d28 100644 --- a/crates/lunex_engine/src/core/mod.rs +++ b/crates/lunex_engine/src/core/mod.rs @@ -19,7 +19,7 @@ pub mod prelude { // #============================# // #=== ALL DEFAULT UI UNITS ===# - pub use super::UiValue; + pub use super::{UiValue, UiValueType}; pub use super::{Ab, Rl, Rw, Rh, Em, Sp, Vp, Vw, Vh}; diff --git a/crates/lunex_engine/src/core/value.rs b/crates/lunex_engine/src/core/value.rs index 5ade113..9181c7f 100644 --- a/crates/lunex_engine/src/core/value.rs +++ b/crates/lunex_engine/src/core/value.rs @@ -516,6 +516,13 @@ macro_rules! unit_implement { $unit(Vec4::new(self.0, self.0, self.0, self.0)).into() } } + + + impl Into> for $unit { + fn into(self) -> UiValueType { + UiValueType::$unit(self) + } + } )* }; } @@ -644,6 +651,19 @@ pub struct Vw(pub T); #[derive(Debug, Default, Clone, Copy, PartialEq)] pub struct Vh(pub T); +/// **Unit type** - Enum with all possible ui unit types. +#[derive(Debug, Clone, Copy, PartialEq)] +pub enum UiValueType { + Ab(Ab), + Rl(Rl), + Rw(Rw), + Rh(Rh), + Em(Em), + Sp(Sp), + Vp(Vp), + Vw(Vw), + Vh(Vh), +} // #===================# // #=== MACRO CALLS ===# diff --git a/docs/src/advanced/4_text.md b/docs/src/advanced/4_text.md index d90323f..39ae447 100644 --- a/docs/src/advanced/4_text.md +++ b/docs/src/advanced/4_text.md @@ -5,8 +5,7 @@ All you have to do is specify the position and the anchor of the text node. You can disregard any size parameters, as they get overwritten by text-size. -For text-size, the provided `font_size` parameter is used, but instead of pixels it becomes `Rh` unit. -Currently it is hardcoded, but in the future you will be able to specify which unit to use. +For text-size, the provided `font_size` parameter is used, but instead of pixels it becomes `Rh` unit. You can change this with `UiTextSize` component. ```rust // Link this widget @@ -21,9 +20,15 @@ UiText2dBundle { text: Text::from_section("Hello world!", TextStyle { font: assets.load("font.ttf"), - font_size: 60.0, // Currently hardcoded as Relative height (Rh) - so 60% of the node height + font_size: 60.0, // By default hardcoded as Relative height (Rh) - so 60% of the node height color: Color::RED, }), ..default() }, +``` + +You can also decouple the font size from the logical font size by adding this component. This new value will be used instead and native bevy font size will used purely for rendering (font resolution). + +```rust +UiTextSize::new().size(Rh(5.0)), ``` \ No newline at end of file diff --git a/docs/src/advanced/8_2d_and_3d.md b/docs/src/advanced/8_2d_and_3d.md index c355bfd..b2b66a0 100644 --- a/docs/src/advanced/8_2d_and_3d.md +++ b/docs/src/advanced/8_2d_and_3d.md @@ -82,6 +82,7 @@ ui.spawn(( root.add("Camera3d"), UiLayout::solid().size((1920.0, 1080.0)).scaling(Scaling::Fill).pack::(), UiImage2dBundle::from(render_image), + PickingPortal, // You can add this component to send picking events through the viewport. )); ``` From 0167232495fc3ee5985a0350529de297f73ed464 Mon Sep 17 00:00:00 2001 From: IDEDARY Date: Tue, 9 Jul 2024 21:06:02 +0200 Subject: [PATCH 3/3] Version bump to 0.2.1 --- Cargo.toml | 6 +++--- README.md | 2 +- crates/bevy_lunex/README.md | 2 +- docs/src/2_installation.md | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 8ce87a7..e4a1314 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -17,7 +17,7 @@ [workspace.package] authors = ["IDEDARY"] - version = "0.2.0" + version = "0.2.1" edition = "2021" license = "MIT OR Apache-2.0" repository = "https://github.com/bytestring-net/bevy-lunex" @@ -26,8 +26,8 @@ [workspace.dependencies] - bevy_lunex = { path = "crates/bevy_lunex", version = "0.2.0" } - lunex_engine = { path = "crates/lunex_engine", version = "0.2.0" } + bevy_lunex = { path = "crates/bevy_lunex", version = "0.2.1" } + lunex_engine = { path = "crates/lunex_engine", version = "0.2.1" } colored = { version = "^2.1" } indexmap = { version = "^2.1" } diff --git a/README.md b/README.md index f266ebe..631d7a6 100644 --- a/README.md +++ b/README.md @@ -89,7 +89,7 @@ For production ready example/template check out [`Bevypunk source code`](https:/ | Bevy | Bevy Lunex | |--------|-----------------| -| 0.14.0 | 0.2.0 | +| 0.14.0 | 0.2.0 - 0.2.1 | | 0.13.2 | 0.1.0 | | 0.12.1 | 0.0.10 - 0.0.11 | | 0.12.0 | 0.0.7 - 0.0.9 | diff --git a/crates/bevy_lunex/README.md b/crates/bevy_lunex/README.md index f266ebe..631d7a6 100644 --- a/crates/bevy_lunex/README.md +++ b/crates/bevy_lunex/README.md @@ -89,7 +89,7 @@ For production ready example/template check out [`Bevypunk source code`](https:/ | Bevy | Bevy Lunex | |--------|-----------------| -| 0.14.0 | 0.2.0 | +| 0.14.0 | 0.2.0 - 0.2.1 | | 0.13.2 | 0.1.0 | | 0.12.1 | 0.0.10 - 0.0.11 | | 0.12.0 | 0.0.7 - 0.0.9 | diff --git a/docs/src/2_installation.md b/docs/src/2_installation.md index 7070185..8f0627d 100644 --- a/docs/src/2_installation.md +++ b/docs/src/2_installation.md @@ -6,7 +6,7 @@ Add the following to your `Cargo.toml`: ```toml [dependencies] -bevy_lunex = { version = "0.2.0" } +bevy_lunex = { version = "0.2.1" } ``` Alternatively, you can use the latest bleeding edge version from the Git repository: