mirror of
https://github.com/griffi-gh/hUI.git
synced 2024-11-25 16:38:42 -06:00
make hacky macro even hackier
This commit is contained in:
parent
9ba0a7e762
commit
7a64a6b750
|
@ -5,7 +5,7 @@ use hui::{
|
||||||
progress_bar::ProgressBar,
|
progress_bar::ProgressBar,
|
||||||
text::Text,
|
text::Text,
|
||||||
UiElementExt,
|
UiElementExt,
|
||||||
}, frame::FrameRect, layout::{Alignment, Direction}, size
|
}, frame::FrameRect, frame_rect, layout::{Alignment, Direction}, size
|
||||||
};
|
};
|
||||||
|
|
||||||
#[path = "../boilerplate.rs"]
|
#[path = "../boilerplate.rs"]
|
||||||
|
@ -31,10 +31,10 @@ ui_main!{
|
||||||
.with_gap(5.)
|
.with_gap(5.)
|
||||||
.with_padding(10.)
|
.with_padding(10.)
|
||||||
.with_size(size!(450, auto))
|
.with_size(size!(450, auto))
|
||||||
.with_background(
|
.with_background(frame_rect! {
|
||||||
FrameRect::color((0.2, 0.2, 0.5))
|
color: (0.2, 0.2, 0.5),
|
||||||
.with_corner_radius(8.)
|
corner_radius: 8.
|
||||||
)
|
})
|
||||||
.with_children(|ui| {
|
.with_children(|ui| {
|
||||||
if instant.elapsed().as_secs_f32() < 5. {
|
if instant.elapsed().as_secs_f32() < 5. {
|
||||||
Text::default()
|
Text::default()
|
||||||
|
|
|
@ -7,7 +7,7 @@ use hui::{
|
||||||
text::Text,
|
text::Text,
|
||||||
transformer::ElementTransformExt,
|
transformer::ElementTransformExt,
|
||||||
UiElementExt
|
UiElementExt
|
||||||
}, frame::FrameRect, layout::Alignment, rect::Corners, size, text::FontHandle
|
}, frame::FrameRect, frame_rect, layout::Alignment, rect::Corners, size, text::FontHandle
|
||||||
};
|
};
|
||||||
|
|
||||||
#[path = "../boilerplate.rs"]
|
#[path = "../boilerplate.rs"]
|
||||||
|
@ -37,10 +37,10 @@ ui_main!(
|
||||||
.with_align((Alignment::Center, Alignment::Begin))
|
.with_align((Alignment::Center, Alignment::Begin))
|
||||||
.with_padding(15.)
|
.with_padding(15.)
|
||||||
.with_gap(10.)
|
.with_gap(10.)
|
||||||
.with_background(
|
.with_background(frame_rect! {
|
||||||
FrameRect::color((0., 0., 0., 0.5))
|
color: (0., 0., 0., 0.5),
|
||||||
.with_corner_radius(8.)
|
corner_radius: 8.
|
||||||
)
|
})
|
||||||
.with_children(|ui| {
|
.with_children(|ui| {
|
||||||
Text::default()
|
Text::default()
|
||||||
.with_text("Did you know?")
|
.with_text("Did you know?")
|
||||||
|
|
|
@ -64,10 +64,14 @@ macro_rules! size {
|
||||||
/// Helper macro for constructing a `FrameRect`
|
/// Helper macro for constructing a `FrameRect`
|
||||||
#[macro_export]
|
#[macro_export]
|
||||||
macro_rules! frame_rect {
|
macro_rules! frame_rect {
|
||||||
() => {
|
{} => {
|
||||||
$crate::frame::FrameRect::default()
|
$crate::frame::FrameRect::default()
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// () => {
|
||||||
|
// $crate::frame::FrameRect::default()
|
||||||
|
// };
|
||||||
|
|
||||||
($expr:expr) => {
|
($expr:expr) => {
|
||||||
{
|
{
|
||||||
let _frame_rect: $crate::frame::FrameRect = $crate::frame::FrameRect::from($expr);
|
let _frame_rect: $crate::frame::FrameRect = $crate::frame::FrameRect::from($expr);
|
||||||
|
@ -88,10 +92,22 @@ macro_rules! frame_rect {
|
||||||
// construct the FrameRect
|
// construct the FrameRect
|
||||||
{
|
{
|
||||||
let mut frame_rect = $crate::frame::FrameRect::default();
|
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
|
frame_rect
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue