From f820f7e930bb4ba72011b9e2eef85e760093c1bc Mon Sep 17 00:00:00 2001 From: griffi-gh Date: Wed, 17 Apr 2024 15:57:46 +0200 Subject: [PATCH] rename `FrameRect` to `RectFrame` --- README.md | 4 +-- hui-examples/examples/align_test.rs | 6 ++-- hui-examples/examples/mom_downloader.rs | 8 +++--- hui-examples/examples/text_weird.rs | 4 +-- hui-examples/examples/ui_test.rs | 8 +++--- hui-examples/examples/ui_test_2_loading.rs | 10 +++---- hui-examples/examples/ui_test_3_transform.rs | 4 +-- hui-examples/examples/ui_test_4_wrapping.rs | 4 +-- hui/src/element/builtin/container.rs | 4 +-- hui/src/element/builtin/frame_view.rs | 4 +-- hui/src/element/builtin/progress_bar.rs | 6 ++-- hui/src/element/builtin/slider.rs | 8 +++--- hui/src/frame.rs | 2 +- hui/src/frame/rect.rs | 30 ++++++++++---------- hui/src/macros.rs | 20 ++++++------- 15 files changed, 61 insertions(+), 61 deletions(-) diff --git a/README.md b/README.md index 03ca769..31c080e 100644 --- a/README.md +++ b/README.md @@ -32,7 +32,7 @@ .with_align(Alignment::Center) .with_padding(5.) .with_gap(10.) - .with_background(frame_rect! { + .with_background(rect_frame! { color: (0.5, 0.5, 0.5, 1.), corner_radius: 10., }) @@ -44,7 +44,7 @@ .add_child(ui); Container::default() .with_padding((10., 20.)) - .with_background(frame_rect! { + .with_background(rect_frame! { color: color::DARK_RED, corner_radius: (2.5, 30., 2.5, 2.5), }) diff --git a/hui-examples/examples/align_test.rs b/hui-examples/examples/align_test.rs index 45806bd..bd33738 100644 --- a/hui-examples/examples/align_test.rs +++ b/hui-examples/examples/align_test.rs @@ -10,7 +10,7 @@ use winit::{ use hui::{ element::{ container::Container, frame_view::FrameView, progress_bar::ProgressBar, ElementList, UiElement - }, frame::FrameRect, layout::{Alignment, Direction, Size}, rect::{Corners, Sides}, UiInstance + }, frame::RectFrame, layout::{Alignment, Direction, Size}, rect::{Corners, Sides}, UiInstance }; use hui_glium::GliumUiRenderer; @@ -92,7 +92,7 @@ fn main() { Box::new(Container { gap: 5., padding: Sides::all(5.), - background_frame: Box::new(FrameRect::color(vec4(0., 0., 0., 0.5))), + background_frame: Box::new(RectFrame::color(vec4(0., 0., 0., 0.5))), direction: Direction::Horizontal, children: { let mut x: Vec> = vec![]; @@ -111,7 +111,7 @@ fn main() { ..Default::default() }), Box::new(Container { - background_frame: Box::new(FrameRect::color((1., 0., 0.)).with_corner_radius(Corners { + background_frame: Box::new(RectFrame::color((1., 0., 0.)).with_corner_radius(Corners { top_left: 0., top_right: 30., bottom_left: 0., diff --git a/hui-examples/examples/mom_downloader.rs b/hui-examples/examples/mom_downloader.rs index cd28de0..2061bfe 100644 --- a/hui-examples/examples/mom_downloader.rs +++ b/hui-examples/examples/mom_downloader.rs @@ -5,7 +5,7 @@ use hui::{ progress_bar::ProgressBar, text::Text, UiElementExt, - }, frame::FrameRect, frame_rect, layout::{Alignment, Direction}, size + }, frame::RectFrame, rect_frame, layout::{Alignment, Direction}, size }; #[path = "../boilerplate.rs"] @@ -31,7 +31,7 @@ ui_main!{ .with_gap(5.) .with_padding(10.) .with_size(size!(450, auto)) - .with_background(frame_rect! { + .with_background(rect_frame! { color: (0.2, 0.2, 0.5), corner_radius: 8. }) @@ -43,11 +43,11 @@ ui_main!{ .add_child(ui); ProgressBar::default() .with_value(mom_ratio) - .with_background(frame_rect! { + .with_background(rect_frame! { color: color::BLACK, corner_radius: 0.125 * ProgressBar::DEFAULT_HEIGHT }) - .with_foreground(frame_rect! { + .with_foreground(rect_frame! { color: color::BLUE, corner_radius: 0.125 * ProgressBar::DEFAULT_HEIGHT }) diff --git a/hui-examples/examples/text_weird.rs b/hui-examples/examples/text_weird.rs index 11689c9..7bfc292 100644 --- a/hui-examples/examples/text_weird.rs +++ b/hui-examples/examples/text_weird.rs @@ -10,7 +10,7 @@ use winit::{ use hui::{ element::{ container::Container, frame_view::FrameView, spacer::Spacer, text::Text, ElementList - }, frame::FrameRect, layout::Size, UiInstance + }, frame::RectFrame, layout::Size, UiInstance }; use hui_glium::GliumUiRenderer; @@ -49,7 +49,7 @@ fn main() { hui.add(Container { size: (Size::Relative(1.), Size::Relative(1.)).into(), - background_frame: Box::new(FrameRect::color((0.1, 0.1, 0.1, 1.))), + background_frame: Box::new(RectFrame::color((0.1, 0.1, 0.1, 1.))), children: elements(|elem| { elem.push(Box::new(Text { text: "THIS LINE SHOULD BE SHARP!".into(), diff --git a/hui-examples/examples/ui_test.rs b/hui-examples/examples/ui_test.rs index f62e2f4..cfc33c6 100644 --- a/hui-examples/examples/ui_test.rs +++ b/hui-examples/examples/ui_test.rs @@ -1,7 +1,7 @@ use hui::{ - color, size, frame_rect, + color, size, rect_frame, element::{container::Container, text::Text, UiElementExt}, - frame::FrameRect, + frame::RectFrame, layout::Alignment, }; @@ -15,7 +15,7 @@ ui_main!(|ui, size, _| { .with_align(Alignment::Center) .with_padding(5.) .with_gap(10.) - .with_background(frame_rect! { + .with_background(rect_frame! { color: (0.5, 0.5, 0.5, 1.), corner_radius: 10., }) @@ -27,7 +27,7 @@ ui_main!(|ui, size, _| { .add_child(ui); Container::default() .with_padding((10., 20.)) - .with_background(frame_rect! { + .with_background(rect_frame! { color: color::DARK_RED, corner_radius: (2.5, 30., 2.5, 2.5), }) diff --git a/hui-examples/examples/ui_test_2_loading.rs b/hui-examples/examples/ui_test_2_loading.rs index 2af1cb5..8f11033 100644 --- a/hui-examples/examples/ui_test_2_loading.rs +++ b/hui-examples/examples/ui_test_2_loading.rs @@ -1,6 +1,6 @@ use glam::vec4; use hui::{ - size, frame_rect, + size, rect_frame, color, element::{ container::Container, @@ -8,7 +8,7 @@ use hui::{ text::Text, UiElementExt }, - frame::FrameRect, + frame::RectFrame, layout::Alignment, rect::Corners, text::FontHandle @@ -45,7 +45,7 @@ ui_main!( .with_children(|ui| { Container::default() .with_padding((10., 15.)) - .with_background(frame_rect! { + .with_background(rect_frame! { color: (0., 0., 0., 0.5), corner_radius: 8., }) @@ -70,7 +70,7 @@ ui_main!( .with_align((Alignment::Center, Alignment::Begin)) .with_padding(15.) .with_gap(10.) - .with_background(frame_rect! { + .with_background(rect_frame! { color: (0., 0., 0., 0.5), corner_radius: 8., }) @@ -111,7 +111,7 @@ ui_main!( .with_children(|ui| { Container::default() .with_padding(10.) - .with_background(frame_rect!{ + .with_background(rect_frame!{ color: (0., 0., 0., 0.5), corner_radius: 8., }) diff --git a/hui-examples/examples/ui_test_3_transform.rs b/hui-examples/examples/ui_test_3_transform.rs index ea0a52d..eb8f392 100644 --- a/hui-examples/examples/ui_test_3_transform.rs +++ b/hui-examples/examples/ui_test_3_transform.rs @@ -7,7 +7,7 @@ use hui::{ text::Text, transformer::ElementTransformExt, UiElementExt - }, frame::FrameRect, frame_rect, layout::Alignment, rect::Corners, size, text::FontHandle + }, frame::RectFrame, rect_frame, layout::Alignment, rect::Corners, size, text::FontHandle }; #[path = "../boilerplate.rs"] @@ -37,7 +37,7 @@ ui_main!( .with_align((Alignment::Center, Alignment::Begin)) .with_padding(15.) .with_gap(10.) - .with_background(frame_rect! { + .with_background(rect_frame! { color: (0., 0., 0., 0.5), corner_radius: 8. }) diff --git a/hui-examples/examples/ui_test_4_wrapping.rs b/hui-examples/examples/ui_test_4_wrapping.rs index 3e5dd43..a580d5f 100644 --- a/hui-examples/examples/ui_test_4_wrapping.rs +++ b/hui-examples/examples/ui_test_4_wrapping.rs @@ -4,7 +4,7 @@ use hui::{ container::Container, frame_view::FrameView, UiElementExt - }, frame_rect, layout::{Alignment, Direction}, size + }, rect_frame, layout::{Alignment, Direction}, size }; #[path = "../boilerplate.rs"] @@ -30,7 +30,7 @@ ui_main!( for i in 0..10 { FrameView::default() .with_size(size!((40 + i * 10))) - .with_frame(frame_rect! { + .with_frame(rect_frame! { color: color::DARK_RED, corner_radius: 8. }) diff --git a/hui/src/element/builtin/container.rs b/hui/src/element/builtin/container.rs index 328f8c9..289225d 100644 --- a/hui/src/element/builtin/container.rs +++ b/hui/src/element/builtin/container.rs @@ -4,7 +4,7 @@ use derive_setters::Setters; use glam::{Vec2, vec2}; use crate::{ element::{ElementList, MeasureContext, ProcessContext, UiElement}, - frame::{Frame, FrameRect}, + frame::{Frame, RectFrame}, layout::{compute_size, Alignment, Alignment2d, Direction, LayoutInfo, Size, Size2d, WrapBehavior}, measure::{Hints, Response}, rect::Sides, @@ -82,7 +82,7 @@ impl Default for Container { gap: 0., padding: Sides::all(0.), align: Alignment2d::default(), - background_frame: Box::::default(), + background_frame: Box::::default(), wrap: WrapBehavior::Allow, children: ElementList(Vec::new()), } diff --git a/hui/src/element/builtin/frame_view.rs b/hui/src/element/builtin/frame_view.rs index 93db512..39f3067 100644 --- a/hui/src/element/builtin/frame_view.rs +++ b/hui/src/element/builtin/frame_view.rs @@ -3,7 +3,7 @@ use derive_setters::Setters; use crate::{ element::{MeasureContext, ProcessContext, UiElement}, - frame::{Frame, FrameRect}, + frame::{Frame, RectFrame}, layout::{compute_size, Size2d}, measure::Response, size @@ -41,7 +41,7 @@ impl Default for FrameView { fn default() -> Self { Self { size: size!(10, 10), - frame: Box::new(FrameRect::color((0., 0., 0., 0.5))), + frame: Box::new(RectFrame::color((0., 0., 0., 0.5))), } } } diff --git a/hui/src/element/builtin/progress_bar.rs b/hui/src/element/builtin/progress_bar.rs index f9fb518..c7246be 100644 --- a/hui/src/element/builtin/progress_bar.rs +++ b/hui/src/element/builtin/progress_bar.rs @@ -2,7 +2,7 @@ use derive_setters::Setters; use glam::vec2; use crate::{ element::{MeasureContext, ProcessContext, UiElement}, - frame::{Frame, FrameRect}, + frame::{Frame, RectFrame}, layout::{compute_size, Size, Size2d}, measure::Response, }; @@ -47,8 +47,8 @@ impl Default for ProgressBar { Self { value: 0., size: Size::Auto.into(), - foreground: Box::new(FrameRect::color((0.0, 0.0, 1.0, 1.0))), - background: Box::new(FrameRect::color((0.0, 0.0, 0.0, 1.0))), + foreground: Box::new(RectFrame::color((0.0, 0.0, 1.0, 1.0))), + background: Box::new(RectFrame::color((0.0, 0.0, 0.0, 1.0))), } } } diff --git a/hui/src/element/builtin/slider.rs b/hui/src/element/builtin/slider.rs index 5d5fd3a..7affebc 100644 --- a/hui/src/element/builtin/slider.rs +++ b/hui/src/element/builtin/slider.rs @@ -4,7 +4,7 @@ use derive_setters::Setters; use glam::{Vec2, vec2}; use crate::{ - draw::UiDrawCommand, element::{MeasureContext, ProcessContext, UiElement}, frame::{Frame, FrameRect}, layout::{compute_size, Size2d}, measure::Response, rect::FillColor, signal::{trigger::SignalTriggerArg, Signal} + draw::UiDrawCommand, element::{MeasureContext, ProcessContext, UiElement}, frame::{Frame, RectFrame}, layout::{compute_size, Size2d}, measure::Response, rect::FillColor, signal::{trigger::SignalTriggerArg, Signal} }; @@ -79,9 +79,9 @@ impl Default for Slider { Self { value: 0.0, size: Size2d::default(), - handle: Box::new(FrameRect::color((0.0, 0.0, 1.))), - track: Box::new(FrameRect::color((0.5, 0.5, 0.5))), - track_active: Box::new(FrameRect::color((0.0, 0.0, 0.75))), + handle: Box::new(RectFrame::color((0.0, 0.0, 1.))), + track: Box::new(RectFrame::color((0.5, 0.5, 0.5))), + track_active: Box::new(RectFrame::color((0.0, 0.0, 0.75))), track_height: 0.25, handle_size: (15.0, 1.), follow_mode: SliderFollowMode::default(), diff --git a/hui/src/frame.rs b/hui/src/frame.rs index 52db5a9..d33b943 100644 --- a/hui/src/frame.rs +++ b/hui/src/frame.rs @@ -9,7 +9,7 @@ pub mod stack; pub mod nine_patch; mod impls; -pub use rect::FrameRect; +pub use rect::RectFrame; /// Trait for a drawable frame pub trait Frame { diff --git a/hui/src/frame/rect.rs b/hui/src/frame/rect.rs index fc24f6f..05db4ee 100644 --- a/hui/src/frame/rect.rs +++ b/hui/src/frame/rect.rs @@ -10,7 +10,7 @@ use super::{Frame, point::FramePoint2d}; /// /// Can optionally be tinted, textured, and have rounded corners #[derive(Clone, Copy)] -pub struct FrameRect { +pub struct RectFrame { /// Background color of the frame\ /// /// If the container has a background texture, it will be multiplied by this color @@ -35,26 +35,26 @@ pub struct FrameRect { pub corner_radius: Corners, } -// impl> From for FrameRect { +// impl> From for RectFrame { // fn from(color: T) -> Self { // Self::from_color(color) // } // } -impl From for FrameRect { +impl From for RectFrame { fn from(color: FillColor) -> Self { Self::color(color) } } -impl From for FrameRect { +impl From for RectFrame { fn from(image: ImageHandle) -> Self { Self::image(image) } } -impl FrameRect { - /// Create a new [`FrameRect`] with the given color +impl RectFrame { + /// Create a new [`RectFrame`] with the given color pub fn color(color: impl Into) -> Self { Self { color: color.into(), @@ -62,7 +62,7 @@ impl FrameRect { } } - /// Create a new [`FrameRect`] with the given image\ + /// Create a new [`RectFrame`] with the given image\ /// /// Color will be set to [`WHITE`](crate::color::WHITE) to ensure the image is visible pub fn image(image: ImageHandle) -> Self { @@ -73,7 +73,7 @@ impl FrameRect { } } - /// Create a new [`FrameRect`] with the given color and image + /// Create a new [`RectFrame`] with the given color and image pub fn color_image(color: impl Into, image: ImageHandle) -> Self { Self { color: color.into(), @@ -82,7 +82,7 @@ impl FrameRect { } } - /// Set the corner radius of the [`FrameRect`] + /// Set the corner radius of the [`RectFrame`] pub fn with_corner_radius(self, radius: impl Into>) -> Self { Self { corner_radius: radius.into(), @@ -102,7 +102,7 @@ impl FrameRect { } } -impl Default for FrameRect { +impl Default for RectFrame { fn default() -> Self { Self { color: FillColor::transparent(), @@ -114,7 +114,7 @@ impl Default for FrameRect { } } -impl Frame for FrameRect { +impl Frame for RectFrame { fn draw(&self, draw: &mut UiDrawCommandList, position: Vec2, parent_size: Vec2) { //TODO: handle bottom_right < top_left let top_left = self.top_left.resolve(parent_size); @@ -132,14 +132,14 @@ impl Frame for FrameRect { } fn covers_opaque(&self) -> bool { - self.top_left.x.absolute <= 0. && self.top_left.x.relative <= 0. && - self.top_left.y.absolute <= 0. && + self.top_left.x.absolute <= 0. && self.top_left.y.relative <= 0. && - self.bottom_right.x.absolute >= 0. && + self.top_left.y.absolute <= 0. && self.bottom_right.x.relative >= 1. && - self.bottom_right.y.absolute >= 0. && + self.bottom_right.x.absolute >= 0. && self.bottom_right.y.relative >= 1. && + self.bottom_right.y.absolute >= 0. && self.color.is_opaque() && self.image.is_none() && self.corner_radius.max_f32() == 0. diff --git a/hui/src/macros.rs b/hui/src/macros.rs index 9386032..09af3fd 100644 --- a/hui/src/macros.rs +++ b/hui/src/macros.rs @@ -75,7 +75,7 @@ macro_rules! size { }; } -/// Helper macro for constructing a `FrameRect` +/// Helper macro for constructing a `RectFrame` /// /// # Example: /// ``` @@ -89,24 +89,24 @@ macro_rules! size { /// - If the `image` field is set, but not `color`, the `color` field will default to [`WHITE`](crate::color::WHITE) (to ensure visibility) /// - If both `color` and `image` are not set, the `color` field will default to [`TRANSPARENT`](crate::color::TRANSPARENT) #[macro_export] -macro_rules! frame_rect { +macro_rules! rect_frame { {} => { - $crate::frame::FrameRect::default() + $crate::frame::RectFrame::default() }; // () => { - // $crate::frame::FrameRect::default() + // $crate::frame::RectFrame::default() // }; ($expr:expr) => { { - let _frame_rect: $crate::frame::FrameRect = $crate::frame::FrameRect::from($expr); + let _frame_rect: $crate::frame::RectFrame = $crate::frame::RectFrame::from($expr); _frame_rect } }; ($image:expr, $color:expr) => { - $crate::frame::FrameRect::color_image($color, $image) + $crate::frame::RectFrame::color_image($color, $image) }; {$($ident:ident : $expr:expr),+$(,)?} => { @@ -115,9 +115,9 @@ macro_rules! frame_rect { #[allow(non_upper_case_globals)] {$(const $ident: () = ();)+} - // construct the FrameRect + // construct the RectFrame { - let mut frame_rect = $crate::frame::FrameRect::default(); + let mut frame_rect = $crate::frame::RectFrame::default(); let mut _color_is_set = false; let mut _image_is_set = false; $( @@ -148,9 +148,9 @@ macro_rules! frame_rect { // const $ident: () = (); // )+ // } - // // construct the FrameRect + // // construct the RectFrame // { - // let mut _frame_rect: $crate::frame::FrameRect = ($from).into(); + // let mut _frame_rect: $crate::frame::RectFrame = ($from).into(); // $( // let $ident = ($expr).into(); // _frame_rect.$ident = $ident;