rename FillRect to FrameView

This commit is contained in:
griffi-gh 2024-04-17 15:44:47 +02:00
parent 7b671d2f3d
commit 45829d5fef
6 changed files with 35 additions and 29 deletions

View file

@ -9,7 +9,7 @@ use winit::{
};
use hui::{
element::{
container::Container, fill_rect::FillRect, progress_bar::ProgressBar, ElementList, UiElement
container::Container, fill_rect::FrameView, progress_bar::ProgressBar, ElementList, UiElement
}, frame::FrameRect, layout::{Alignment, Direction, Size}, rect::{Corners, Sides}, UiInstance
};
use hui_glium::GliumUiRenderer;
@ -71,11 +71,11 @@ fn main() {
padding: Sides::all(5.),
gap: 10.,
children: ElementList(vec![
Box::new(FillRect {
Box::new(FrameView {
size: (Size::Relative(0.5), Size::Absolute(30.)).into(),
frame: Box::new(vec4(0.75, 0., 0., 1.)),
}),
Box::new(FillRect {
Box::new(FrameView {
size: (Size::Relative(z / 2. + 0.5), Size::Absolute(30.)).into(),
frame: Box::new(Corners::left_right(
vec4(1., 0., 0., 1.),
@ -85,7 +85,7 @@ fn main() {
]),
..Default::default()
}),
Box::new(FillRect {
Box::new(FrameView {
size: (Size::Relative(z / 2. + 0.5), Size::Absolute(30.)).into(),
frame: Box::new(vec4(0., 0.75, 0., 1.)),
}),
@ -97,7 +97,7 @@ fn main() {
children: {
let mut x: Vec<Box<dyn UiElement>> = vec![];
for i in 0..10 {
x.push(Box::new(FillRect {
x.push(Box::new(FrameView {
size: (Size::Absolute(50.), Size::Absolute(50.)).into(),
frame: Box::new(if i == 1 {
vec4(0.75, 0.75, 0.75, 0.75)
@ -124,7 +124,7 @@ fn main() {
right: 40.,
},
children: ElementList(vec![
Box::new(FillRect {
Box::new(FrameView {
size: (Size::Absolute(50.), Size::Absolute(50.)).into(),
frame: Box::new(vec4(1., 1., 1., 0.75)),
}),

View file

@ -9,7 +9,7 @@ use winit::{
};
use hui::{
element::{
container::Container, fill_rect::FillRect, spacer::Spacer, text::Text, ElementList
container::Container, fill_rect::FrameView, spacer::Spacer, text::Text, ElementList
}, frame::FrameRect, layout::Size, UiInstance
};
use hui_glium::GliumUiRenderer;
@ -71,11 +71,11 @@ fn main() {
..Default::default()
}));
}
elem.push(Box::new(FillRect {
elem.push(Box::new(FrameView {
size: (Size::Relative(1.), Size::Absolute(10.)).into(),
frame: Box::new(vec4(0., 0., 1., 1.)),
}));
elem.push(Box::new(FillRect {
elem.push(Box::new(FrameView {
size: (Size::Relative(1.), Size::Absolute(10.)).into(),
frame: Box::new(vec4(1., 1., 0., 1.)),
}));
@ -86,11 +86,11 @@ fn main() {
..Default::default()
}));
if instant.elapsed().as_secs() & 1 != 0 {
elem.push(Box::new(FillRect {
elem.push(Box::new(FrameView {
size: (Size::Relative(1.), Size::Absolute(10.)).into(),
frame: Box::new(vec4(1., 0., 0., 1.)),
}));
elem.push(Box::new(FillRect {
elem.push(Box::new(FrameView {
size: (Size::Relative(1.), Size::Absolute(10.)).into(),
frame: Box::new(vec4(0., 0., 0., 1.)),
}));

View file

@ -2,7 +2,7 @@ use std::time::Instant;
use hui::{
color, element::{
container::Container,
fill_rect::FillRect,
fill_rect::FrameView,
UiElementExt
}, frame_rect, layout::{Alignment, Direction}, size
};
@ -28,7 +28,7 @@ ui_main!(
.with_wrap(true)
.with_children(|ui| {
for i in 0..10 {
FillRect::default()
FrameView::default()
.with_size(size!((40 + i * 10)))
.with_frame(frame_rect! {
color: color::DARK_RED,

View file

@ -3,7 +3,7 @@ use hui::{
color,
element::{
container::Container,
fill_rect::FillRect,
fill_rect::FrameView,
slider::Slider,
text::Text,
UiElementExt
@ -54,7 +54,7 @@ ui_main!(
.add_child(ui);
})
.add_child(ui);
FillRect::default()
FrameView::default()
.with_size(size!(600, 75))
.with_frame(NinePatchFrame::from_asset(*asset).with_color(color::GREEN))
.add_child(ui);
@ -62,7 +62,7 @@ ui_main!(
.with_color(color::BLACK)
.with_text_size(32)
.add_child(ui);
FillRect::default()
FrameView::default()
.with_size(size!(700, 50))
.with_frame(NinePatchFrame::from_asset(*asset).with_color((
(1., 0., 1.),

View file

@ -6,7 +6,7 @@ use hui::{
layout::{Alignment, Direction},
element::{
container::Container,
fill_rect::FillRect,
fill_rect::FrameView,
image::Image,
text::Text,
UiElementExt
@ -62,7 +62,7 @@ ui_main!(
.add_child(ui);
})
.add_child(ui);
FillRect::default()
FrameView::default()
.with_size(size!(100%, 1))
.with_frame(color::rgb_hex(0x2d2d30))
.add_child(ui);
@ -75,7 +75,7 @@ ui_main!(
.with_size(size!(54, 100%))
.with_background(color::rgb_hex(0x343334))
.add_child(ui);
FillRect::default()
FrameView::default()
.with_size(size!(1, 100%))
.with_frame(color::rgb_hex(0x2d2d30))
.add_child(ui);

View file

@ -1,20 +1,18 @@
//! Simple filled rectangle with the specified size, background and corner radius
//! Simple element that displays the specified frame
use derive_setters::Setters;
use glam::vec2;
use crate::{
draw::{RoundedCorners, UiDrawCommand},
element::{MeasureContext, ProcessContext, UiElement},
frame::{Frame, FrameRect},
layout::{compute_size, Size, Size2d},
layout::{compute_size, Size2d},
measure::Response,
size
};
/// Simple filled rectangle with the specified size, background, and corner radius
/// Simple rectangle that displays the specified frame
#[derive(Setters)]
#[setters(prefix = "with_")]
pub struct FillRect {
pub struct FrameView {
/// Size of the rectangle
#[setters(into)]
pub size: Size2d,
@ -24,14 +22,22 @@ pub struct FillRect {
pub frame: Box<dyn Frame>,
}
impl FillRect {
impl FrameView {
pub fn new(frame: impl Frame + 'static) -> Self {
Self {
size: size!(10, 10),
frame: Box::new(frame),
}
}
//setters:
pub fn with_frame(mut self, frame: impl Frame + 'static) -> Self {
self.frame = Box::new(frame);
self
}
}
impl Default for FillRect {
impl Default for FrameView {
fn default() -> Self {
Self {
size: size!(10, 10),
@ -40,9 +46,9 @@ impl Default for FillRect {
}
}
impl UiElement for FillRect {
impl UiElement for FrameView {
fn name(&self) -> &'static str {
"fill_rect"
"frame_view"
}
fn size(&self) -> Option<Size2d> {