make hacky macro even hackier

This commit is contained in:
griffi-gh 2024-03-24 02:19:26 +01:00
parent 9ba0a7e762
commit 7a64a6b750
3 changed files with 29 additions and 13 deletions

View file

@ -5,7 +5,7 @@ use hui::{
progress_bar::ProgressBar,
text::Text,
UiElementExt,
}, frame::FrameRect, layout::{Alignment, Direction}, size
}, frame::FrameRect, frame_rect, layout::{Alignment, Direction}, size
};
#[path = "../boilerplate.rs"]
@ -31,10 +31,10 @@ ui_main!{
.with_gap(5.)
.with_padding(10.)
.with_size(size!(450, auto))
.with_background(
FrameRect::color((0.2, 0.2, 0.5))
.with_corner_radius(8.)
)
.with_background(frame_rect! {
color: (0.2, 0.2, 0.5),
corner_radius: 8.
})
.with_children(|ui| {
if instant.elapsed().as_secs_f32() < 5. {
Text::default()

View file

@ -7,7 +7,7 @@ use hui::{
text::Text,
transformer::ElementTransformExt,
UiElementExt
}, frame::FrameRect, layout::Alignment, rect::Corners, size, text::FontHandle
}, frame::FrameRect, frame_rect, layout::Alignment, rect::Corners, size, text::FontHandle
};
#[path = "../boilerplate.rs"]
@ -37,10 +37,10 @@ ui_main!(
.with_align((Alignment::Center, Alignment::Begin))
.with_padding(15.)
.with_gap(10.)
.with_background(
FrameRect::color((0., 0., 0., 0.5))
.with_corner_radius(8.)
)
.with_background(frame_rect! {
color: (0., 0., 0., 0.5),
corner_radius: 8.
})
.with_children(|ui| {
Text::default()
.with_text("Did you know?")

View file

@ -64,10 +64,14 @@ macro_rules! size {
/// Helper macro for constructing a `FrameRect`
#[macro_export]
macro_rules! frame_rect {
() => {
{} => {
$crate::frame::FrameRect::default()
};
// () => {
// $crate::frame::FrameRect::default()
// };
($expr:expr) => {
{
let _frame_rect: $crate::frame::FrameRect = $crate::frame::FrameRect::from($expr);
@ -88,10 +92,22 @@ macro_rules! frame_rect {
// construct the FrameRect
{
let mut frame_rect = $crate::frame::FrameRect::default();
let mut _color_is_set = false;
let mut _image_is_set = false;
$(
let $ident = ($expr).into();
frame_rect.$ident = $ident;
{
frame_rect.$ident = ($expr).into();
if stringify!($ident) == "image" {
_image_is_set = true;
}
if stringify!($ident) == "color" {
_color_is_set = true;
}
}
)+
if frame_rect.image.is_some() && _image_is_set && !_color_is_set {
frame_rect.color = (1., 1., 1., 1.).into();
}
frame_rect
}
}