From a0dc882799c09cfb0cdb595639e7329e7d521dfb Mon Sep 17 00:00:00 2001 From: griffi-gh Date: Fri, 22 Mar 2024 18:39:18 +0100 Subject: [PATCH] static -> absolute, fraction -> relative --- hui-examples/examples/align_test.rs | 16 ++++++++-------- hui-examples/examples/rounded_rect.rs | 12 ++++++------ hui-examples/examples/text_weird.rs | 10 +++++----- hui/src/element/builtin/container.rs | 24 ++++++++++++------------ hui/src/element/builtin/fill_rect.rs | 8 ++++---- hui/src/element/builtin/text.rs | 8 ++++---- hui/src/frame.rs | 4 ++-- hui/src/layout.rs | 14 +++++++------- hui/src/macros.rs | 22 +++++++++++----------- 9 files changed, 59 insertions(+), 59 deletions(-) diff --git a/hui-examples/examples/align_test.rs b/hui-examples/examples/align_test.rs index a11eb6e..86e4c57 100644 --- a/hui-examples/examples/align_test.rs +++ b/hui-examples/examples/align_test.rs @@ -44,7 +44,7 @@ fn main() { gap: 5., padding: Sides::all(5.), align: (Alignment::Center, Alignment::Begin).into(), - size: (Size::Fraction(1.), Size::Fraction(1.)).into(), + size: (Size::Relative(1.), Size::Relative(1.)).into(), children: ElementList(vec![ Box::new(ProgressBar { value: 0.5, @@ -58,7 +58,7 @@ fn main() { gap: 5., padding: Sides::all(5.), align: (Alignment::Center, Alignment::End).into(), - size: (Size::Fraction(1.), Size::Fraction(1.)).into(), + size: (Size::Relative(1.), Size::Relative(1.)).into(), children: ElementList(vec![ Box::new(ProgressBar { value: z, @@ -66,18 +66,18 @@ fn main() { ..Default::default() }), Box::new(Container { - size: (Size::Fraction(1.), Size::Auto).into(), + size: (Size::Relative(1.), Size::Auto).into(), align: (Alignment::End, Alignment::Center).into(), padding: Sides::all(5.), gap: 10., children: ElementList(vec![ Box::new(FillRect { - size: (Size::Fraction(0.5), Size::Static(30.)).into(), + size: (Size::Relative(0.5), Size::Absolute(30.)).into(), background: vec4(0.75, 0., 0., 1.).into(), ..Default::default() }), Box::new(FillRect { - size: (Size::Fraction(z / 2. + 0.5), Size::Static(30.)).into(), + size: (Size::Relative(z / 2. + 0.5), Size::Absolute(30.)).into(), background: Corners::left_right( vec4(1., 0., 0., 1.), vec4(0., 1., 0., 1.) @@ -88,7 +88,7 @@ fn main() { ..Default::default() }), Box::new(FillRect { - size: (Size::Fraction(z / 2. + 0.5), Size::Static(30.)).into(), + size: (Size::Relative(z / 2. + 0.5), Size::Absolute(30.)).into(), background: vec4(0., 0.75, 0., 1.).into(), ..Default::default() }), @@ -101,7 +101,7 @@ fn main() { let mut x: Vec> = vec![]; for i in 0..10 { x.push(Box::new(FillRect { - size: (Size::Static(50.), Size::Static(50.)).into(), + size: (Size::Absolute(50.), Size::Absolute(50.)).into(), background: if i == 1 { vec4(0.75, 0.75, 0.75, 0.75).into() } else { @@ -130,7 +130,7 @@ fn main() { }, children: ElementList(vec![ Box::new(FillRect { - size: (Size::Static(50.), Size::Static(50.)).into(), + size: (Size::Absolute(50.), Size::Absolute(50.)).into(), background: vec4(1., 1., 1., 0.75).into(), ..Default::default() }), diff --git a/hui-examples/examples/rounded_rect.rs b/hui-examples/examples/rounded_rect.rs index abe66b8..81c6487 100644 --- a/hui-examples/examples/rounded_rect.rs +++ b/hui-examples/examples/rounded_rect.rs @@ -42,11 +42,11 @@ fn main() { hui.add(Container { gap: 10., align: Alignment::Center.into(), - size: (Size::Fraction(1.), Size::Fraction(1.)).into(), + size: (Size::Relative(1.), Size::Relative(1.)).into(), children: ElementList(vec![ Box::new(Container { align: Alignment::Center.into(), - size: (Size::Fraction(0.5), Size::Fraction(0.5)).into(), + size: (Size::Relative(0.5), Size::Relative(0.5)).into(), background: vec4(1., 0., 0., 1.).into(), corner_radius: Corners { top_left: 10., @@ -86,7 +86,7 @@ fn main() { direction: Direction::Horizontal, children: ElementList(vec![ Box::new(Container { - size: (Size::Static(100.), Size::Static(100.)).into(), + size: (Size::Absolute(100.), Size::Absolute(100.)).into(), background: Corners::left_right( vec4(1., 0., 0., 1.), vec4(0., 1., 0., 1.) @@ -95,7 +95,7 @@ fn main() { ..Default::default() }), Box::new(Container { - size: (Size::Static(100.), Size::Static(100.)).into(), + size: (Size::Absolute(100.), Size::Absolute(100.)).into(), background: Corners::left_right( vec4(1., 0., 0., 1.), vec4(0., 1., 0., 1.) @@ -104,7 +104,7 @@ fn main() { ..Default::default() }), Box::new(Container { - size: (Size::Static(100.), Size::Static(100.)).into(), + size: (Size::Absolute(100.), Size::Absolute(100.)).into(), background: Corners::left_right( vec4(1., 0., 0., 1.), vec4(0., 1., 0., 1.) @@ -113,7 +113,7 @@ fn main() { ..Default::default() }), Box::new(Container { - size: (Size::Static(100.), Size::Static(100.)).into(), + size: (Size::Absolute(100.), Size::Absolute(100.)).into(), background: Corners::left_right( vec4(1., 0., 0., 1.), vec4(0., 1., 0., 1.) diff --git a/hui-examples/examples/text_weird.rs b/hui-examples/examples/text_weird.rs index ebe6bce..a9222eb 100644 --- a/hui-examples/examples/text_weird.rs +++ b/hui-examples/examples/text_weird.rs @@ -48,7 +48,7 @@ fn main() { hui.begin(); hui.add(Container { - size: (Size::Fraction(1.), Size::Fraction(1.)).into(), + size: (Size::Relative(1.), Size::Relative(1.)).into(), background: vec4(0.1, 0.1, 0.1, 1.).into(), children: elements(|elem| { elem.push(Box::new(Text { @@ -72,12 +72,12 @@ fn main() { })); } elem.push(Box::new(FillRect { - size: (Size::Fraction(1.), Size::Static(10.)).into(), + size: (Size::Relative(1.), Size::Absolute(10.)).into(), background: vec4(0., 0., 1., 1.).into(), ..Default::default() })); elem.push(Box::new(FillRect { - size: (Size::Fraction(1.), Size::Static(10.)).into(), + size: (Size::Relative(1.), Size::Absolute(10.)).into(), background: vec4(1., 1., 0., 1.).into(), ..Default::default() })); @@ -89,12 +89,12 @@ fn main() { })); if instant.elapsed().as_secs() & 1 != 0 { elem.push(Box::new(FillRect { - size: (Size::Fraction(1.), Size::Static(10.)).into(), + size: (Size::Relative(1.), Size::Absolute(10.)).into(), background: vec4(1., 0., 0., 1.).into(), ..Default::default() })); elem.push(Box::new(FillRect { - size: (Size::Fraction(1.), Size::Static(10.)).into(), + size: (Size::Relative(1.), Size::Absolute(10.)).into(), background: vec4(0., 0., 0., 1.).into(), ..Default::default() })); diff --git a/hui/src/element/builtin/container.rs b/hui/src/element/builtin/container.rs index bdd422e..beb13ee 100644 --- a/hui/src/element/builtin/container.rs +++ b/hui/src/element/builtin/container.rs @@ -116,13 +116,13 @@ impl Container { pub fn measure_max_inner_size(&self, layout: &LayoutInfo) -> Vec2 { let outer_size_x = match self.size.width { Size::Auto => layout.max_size.x, - Size::Fraction(p) => layout.max_size.x * p, - Size::Static(p) => p, + Size::Relative(p) => layout.max_size.x * p, + Size::Absolute(p) => p, }; let outer_size_y = match self.size.height { Size::Auto => layout.max_size.y, - Size::Fraction(p) => layout.max_size.y * p, - Size::Static(p) => p, + Size::Relative(p) => layout.max_size.y * p, + Size::Absolute(p) => p, }; vec2( outer_size_x - (self.padding.left + self.padding.right), @@ -148,13 +148,13 @@ impl UiElement for Container { let max_line_pri = match self.direction { Direction::Horizontal => match self.size.width { Size::Auto => ctx.layout.max_size.x, - Size::Fraction(p) => ctx.layout.max_size.x * p, - Size::Static(p) => p, + Size::Relative(p) => ctx.layout.max_size.x * p, + Size::Absolute(p) => p, }, Direction::Vertical => match self.size.height { Size::Auto => ctx.layout.max_size.y, - Size::Fraction(p) => ctx.layout.max_size.y * p, - Size::Static(p) => p, + Size::Relative(p) => ctx.layout.max_size.y * p, + Size::Absolute(p) => p, } }; @@ -300,13 +300,13 @@ impl UiElement for Container { match self.size.width { Size::Auto => (), - Size::Fraction(percentage) => total_size.x = ctx.layout.max_size.x * percentage, - Size::Static(pixels) => total_size.x = pixels, + Size::Relative(percentage) => total_size.x = ctx.layout.max_size.x * percentage, + Size::Absolute(pixels) => total_size.x = pixels, } match self.size.height { Size::Auto => (), - Size::Fraction(percentage) => total_size.y = ctx.layout.max_size.y * percentage, - Size::Static(pixels) => total_size.y = pixels, + Size::Relative(percentage) => total_size.y = ctx.layout.max_size.y * percentage, + Size::Absolute(pixels) => total_size.y = pixels, } Response { diff --git a/hui/src/element/builtin/fill_rect.rs b/hui/src/element/builtin/fill_rect.rs index 077b1dc..d93b0da 100644 --- a/hui/src/element/builtin/fill_rect.rs +++ b/hui/src/element/builtin/fill_rect.rs @@ -48,13 +48,13 @@ impl UiElement for FillRect { size: vec2( match self.size.width { Size::Auto => ctx.layout.max_size.x, - Size::Fraction(percentage) => ctx.layout.max_size.x * percentage, - Size::Static(pixels) => pixels, + Size::Relative(percentage) => ctx.layout.max_size.x * percentage, + Size::Absolute(pixels) => pixels, }, match self.size.height { Size::Auto => ctx.layout.max_size.y, - Size::Fraction(percentage) => ctx.layout.max_size.y * percentage, - Size::Static(pixels) => pixels, + Size::Relative(percentage) => ctx.layout.max_size.y * percentage, + Size::Absolute(pixels) => pixels, }, ), ..Default::default() diff --git a/hui/src/element/builtin/text.rs b/hui/src/element/builtin/text.rs index 3e760ff..66bac10 100644 --- a/hui/src/element/builtin/text.rs +++ b/hui/src/element/builtin/text.rs @@ -86,13 +86,13 @@ impl UiElement for Text { size: vec2( match self.size.width { Size::Auto => size.0, - Size::Fraction(percentage) => ctx.layout.max_size.x * percentage, - Size::Static(pixels) => pixels, + Size::Relative(percentage) => ctx.layout.max_size.x * percentage, + Size::Absolute(pixels) => pixels, }, match self.size.height { Size::Auto => size.1, - Size::Fraction(percentage) => ctx.layout.max_size.y * percentage, - Size::Static(pixels) => pixels, + Size::Relative(percentage) => ctx.layout.max_size.y * percentage, + Size::Absolute(pixels) => pixels, }, ), ..Default::default() diff --git a/hui/src/frame.rs b/hui/src/frame.rs index 842d8aa..c4a8934 100644 --- a/hui/src/frame.rs +++ b/hui/src/frame.rs @@ -28,8 +28,8 @@ impl From for FramePoint { fn from(size: Size) -> Self { match size { Size::Auto => Self::BEGIN, - Size::Fraction(value) => Self::relative(value), - Size::Static(value) => Self::absolute(value), + Size::Relative(value) => Self::relative(value), + Size::Absolute(value) => Self::absolute(value), } } } diff --git a/hui/src/layout.rs b/hui/src/layout.rs index e7963b4..3744009 100644 --- a/hui/src/layout.rs +++ b/hui/src/layout.rs @@ -91,18 +91,18 @@ pub enum Size { /// /// Out of range values are allowed, but are not guaranteed to work as expected\ /// (especially with negative values) - Fraction(f32), + Relative(f32), //TODO FractionRemaining(f32), /// Static size in pixels - Static(f32), + Absolute(f32), } impl From for Size { #[inline] fn from(value: f32) -> Self { - Self::Static(value) + Self::Absolute(value) } } @@ -166,13 +166,13 @@ pub struct LayoutInfo { pub fn compute_size(layout: &LayoutInfo, size: Size2d, comfy_size: Vec2) -> Vec2 { let width = match size.width { Size::Auto => comfy_size.x, - Size::Fraction(fraction) => layout.max_size.x * fraction, - Size::Static(size) => size, + Size::Relative(fraction) => layout.max_size.x * fraction, + Size::Absolute(size) => size, }; let height = match size.height { Size::Auto => comfy_size.y, - Size::Fraction(fraction) => layout.max_size.y * fraction, - Size::Static(size) => size, + Size::Relative(fraction) => layout.max_size.y * fraction, + Size::Absolute(size) => size, }; vec2(width, height) } diff --git a/hui/src/macros.rs b/hui/src/macros.rs index 53b0366..434e248 100644 --- a/hui/src/macros.rs +++ b/hui/src/macros.rs @@ -3,16 +3,16 @@ /// /// # Syntax: /// - `auto` - `Size::Auto` -/// - `x` - `Size::Static(x)` -/// - `x%` - `Size::Fraction(x / 100.)` *(literal only)* -/// - `x/` - `Size::Fraction(x)` +/// - `x` - `Size::Absolute(x)` +/// - `x%` - `Size::Relative(x / 100.)` *(literal only)* +/// - `x/` - `Size::Relative(x)` /// /// ...where `x` is a literal, identifier or an expression wrapped in parentheses /// /// # Note: /// - If a single argument is provided, it creates a `Size` using the rules specified above\ /// - If two arguments are provided, it creates a `Size2d` with the first value as width and the second as height\ -/// Example: `size!(100, 50%)` creates a `Size2d` with width `100` (`Size::Static(100.)`) and height `50%` (`Size::Fraction(0.5)`) +/// Example: `size!(100, 50%)` creates a `Size2d` with width `100` (`Size::Absolute(100.)`) and height `50%` (`Size::Relative(0.5)`) /// - `%` syntax is only valid for literals (`50%`), not expressions or identidiers.\ /// Use `/` instead (`(0.5 * x)/`, `x/`), but be aware of the different range (0.0-1.0) \ /// - Expressions must be wrapped in parentheses (for example: `(x + 5)`).\ @@ -24,27 +24,27 @@ macro_rules! size { }; ($x:literal) => { - $crate::layout::Size::Static($x as f32) + $crate::layout::Size::Absolute($x as f32) }; ($x:literal %) => { - $crate::layout::Size::Fraction($x as f32 / 100.) + $crate::layout::Size::Relative($x as f32 / 100.) }; ($x:literal /) => { - $crate::layout::Size::Fraction($x as f32) + $crate::layout::Size::Relative($x as f32) }; ($x:ident) => { - $crate::layout::Size::Static($x as f32) + $crate::layout::Size::Absolute($x as f32) }; ($x:ident /) => { - $crate::layout::Size::Fraction($x as f32) + $crate::layout::Size::Relative($x as f32) }; (($x:expr)) => { - $crate::layout::Size::Static(($x) as f32) + $crate::layout::Size::Absolute(($x) as f32) }; (($x:expr) /) => { - $crate::layout::Size::Fraction(($x) as f32) + $crate::layout::Size::Relative(($x) as f32) }; ($x:tt , $y:tt $($ys:tt)?) => {