mirror of
https://github.com/griffi-gh/hUI.git
synced 2024-11-22 07:08:42 -06:00
rename stuff
This commit is contained in:
parent
74027c52d0
commit
becbffc367
|
@ -8,7 +8,7 @@ use winit::{
|
||||||
use hui::{
|
use hui::{
|
||||||
element::{
|
element::{
|
||||||
container::Container, progress_bar::ProgressBar, rect::Rect, ElementList, UiElement
|
container::Container, progress_bar::ProgressBar, rect::Rect, ElementList, UiElement
|
||||||
}, layout::{Alignment, UiDirection, UiSize}, rectangle::{Corners, Sides}, UiInstance
|
}, layout::{Alignment, UiDirection, Size}, rectangle::{Corners, Sides}, UiInstance
|
||||||
};
|
};
|
||||||
use hui_glium::GliumUiRenderer;
|
use hui_glium::GliumUiRenderer;
|
||||||
|
|
||||||
|
@ -42,7 +42,7 @@ fn main() {
|
||||||
gap: 5.,
|
gap: 5.,
|
||||||
padding: Sides::all(5.),
|
padding: Sides::all(5.),
|
||||||
align: (Alignment::Begin, Alignment::Center).into(),
|
align: (Alignment::Begin, Alignment::Center).into(),
|
||||||
size: (UiSize::Fraction(1.), UiSize::Fraction(1.)).into(),
|
size: (Size::Fraction(1.), Size::Fraction(1.)).into(),
|
||||||
children: ElementList(vec![
|
children: ElementList(vec![
|
||||||
Box::new(ProgressBar {
|
Box::new(ProgressBar {
|
||||||
value: 0.5,
|
value: 0.5,
|
||||||
|
@ -56,7 +56,7 @@ fn main() {
|
||||||
gap: 5.,
|
gap: 5.,
|
||||||
padding: Sides::all(5.),
|
padding: Sides::all(5.),
|
||||||
align: (Alignment::End, Alignment::Center).into(),
|
align: (Alignment::End, Alignment::Center).into(),
|
||||||
size: (UiSize::Fraction(1.), UiSize::Fraction(1.)).into(),
|
size: (Size::Fraction(1.), Size::Fraction(1.)).into(),
|
||||||
children: ElementList(vec![
|
children: ElementList(vec![
|
||||||
Box::new(ProgressBar {
|
Box::new(ProgressBar {
|
||||||
value: z,
|
value: z,
|
||||||
|
@ -64,17 +64,17 @@ fn main() {
|
||||||
..Default::default()
|
..Default::default()
|
||||||
}),
|
}),
|
||||||
Box::new(Container {
|
Box::new(Container {
|
||||||
size: (UiSize::Fraction(1.), UiSize::Auto).into(),
|
size: (Size::Fraction(1.), Size::Auto).into(),
|
||||||
align: (Alignment::Center, Alignment::End).into(),
|
align: (Alignment::Center, Alignment::End).into(),
|
||||||
padding: Sides::all(5.),
|
padding: Sides::all(5.),
|
||||||
gap: 10.,
|
gap: 10.,
|
||||||
children: ElementList(vec![
|
children: ElementList(vec![
|
||||||
Box::new(Rect {
|
Box::new(Rect {
|
||||||
size: (UiSize::Fraction(0.5), UiSize::Static(30.)),
|
size: (Size::Fraction(0.5), Size::Static(30.)),
|
||||||
color: vec4(0.75, 0., 0., 1.).into()
|
color: vec4(0.75, 0., 0., 1.).into()
|
||||||
}),
|
}),
|
||||||
Box::new(Rect {
|
Box::new(Rect {
|
||||||
size: (UiSize::Fraction(z / 2. + 0.5), UiSize::Static(30.)),
|
size: (Size::Fraction(z / 2. + 0.5), Size::Static(30.)),
|
||||||
color: Corners::left_right(
|
color: Corners::left_right(
|
||||||
vec4(1., 0., 0., 1.),
|
vec4(1., 0., 0., 1.),
|
||||||
vec4(0., 1., 0., 1.)
|
vec4(0., 1., 0., 1.)
|
||||||
|
@ -84,7 +84,7 @@ fn main() {
|
||||||
..Default::default()
|
..Default::default()
|
||||||
}),
|
}),
|
||||||
Box::new(Rect {
|
Box::new(Rect {
|
||||||
size: (UiSize::Fraction(z / 2. + 0.5), UiSize::Static(30.)),
|
size: (Size::Fraction(z / 2. + 0.5), Size::Static(30.)),
|
||||||
color: vec4(0., 0.75, 0., 1.).into()
|
color: vec4(0., 0.75, 0., 1.).into()
|
||||||
}),
|
}),
|
||||||
Box::new(Container {
|
Box::new(Container {
|
||||||
|
@ -96,7 +96,7 @@ fn main() {
|
||||||
let mut x: Vec<Box<dyn UiElement>> = vec![];
|
let mut x: Vec<Box<dyn UiElement>> = vec![];
|
||||||
for i in 0..10 {
|
for i in 0..10 {
|
||||||
x.push(Box::new(Rect {
|
x.push(Box::new(Rect {
|
||||||
size: (UiSize::Static(50.), UiSize::Static(50.)),
|
size: (Size::Static(50.), Size::Static(50.)),
|
||||||
color: if i == 1 {
|
color: if i == 1 {
|
||||||
vec4(0.75, 0.75, 0.75, 0.75).into()
|
vec4(0.75, 0.75, 0.75, 0.75).into()
|
||||||
} else {
|
} else {
|
||||||
|
@ -124,7 +124,7 @@ fn main() {
|
||||||
},
|
},
|
||||||
children: ElementList(vec![
|
children: ElementList(vec![
|
||||||
Box::new(Rect {
|
Box::new(Rect {
|
||||||
size: (UiSize::Static(50.), UiSize::Static(50.)),
|
size: (Size::Static(50.), Size::Static(50.)),
|
||||||
color: vec4(1., 1., 1., 0.75).into()
|
color: vec4(1., 1., 1., 0.75).into()
|
||||||
}),
|
}),
|
||||||
]),
|
]),
|
||||||
|
|
|
@ -11,7 +11,7 @@ use hui::{
|
||||||
progress_bar::ProgressBar,
|
progress_bar::ProgressBar,
|
||||||
text::Text, ElementList,
|
text::Text, ElementList,
|
||||||
},
|
},
|
||||||
layout::{Alignment, UiDirection, UiSize},
|
layout::{Alignment, UiDirection, Size},
|
||||||
rectangle::{Corners, Sides},
|
rectangle::{Corners, Sides},
|
||||||
UiInstance,
|
UiInstance,
|
||||||
};
|
};
|
||||||
|
@ -55,12 +55,12 @@ fn main() {
|
||||||
|
|
||||||
hui.add(Container {
|
hui.add(Container {
|
||||||
align: Alignment::Center.into(),
|
align: Alignment::Center.into(),
|
||||||
size: (UiSize::Fraction(1.), UiSize::Fraction(1.)).into(),
|
size: (Size::Fraction(1.), Size::Fraction(1.)).into(),
|
||||||
background: vec4(0.1, 0.1, 0.1, 1.).into(),
|
background: vec4(0.1, 0.1, 0.1, 1.).into(),
|
||||||
children: ElementList(vec![Box::new(Container {
|
children: ElementList(vec![Box::new(Container {
|
||||||
gap: 5.,
|
gap: 5.,
|
||||||
padding: Sides::all(10.),
|
padding: Sides::all(10.),
|
||||||
size: (UiSize::Static(450.), UiSize::Auto).into(),
|
size: (Size::Static(450.), Size::Auto).into(),
|
||||||
background: vec4(0.2, 0.2, 0.5, 1.).into(),
|
background: vec4(0.2, 0.2, 0.5, 1.).into(),
|
||||||
corner_radius: Corners::all(8.),
|
corner_radius: Corners::all(8.),
|
||||||
children: elements(|el| {
|
children: elements(|el| {
|
||||||
|
@ -79,7 +79,7 @@ fn main() {
|
||||||
el.push(Box::new(Container {
|
el.push(Box::new(Container {
|
||||||
direction: UiDirection::Horizontal,
|
direction: UiDirection::Horizontal,
|
||||||
align: (Alignment::End, Alignment::Center).into(),
|
align: (Alignment::End, Alignment::Center).into(),
|
||||||
size: (UiSize::Fraction(1.), UiSize::Auto).into(),
|
size: (Size::Fraction(1.), Size::Auto).into(),
|
||||||
children: ElementList(vec![Box::new(Text {
|
children: ElementList(vec![Box::new(Text {
|
||||||
text: format!("{:.2}% ({:.1} GB)", mom_ratio * 100., mom_ratio * 10000.).into(),
|
text: format!("{:.2}% ({:.1} GB)", mom_ratio * 100., mom_ratio * 10000.).into(),
|
||||||
font: font_handle,
|
font: font_handle,
|
||||||
|
|
|
@ -9,7 +9,7 @@ use hui::{
|
||||||
container::Container,
|
container::Container,
|
||||||
text::Text, ElementList
|
text::Text, ElementList
|
||||||
},
|
},
|
||||||
layout::{Alignment, UiDirection, UiSize},
|
layout::{Alignment, UiDirection, Size},
|
||||||
rectangle::{Corners, Sides},
|
rectangle::{Corners, Sides},
|
||||||
UiInstance
|
UiInstance
|
||||||
};
|
};
|
||||||
|
@ -40,11 +40,11 @@ fn main() {
|
||||||
hui.add(Container {
|
hui.add(Container {
|
||||||
gap: 10.,
|
gap: 10.,
|
||||||
align: Alignment::Center.into(),
|
align: Alignment::Center.into(),
|
||||||
size: (UiSize::Fraction(1.), UiSize::Fraction(1.)).into(),
|
size: (Size::Fraction(1.), Size::Fraction(1.)).into(),
|
||||||
children: ElementList(vec![
|
children: ElementList(vec![
|
||||||
Box::new(Container {
|
Box::new(Container {
|
||||||
align: Alignment::Center.into(),
|
align: Alignment::Center.into(),
|
||||||
size: (UiSize::Fraction(0.5), UiSize::Fraction(0.5)).into(),
|
size: (Size::Fraction(0.5), Size::Fraction(0.5)).into(),
|
||||||
background: vec4(1., 0., 0., 1.).into(),
|
background: vec4(1., 0., 0., 1.).into(),
|
||||||
corner_radius: Corners {
|
corner_radius: Corners {
|
||||||
top_left: 10.,
|
top_left: 10.,
|
||||||
|
@ -57,7 +57,7 @@ fn main() {
|
||||||
padding: Sides::all(20.),
|
padding: Sides::all(20.),
|
||||||
direction: UiDirection::Horizontal,
|
direction: UiDirection::Horizontal,
|
||||||
align: Alignment::Center.into(),
|
align: Alignment::Center.into(),
|
||||||
size: (UiSize::Auto, UiSize::Auto).into(),
|
size: (Size::Auto, Size::Auto).into(),
|
||||||
background: vec4(0.1, 0.1, 0.1, 0.5).into(),
|
background: vec4(0.1, 0.1, 0.1, 0.5).into(),
|
||||||
corner_radius: Corners::all(8.),
|
corner_radius: Corners::all(8.),
|
||||||
children: ElementList(vec![
|
children: ElementList(vec![
|
||||||
|
@ -84,7 +84,7 @@ fn main() {
|
||||||
direction: UiDirection::Horizontal,
|
direction: UiDirection::Horizontal,
|
||||||
children: ElementList(vec![
|
children: ElementList(vec![
|
||||||
Box::new(Container {
|
Box::new(Container {
|
||||||
size: (UiSize::Static(100.), UiSize::Static(100.)).into(),
|
size: (Size::Static(100.), Size::Static(100.)).into(),
|
||||||
background: Corners::left_right(
|
background: Corners::left_right(
|
||||||
vec4(1., 0., 0., 1.),
|
vec4(1., 0., 0., 1.),
|
||||||
vec4(0., 1., 0., 1.)
|
vec4(0., 1., 0., 1.)
|
||||||
|
@ -93,7 +93,7 @@ fn main() {
|
||||||
..Default::default()
|
..Default::default()
|
||||||
}),
|
}),
|
||||||
Box::new(Container {
|
Box::new(Container {
|
||||||
size: (UiSize::Static(100.), UiSize::Static(100.)).into(),
|
size: (Size::Static(100.), Size::Static(100.)).into(),
|
||||||
background: Corners::left_right(
|
background: Corners::left_right(
|
||||||
vec4(1., 0., 0., 1.),
|
vec4(1., 0., 0., 1.),
|
||||||
vec4(0., 1., 0., 1.)
|
vec4(0., 1., 0., 1.)
|
||||||
|
@ -102,7 +102,7 @@ fn main() {
|
||||||
..Default::default()
|
..Default::default()
|
||||||
}),
|
}),
|
||||||
Box::new(Container {
|
Box::new(Container {
|
||||||
size: (UiSize::Static(100.), UiSize::Static(100.)).into(),
|
size: (Size::Static(100.), Size::Static(100.)).into(),
|
||||||
background: Corners::left_right(
|
background: Corners::left_right(
|
||||||
vec4(1., 0., 0., 1.),
|
vec4(1., 0., 0., 1.),
|
||||||
vec4(0., 1., 0., 1.)
|
vec4(0., 1., 0., 1.)
|
||||||
|
@ -111,7 +111,7 @@ fn main() {
|
||||||
..Default::default()
|
..Default::default()
|
||||||
}),
|
}),
|
||||||
Box::new(Container {
|
Box::new(Container {
|
||||||
size: (UiSize::Static(100.), UiSize::Static(100.)).into(),
|
size: (Size::Static(100.), Size::Static(100.)).into(),
|
||||||
background: Corners::left_right(
|
background: Corners::left_right(
|
||||||
vec4(1., 0., 0., 1.),
|
vec4(1., 0., 0., 1.),
|
||||||
vec4(0., 1., 0., 1.)
|
vec4(0., 1., 0., 1.)
|
||||||
|
|
|
@ -8,7 +8,7 @@ use winit::{
|
||||||
use hui::{
|
use hui::{
|
||||||
element::{
|
element::{
|
||||||
container::Container, rect::Rect, spacer::Spacer, text::Text, ElementList
|
container::Container, rect::Rect, spacer::Spacer, text::Text, ElementList
|
||||||
}, layout::UiSize, UiInstance
|
}, layout::Size, UiInstance
|
||||||
};
|
};
|
||||||
use hui_glium::GliumUiRenderer;
|
use hui_glium::GliumUiRenderer;
|
||||||
|
|
||||||
|
@ -46,7 +46,7 @@ fn main() {
|
||||||
hui.begin();
|
hui.begin();
|
||||||
|
|
||||||
hui.add(Container {
|
hui.add(Container {
|
||||||
size: (UiSize::Fraction(1.), UiSize::Fraction(1.)).into(),
|
size: (Size::Fraction(1.), Size::Fraction(1.)).into(),
|
||||||
background: vec4(0.1, 0.1, 0.1, 1.).into(),
|
background: vec4(0.1, 0.1, 0.1, 1.).into(),
|
||||||
children: elements(|elem| {
|
children: elements(|elem| {
|
||||||
elem.push(Box::new(Text {
|
elem.push(Box::new(Text {
|
||||||
|
@ -70,11 +70,11 @@ fn main() {
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
elem.push(Box::new(Rect {
|
elem.push(Box::new(Rect {
|
||||||
size: (UiSize::Fraction(1.), UiSize::Static(10.)),
|
size: (Size::Fraction(1.), Size::Static(10.)),
|
||||||
color: vec4(0., 0., 1., 1.).into(),
|
color: vec4(0., 0., 1., 1.).into(),
|
||||||
}));
|
}));
|
||||||
elem.push(Box::new(Rect {
|
elem.push(Box::new(Rect {
|
||||||
size: (UiSize::Fraction(1.), UiSize::Static(10.)),
|
size: (Size::Fraction(1.), Size::Static(10.)),
|
||||||
color: vec4(1., 1., 0., 1.).into(),
|
color: vec4(1., 1., 0., 1.).into(),
|
||||||
}));
|
}));
|
||||||
elem.push(Box::new(Text {
|
elem.push(Box::new(Text {
|
||||||
|
@ -85,11 +85,11 @@ fn main() {
|
||||||
}));
|
}));
|
||||||
if instant.elapsed().as_secs() & 1 != 0 {
|
if instant.elapsed().as_secs() & 1 != 0 {
|
||||||
elem.push(Box::new(Rect {
|
elem.push(Box::new(Rect {
|
||||||
size: (UiSize::Fraction(1.), UiSize::Static(10.)),
|
size: (Size::Fraction(1.), Size::Static(10.)),
|
||||||
color: vec4(1., 0., 0., 1.).into(),
|
color: vec4(1., 0., 0., 1.).into(),
|
||||||
}));
|
}));
|
||||||
elem.push(Box::new(Rect {
|
elem.push(Box::new(Rect {
|
||||||
size: (UiSize::Fraction(1.), UiSize::Static(10.)),
|
size: (Size::Fraction(1.), Size::Static(10.)),
|
||||||
color: vec4(0., 0., 0., 1.).into(),
|
color: vec4(0., 0., 0., 1.).into(),
|
||||||
}));
|
}));
|
||||||
elem.push(Box::new(Spacer(100.)));
|
elem.push(Box::new(Spacer(100.)));
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
//! background color, gradient and texturing
|
||||||
|
|
||||||
use glam::{vec4, Vec3, Vec4};
|
use glam::{vec4, Vec3, Vec4};
|
||||||
use crate::rectangle::Corners;
|
use crate::rectangle::Corners;
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
//! Stuff related to tesselation and UI rendering.
|
//! draw commands, tesselation and UI rendering.
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
rectangle::Corners,
|
rectangle::Corners,
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
//! element API, built-in elements like `Container`, `Button`, `Text`, etc.
|
||||||
use std::any::Any;
|
use std::any::Any;
|
||||||
use crate::{
|
use crate::{
|
||||||
draw::UiDrawCommandList, layout::LayoutInfo, measure::Response, state::StateRepo, text::TextMeasure, UiInstance
|
draw::UiDrawCommandList, layout::LayoutInfo, measure::Response, state::StateRepo, text::TextMeasure, UiInstance
|
||||||
|
|
|
@ -4,7 +4,7 @@ use crate::{
|
||||||
background::BackgroundColor,
|
background::BackgroundColor,
|
||||||
draw::{RoundedCorners, UiDrawCommand},
|
draw::{RoundedCorners, UiDrawCommand},
|
||||||
element::{ElementList, MeasureContext, ProcessContext, UiElement},
|
element::{ElementList, MeasureContext, ProcessContext, UiElement},
|
||||||
layout::{Alignment, Alignment2d, LayoutInfo, UiDirection, UiSize, UiSize2d},
|
layout::{Alignment, Alignment2d, LayoutInfo, UiDirection, Size, Size2d},
|
||||||
measure::{Hints, Response},
|
measure::{Hints, Response},
|
||||||
rectangle::{Corners, Sides}
|
rectangle::{Corners, Sides}
|
||||||
};
|
};
|
||||||
|
@ -23,7 +23,7 @@ use crate::{
|
||||||
#[setters(prefix = "with_")]
|
#[setters(prefix = "with_")]
|
||||||
pub struct Container {
|
pub struct Container {
|
||||||
#[setters(into)]
|
#[setters(into)]
|
||||||
pub size: UiSize2d,
|
pub size: Size2d,
|
||||||
pub direction: UiDirection,
|
pub direction: UiDirection,
|
||||||
pub gap: f32,
|
pub gap: f32,
|
||||||
#[setters(into)]
|
#[setters(into)]
|
||||||
|
@ -48,7 +48,7 @@ impl Container {
|
||||||
impl Default for Container {
|
impl Default for Container {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Self {
|
Self {
|
||||||
size: (UiSize::Auto, UiSize::Auto).into(),
|
size: (Size::Auto, Size::Auto).into(),
|
||||||
direction: UiDirection::Vertical,
|
direction: UiDirection::Vertical,
|
||||||
gap: 0.,
|
gap: 0.,
|
||||||
padding: Sides::all(0.),
|
padding: Sides::all(0.),
|
||||||
|
@ -63,14 +63,14 @@ impl Default for Container {
|
||||||
impl Container {
|
impl Container {
|
||||||
pub fn measure_max_inner_size(&self, layout: &LayoutInfo) -> Vec2 {
|
pub fn measure_max_inner_size(&self, layout: &LayoutInfo) -> Vec2 {
|
||||||
let outer_size_x = match self.size.width {
|
let outer_size_x = match self.size.width {
|
||||||
UiSize::Auto => layout.max_size.x,
|
Size::Auto => layout.max_size.x,
|
||||||
UiSize::Fraction(p) => layout.max_size.x * p,
|
Size::Fraction(p) => layout.max_size.x * p,
|
||||||
UiSize::Static(p) => p,
|
Size::Static(p) => p,
|
||||||
};
|
};
|
||||||
let outer_size_y = match self.size.height {
|
let outer_size_y = match self.size.height {
|
||||||
UiSize::Auto => layout.max_size.y,
|
Size::Auto => layout.max_size.y,
|
||||||
UiSize::Fraction(p) => layout.max_size.y * p,
|
Size::Fraction(p) => layout.max_size.y * p,
|
||||||
UiSize::Static(p) => p,
|
Size::Static(p) => p,
|
||||||
};
|
};
|
||||||
vec2(
|
vec2(
|
||||||
outer_size_x - (self.padding.left + self.padding.right),
|
outer_size_x - (self.padding.left + self.padding.right),
|
||||||
|
@ -116,14 +116,14 @@ impl UiElement for Container {
|
||||||
);
|
);
|
||||||
|
|
||||||
match self.size.width {
|
match self.size.width {
|
||||||
UiSize::Auto => (),
|
Size::Auto => (),
|
||||||
UiSize::Fraction(percentage) => size.x = ctx.layout.max_size.x * percentage,
|
Size::Fraction(percentage) => size.x = ctx.layout.max_size.x * percentage,
|
||||||
UiSize::Static(pixels) => size.x = pixels,
|
Size::Static(pixels) => size.x = pixels,
|
||||||
}
|
}
|
||||||
match self.size.height {
|
match self.size.height {
|
||||||
UiSize::Auto => (),
|
Size::Auto => (),
|
||||||
UiSize::Fraction(percentage) => size.y = ctx.layout.max_size.y * percentage,
|
Size::Fraction(percentage) => size.y = ctx.layout.max_size.y * percentage,
|
||||||
UiSize::Static(pixels) => size.y = pixels,
|
Size::Static(pixels) => size.y = pixels,
|
||||||
}
|
}
|
||||||
|
|
||||||
Response {
|
Response {
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
use glam::{vec2, Vec4, vec4};
|
use glam::{vec2, Vec4, vec4};
|
||||||
use crate::{
|
use crate::{
|
||||||
draw::{RoundedCorners, UiDrawCommand}, element::{MeasureContext, ProcessContext, UiElement}, layout::UiSize, measure::Response, rectangle::Corners
|
draw::{RoundedCorners, UiDrawCommand}, element::{MeasureContext, ProcessContext, UiElement}, layout::Size, measure::Response, rectangle::Corners
|
||||||
};
|
};
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy)]
|
#[derive(Debug, Clone, Copy)]
|
||||||
pub struct ProgressBar {
|
pub struct ProgressBar {
|
||||||
pub size: (UiSize, UiSize),
|
pub size: (Size, Size),
|
||||||
pub value: f32,
|
pub value: f32,
|
||||||
pub color_foreground: Vec4,
|
pub color_foreground: Vec4,
|
||||||
pub color_background: Vec4,
|
pub color_background: Vec4,
|
||||||
|
@ -19,7 +19,7 @@ impl ProgressBar {
|
||||||
impl Default for ProgressBar {
|
impl Default for ProgressBar {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Self {
|
Self {
|
||||||
size: (UiSize::Auto, UiSize::Auto),
|
size: (Size::Auto, Size::Auto),
|
||||||
value: 0.,
|
value: 0.,
|
||||||
color_foreground: vec4(0.0, 0.0, 1.0, 1.0),
|
color_foreground: vec4(0.0, 0.0, 1.0, 1.0),
|
||||||
color_background: vec4(0.0, 0.0, 0.0, 1.0),
|
color_background: vec4(0.0, 0.0, 0.0, 1.0),
|
||||||
|
@ -35,14 +35,14 @@ impl UiElement for ProgressBar {
|
||||||
Response {
|
Response {
|
||||||
size: vec2(
|
size: vec2(
|
||||||
match self.size.0 {
|
match self.size.0 {
|
||||||
UiSize::Auto => ctx.layout.max_size.x.max(300.),
|
Size::Auto => ctx.layout.max_size.x.max(300.),
|
||||||
UiSize::Fraction(p) => ctx.layout.max_size.x * p,
|
Size::Fraction(p) => ctx.layout.max_size.x * p,
|
||||||
UiSize::Static(p) => p,
|
Size::Static(p) => p,
|
||||||
},
|
},
|
||||||
match self.size.1 {
|
match self.size.1 {
|
||||||
UiSize::Auto => Self::DEFAULT_HEIGHT,
|
Size::Auto => Self::DEFAULT_HEIGHT,
|
||||||
UiSize::Fraction(p) => ctx.layout.max_size.y * p,
|
Size::Fraction(p) => ctx.layout.max_size.y * p,
|
||||||
UiSize::Static(p) => p,
|
Size::Static(p) => p,
|
||||||
}
|
}
|
||||||
),
|
),
|
||||||
hints: Default::default(),
|
hints: Default::default(),
|
||||||
|
|
|
@ -3,19 +3,19 @@ use crate::{
|
||||||
background::BackgroundColor,
|
background::BackgroundColor,
|
||||||
draw::UiDrawCommand,
|
draw::UiDrawCommand,
|
||||||
element::{MeasureContext, ProcessContext, UiElement},
|
element::{MeasureContext, ProcessContext, UiElement},
|
||||||
layout::UiSize,
|
layout::Size,
|
||||||
measure::Response
|
measure::Response
|
||||||
};
|
};
|
||||||
|
|
||||||
pub struct Rect {
|
pub struct Rect {
|
||||||
pub size: (UiSize, UiSize),
|
pub size: (Size, Size),
|
||||||
pub color: BackgroundColor,
|
pub color: BackgroundColor,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for Rect {
|
impl Default for Rect {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Self {
|
Self {
|
||||||
size: (UiSize::Static(10.), UiSize::Static(10.)),
|
size: (Size::Static(10.), Size::Static(10.)),
|
||||||
color: Vec4::new(0., 0., 0., 0.5).into(),
|
color: Vec4::new(0., 0., 0., 0.5).into(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -26,14 +26,14 @@ impl UiElement for Rect {
|
||||||
Response {
|
Response {
|
||||||
size: vec2(
|
size: vec2(
|
||||||
match self.size.0 {
|
match self.size.0 {
|
||||||
UiSize::Auto => ctx.layout.max_size.x,
|
Size::Auto => ctx.layout.max_size.x,
|
||||||
UiSize::Fraction(percentage) => ctx.layout.max_size.x * percentage,
|
Size::Fraction(percentage) => ctx.layout.max_size.x * percentage,
|
||||||
UiSize::Static(pixels) => pixels,
|
Size::Static(pixels) => pixels,
|
||||||
},
|
},
|
||||||
match self.size.1 {
|
match self.size.1 {
|
||||||
UiSize::Auto => ctx.layout.max_size.y,
|
Size::Auto => ctx.layout.max_size.y,
|
||||||
UiSize::Fraction(percentage) => ctx.layout.max_size.y * percentage,
|
Size::Fraction(percentage) => ctx.layout.max_size.y * percentage,
|
||||||
UiSize::Static(pixels) => pixels,
|
Size::Static(pixels) => pixels,
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
hints: Default::default(),
|
hints: Default::default(),
|
||||||
|
|
|
@ -4,7 +4,7 @@ use glam::{vec2, Vec4};
|
||||||
use crate::{
|
use crate::{
|
||||||
draw::UiDrawCommand,
|
draw::UiDrawCommand,
|
||||||
element::{MeasureContext, ProcessContext, UiElement},
|
element::{MeasureContext, ProcessContext, UiElement},
|
||||||
layout::UiSize,
|
layout::Size,
|
||||||
measure::Response,
|
measure::Response,
|
||||||
text::FontHandle,
|
text::FontHandle,
|
||||||
};
|
};
|
||||||
|
@ -22,7 +22,7 @@ use crate::{
|
||||||
pub struct Text {
|
pub struct Text {
|
||||||
#[setters(into)]
|
#[setters(into)]
|
||||||
pub text: Cow<'static, str>,
|
pub text: Cow<'static, str>,
|
||||||
pub size: (UiSize, UiSize),
|
pub size: (Size, Size),
|
||||||
pub color: Vec4,
|
pub color: Vec4,
|
||||||
pub font: FontHandle,
|
pub font: FontHandle,
|
||||||
pub text_size: u16,
|
pub text_size: u16,
|
||||||
|
@ -32,7 +32,7 @@ impl Default for Text {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Self {
|
Self {
|
||||||
text: "".into(),
|
text: "".into(),
|
||||||
size: (UiSize::Auto, UiSize::Auto),
|
size: (Size::Auto, Size::Auto),
|
||||||
color: Vec4::new(1., 1., 1., 1.),
|
color: Vec4::new(1., 1., 1., 1.),
|
||||||
font: FontHandle::default(),
|
font: FontHandle::default(),
|
||||||
text_size: 16,
|
text_size: 16,
|
||||||
|
@ -43,7 +43,7 @@ impl Default for Text {
|
||||||
impl UiElement for Text {
|
impl UiElement for Text {
|
||||||
fn measure(&self, ctx: MeasureContext) -> Response {
|
fn measure(&self, ctx: MeasureContext) -> Response {
|
||||||
let mut size = (0., 0.);
|
let mut size = (0., 0.);
|
||||||
if matches!(self.size.0, UiSize::Auto) || matches!(self.size.1, UiSize::Auto) {
|
if matches!(self.size.0, Size::Auto) || matches!(self.size.1, Size::Auto) {
|
||||||
let res = ctx.text_measure.measure(self.font, self.text_size, &self.text);
|
let res = ctx.text_measure.measure(self.font, self.text_size, &self.text);
|
||||||
size.0 = res.max_width;
|
size.0 = res.max_width;
|
||||||
size.1 = res.height;
|
size.1 = res.height;
|
||||||
|
@ -51,14 +51,14 @@ impl UiElement for Text {
|
||||||
Response {
|
Response {
|
||||||
size: vec2(
|
size: vec2(
|
||||||
match self.size.0 {
|
match self.size.0 {
|
||||||
UiSize::Auto => size.0,
|
Size::Auto => size.0,
|
||||||
UiSize::Fraction(percentage) => ctx.layout.max_size.x * percentage,
|
Size::Fraction(percentage) => ctx.layout.max_size.x * percentage,
|
||||||
UiSize::Static(pixels) => pixels,
|
Size::Static(pixels) => pixels,
|
||||||
},
|
},
|
||||||
match self.size.1 {
|
match self.size.1 {
|
||||||
UiSize::Auto => size.1,
|
Size::Auto => size.1,
|
||||||
UiSize::Fraction(percentage) => ctx.layout.max_size.y * percentage,
|
Size::Fraction(percentage) => ctx.layout.max_size.y * percentage,
|
||||||
UiSize::Static(pixels) => pixels,
|
Size::Static(pixels) => pixels,
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
hints: Default::default(),
|
hints: Default::default(),
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
//! input, window events and event handling
|
||||||
|
|
||||||
use glam::Vec2;
|
use glam::Vec2;
|
||||||
|
|
||||||
/// Represents a mouse button.
|
/// Represents a mouse button.
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
//! keyboard, mouse, and touch input handling
|
||||||
|
|
||||||
pub(crate) struct UiInputState {
|
pub(crate) struct UiInputState {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
//! Layout related types and functions
|
//! element layout, alignment and sizing
|
||||||
|
|
||||||
use glam::Vec2;
|
use glam::Vec2;
|
||||||
|
|
||||||
|
@ -81,7 +81,7 @@ impl From<Alignment> for Alignment2d {
|
||||||
/// Can be either a static size in pixels, a fraction the parent size or auto-calculated\
|
/// Can be either a static size in pixels, a fraction the parent size or auto-calculated\
|
||||||
/// (Meaning of `auto` is entirely dependent on the element).
|
/// (Meaning of `auto` is entirely dependent on the element).
|
||||||
#[derive(Default, Debug, Clone, Copy, PartialEq)]
|
#[derive(Default, Debug, Clone, Copy, PartialEq)]
|
||||||
pub enum UiSize {
|
pub enum Size {
|
||||||
#[default]
|
#[default]
|
||||||
/// Automatically calculate size based on content
|
/// Automatically calculate size based on content
|
||||||
Auto,
|
Auto,
|
||||||
|
@ -95,7 +95,7 @@ pub enum UiSize {
|
||||||
Static(f32),
|
Static(f32),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<f32> for UiSize {
|
impl From<f32> for Size {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn from(value: f32) -> Self {
|
fn from(value: f32) -> Self {
|
||||||
Self::Static(value)
|
Self::Static(value)
|
||||||
|
@ -103,22 +103,22 @@ impl From<f32> for UiSize {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Default, Debug, Clone, Copy, PartialEq)]
|
#[derive(Default, Debug, Clone, Copy, PartialEq)]
|
||||||
pub struct UiSize2d {
|
pub struct Size2d {
|
||||||
pub width: UiSize,
|
pub width: Size,
|
||||||
pub height: UiSize,
|
pub height: Size,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<(UiSize, UiSize)> for UiSize2d {
|
impl From<(Size, Size)> for Size2d {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn from((width, height): (UiSize, UiSize)) -> Self {
|
fn from((width, height): (Size, Size)) -> Self {
|
||||||
Self { width, height }
|
Self { width, height }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//XXX: should this exist?
|
//XXX: should this exist?
|
||||||
impl From<UiSize> for UiSize2d {
|
impl From<Size> for Size2d {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn from(size: UiSize) -> Self {
|
fn from(size: Size) -> Self {
|
||||||
Self {
|
Self {
|
||||||
width: size,
|
width: size,
|
||||||
height: size,
|
height: size,
|
||||||
|
@ -126,71 +126,6 @@ impl From<UiSize> for UiSize2d {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO?: add `UiSize2d` from `(Into<UiSize>, Into<UiSize>)` or Into<UiSize> conversion
|
|
||||||
|
|
||||||
/// Constructs a `UiSize` or `UiSize2d` from a literal or expression
|
|
||||||
///
|
|
||||||
/// # Syntax:
|
|
||||||
/// - `auto` - `UiSize::Auto`
|
|
||||||
/// - `x` - `UiSize::Static(x)`
|
|
||||||
/// - `x%` - `UiSize::Fraction(x / 100.)` *(literal only)*
|
|
||||||
/// - `x/` - `UiSize::Fraction(x)`
|
|
||||||
///
|
|
||||||
/// ...where `x` is a literal, identifier or an expression wrapped in parentheses
|
|
||||||
///
|
|
||||||
/// # Note:
|
|
||||||
/// - If a single argument is provided, it creates a `UiSize` using the rules specified above\
|
|
||||||
/// - If two arguments are provided, it creates a `UiSize2d` with the first value as width and the second as height\
|
|
||||||
/// Example: `size!(100, 50%)` creates a `UiSize2d` with width `100` (`UiSize::Static(100.)`) and height `50%` (`UiSize::Fraction(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)`).\
|
|
||||||
/// This does not apply to single identifiers (`x`) or literals (`5`)
|
|
||||||
#[macro_export]
|
|
||||||
macro_rules! size {
|
|
||||||
(auto) => {
|
|
||||||
$crate::layout::UiSize::Auto
|
|
||||||
};
|
|
||||||
|
|
||||||
($x:literal) => {
|
|
||||||
$crate::layout::UiSize::Static($x as f32)
|
|
||||||
};
|
|
||||||
($x:literal %) => {
|
|
||||||
$crate::layout::UiSize::Fraction($x as f32 / 100.)
|
|
||||||
};
|
|
||||||
($x:literal /) => {
|
|
||||||
$crate::layout::UiSize::Fraction($x as f32)
|
|
||||||
};
|
|
||||||
|
|
||||||
($x:ident) => {
|
|
||||||
$crate::layout::UiSize::Static($x as f32)
|
|
||||||
};
|
|
||||||
($x:ident /) => {
|
|
||||||
$crate::layout::UiSize::Fraction($x as f32)
|
|
||||||
};
|
|
||||||
|
|
||||||
(($x:expr)) => {
|
|
||||||
$crate::layout::UiSize::Static(($x) as f32)
|
|
||||||
};
|
|
||||||
(($x:expr) /) => {
|
|
||||||
$crate::layout::UiSize::Fraction(($x) as f32)
|
|
||||||
};
|
|
||||||
|
|
||||||
($x:tt , $y:tt $($ys:tt)?) => {
|
|
||||||
$crate::layout::UiSize2d {
|
|
||||||
width: $crate::layout::size!($x),
|
|
||||||
height: $crate::layout::size!($y $($ys)?),
|
|
||||||
}
|
|
||||||
};
|
|
||||||
($x:tt $($xs:tt)? , $y:tt $($ys:tt)?) => {
|
|
||||||
$crate::layout::UiSize2d {
|
|
||||||
width: $crate::layout::size!($x $($xs)?),
|
|
||||||
height: $crate::layout::size!($y $($ys)?),
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
pub use size;
|
|
||||||
|
|
||||||
/// Represents the direction of the layout\
|
/// Represents the direction of the layout\
|
||||||
/// (for example, the direction of a container's children)\
|
/// (for example, the direction of a container's children)\
|
||||||
///
|
///
|
||||||
|
|
|
@ -10,6 +10,7 @@
|
||||||
#![forbid(unsafe_op_in_unsafe_fn)]
|
#![forbid(unsafe_op_in_unsafe_fn)]
|
||||||
|
|
||||||
mod instance;
|
mod instance;
|
||||||
|
mod macros;
|
||||||
pub mod layout;
|
pub mod layout;
|
||||||
pub mod rectangle;
|
pub mod rectangle;
|
||||||
pub mod background;
|
pub mod background;
|
||||||
|
|
62
hui/src/macros.rs
Normal file
62
hui/src/macros.rs
Normal file
|
@ -0,0 +1,62 @@
|
||||||
|
|
||||||
|
/// Constructs a `Size` or `Size2d` from a literal or expression
|
||||||
|
///
|
||||||
|
/// # Syntax:
|
||||||
|
/// - `auto` - `Size::Auto`
|
||||||
|
/// - `x` - `Size::Static(x)`
|
||||||
|
/// - `x%` - `Size::Fraction(x / 100.)` *(literal only)*
|
||||||
|
/// - `x/` - `Size::Fraction(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)`)
|
||||||
|
/// - `%` 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)`).\
|
||||||
|
/// This does not apply to single identifiers (`x`) or literals (`5`)
|
||||||
|
#[macro_export]
|
||||||
|
macro_rules! size {
|
||||||
|
(auto) => {
|
||||||
|
$crate::layout::Size::Auto
|
||||||
|
};
|
||||||
|
|
||||||
|
($x:literal) => {
|
||||||
|
$crate::layout::Size::Static($x as f32)
|
||||||
|
};
|
||||||
|
($x:literal %) => {
|
||||||
|
$crate::layout::Size::Fraction($x as f32 / 100.)
|
||||||
|
};
|
||||||
|
($x:literal /) => {
|
||||||
|
$crate::layout::Size::Fraction($x as f32)
|
||||||
|
};
|
||||||
|
|
||||||
|
($x:ident) => {
|
||||||
|
$crate::layout::Size::Static($x as f32)
|
||||||
|
};
|
||||||
|
($x:ident /) => {
|
||||||
|
$crate::layout::Size::Fraction($x as f32)
|
||||||
|
};
|
||||||
|
|
||||||
|
(($x:expr)) => {
|
||||||
|
$crate::layout::Size::Static(($x) as f32)
|
||||||
|
};
|
||||||
|
(($x:expr) /) => {
|
||||||
|
$crate::layout::Size::Fraction(($x) as f32)
|
||||||
|
};
|
||||||
|
|
||||||
|
($x:tt , $y:tt $($ys:tt)?) => {
|
||||||
|
$crate::layout::Size2d {
|
||||||
|
width: $crate::size!($x),
|
||||||
|
height: $crate::size!($y $($ys)?),
|
||||||
|
}
|
||||||
|
};
|
||||||
|
($x:tt $($xs:tt)? , $y:tt $($ys:tt)?) => {
|
||||||
|
$crate::layout::Size2d {
|
||||||
|
width: $crate::size!($x $($xs)?),
|
||||||
|
height: $crate::size!($y $($ys)?),
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
|
@ -1,3 +1,5 @@
|
||||||
|
//! element measurement, hints and responses
|
||||||
|
|
||||||
use glam::Vec2;
|
use glam::Vec2;
|
||||||
|
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
//! state managment for stateful elements
|
||||||
|
|
||||||
use hashbrown::{HashMap, HashSet};
|
use hashbrown::{HashMap, HashSet};
|
||||||
use nohash_hasher::BuildNoHashHasher;
|
use nohash_hasher::BuildNoHashHasher;
|
||||||
use std::any::Any;
|
use std::any::Any;
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
//! text rendering, styling, measuring
|
||||||
|
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
mod font;
|
mod font;
|
||||||
|
|
Loading…
Reference in a new issue