Skip to content

Commit

Permalink
Merge pull request #57 from bytestring-net/dev
Browse files Browse the repository at this point in the history
Version 0.2.1
  • Loading branch information
IDEDARY authored Jul 9, 2024
2 parents 8e65e23 + 0167232 commit 4ab01f1
Show file tree
Hide file tree
Showing 10 changed files with 79 additions and 15 deletions.
10 changes: 5 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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" }
Expand All @@ -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"] }
bevy_kira_audio = { version = "^0.20.0" }
bevy_mod_picking = { version = "^0.20.0", default_features = false, features = ["selection", "backend_raycast"] }
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_lunex/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
Expand Down
23 changes: 23 additions & 0 deletions crates/bevy_lunex/src/structs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<f32>,
}
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<UiValueType<f32>>) -> Self {
self.size = size.into();
self
}
}

// #=======================#
// #=== MAIN COMPONENTS ===#

Expand Down
21 changes: 18 additions & 3 deletions crates/bevy_lunex/src/systems.rs
Original file line number Diff line number Diff line change
Expand Up @@ -442,13 +442,28 @@ pub fn element_reconstruct_mesh<T: Component>(
/// ## 📦 Types
/// * Generic `(T)` - Marker component grouping entities into one widget type
pub fn element_text_size_to_layout<T: Component>(
mut query: Query<(&mut UiLayout, &TextLayoutInfo), (With<UiLink<T>>, With<Element>, Changed<TextLayoutInfo>)>,
mut query: Query<(&mut UiLayout, &TextLayoutInfo, &Text, Option<&UiTextSize>), (With<UiLink<T>>, With<Element>, Changed<TextLayoutInfo>)>,
) {
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()},
_ => {},
}
Expand Down
2 changes: 1 addition & 1 deletion crates/lunex_engine/src/core/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};


Expand Down
20 changes: 20 additions & 0 deletions crates/lunex_engine/src/core/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -516,6 +516,13 @@ macro_rules! unit_implement {
$unit(Vec4::new(self.0, self.0, self.0, self.0)).into()
}
}


impl Into<UiValueType<f32>> for $unit<f32> {
fn into(self) -> UiValueType<f32> {
UiValueType::$unit(self)
}
}
)*
};
}
Expand Down Expand Up @@ -644,6 +651,19 @@ pub struct Vw<T>(pub T);
#[derive(Debug, Default, Clone, Copy, PartialEq)]
pub struct Vh<T>(pub T);

/// **Unit type** - Enum with all possible ui unit types.
#[derive(Debug, Clone, Copy, PartialEq)]
pub enum UiValueType<T> {
Ab(Ab<T>),
Rl(Rl<T>),
Rw(Rw<T>),
Rh(Rh<T>),
Em(Em<T>),
Sp(Sp<T>),
Vp(Vp<T>),
Vw(Vw<T>),
Vh(Vh<T>),
}

// #===================#
// #=== MACRO CALLS ===#
Expand Down
2 changes: 1 addition & 1 deletion docs/src/2_installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
11 changes: 8 additions & 3 deletions docs/src/advanced/4_text.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)),
```
1 change: 1 addition & 0 deletions docs/src/advanced/8_2d_and_3d.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ ui.spawn((
root.add("Camera3d"),
UiLayout::solid().size((1920.0, 1080.0)).scaling(Scaling::Fill).pack::<Base>(),
UiImage2dBundle::from(render_image),
PickingPortal, // You can add this component to send picking events through the viewport.
));
```

Expand Down

0 comments on commit 4ab01f1

Please sign in to comment.