app work
This commit is contained in:
2
TODO
2
TODO
@@ -8,6 +8,8 @@ text
|
|||||||
|
|
||||||
masks r just made to bare minimum work
|
masks r just made to bare minimum work
|
||||||
|
|
||||||
|
move span lengths to the children themselves
|
||||||
|
|
||||||
scaling
|
scaling
|
||||||
could be just a simple scaling factor that multiplies abs
|
could be just a simple scaling factor that multiplies abs
|
||||||
and need to ensure text uses raw abs and not scaled abs
|
and need to ensure text uses raw abs and not scaled abs
|
||||||
|
|||||||
@@ -38,7 +38,8 @@ pub struct Padding {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Padding {
|
impl Padding {
|
||||||
pub fn uniform(amt: f32) -> Self {
|
pub fn uniform(amt: impl UiNum) -> Self {
|
||||||
|
let amt = amt.to_f32();
|
||||||
Self {
|
Self {
|
||||||
left: amt,
|
left: amt,
|
||||||
right: amt,
|
right: amt,
|
||||||
@@ -54,6 +55,24 @@ impl Padding {
|
|||||||
region.bot_right.abs.y -= self.bottom;
|
region.bot_right.abs.y -= self.bottom;
|
||||||
region
|
region
|
||||||
}
|
}
|
||||||
|
pub fn x(amt: impl UiNum) -> Self {
|
||||||
|
let amt = amt.to_f32();
|
||||||
|
Self {
|
||||||
|
left: amt,
|
||||||
|
right: amt,
|
||||||
|
top: 0.0,
|
||||||
|
bottom: 0.0,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
pub fn y(amt: impl UiNum) -> Self {
|
||||||
|
let amt = amt.to_f32();
|
||||||
|
Self {
|
||||||
|
left: 0.0,
|
||||||
|
right: 0.0,
|
||||||
|
top: amt,
|
||||||
|
bottom: amt,
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: UiNum> From<T> for Padding {
|
impl<T: UiNum> From<T> for Padding {
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ use crate::prelude::*;
|
|||||||
pub struct Span {
|
pub struct Span {
|
||||||
pub children: Vec<(WidgetId, SpanLen)>,
|
pub children: Vec<(WidgetId, SpanLen)>,
|
||||||
pub dir: Dir,
|
pub dir: Dir,
|
||||||
|
pub spacing: f32,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Widget for Span {
|
impl Widget for Span {
|
||||||
@@ -36,6 +37,7 @@ impl Widget for Span {
|
|||||||
child_region.flip(self.dir.axis);
|
child_region.flip(self.dir.axis);
|
||||||
}
|
}
|
||||||
painter.widget_within(child, child_region);
|
painter.widget_within(child, child_region);
|
||||||
|
start.abs += self.spacing;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -45,7 +47,10 @@ impl Widget for Span {
|
|||||||
let dir_len = if total.ratio != 0.0 {
|
let dir_len = if total.ratio != 0.0 {
|
||||||
UiScalar::rel_max()
|
UiScalar::rel_max()
|
||||||
} else {
|
} else {
|
||||||
UiScalar::new(total.rel, total.abs)
|
UiScalar::new(
|
||||||
|
total.rel,
|
||||||
|
total.abs + self.spacing * self.children.len().saturating_sub(1) as f32,
|
||||||
|
)
|
||||||
};
|
};
|
||||||
let mut max_ortho = UiScalar::ZERO;
|
let mut max_ortho = UiScalar::ZERO;
|
||||||
for (child, _) in &self.children {
|
for (child, _) in &self.children {
|
||||||
@@ -68,9 +73,15 @@ impl Span {
|
|||||||
Self {
|
Self {
|
||||||
children: Vec::new(),
|
children: Vec::new(),
|
||||||
dir,
|
dir,
|
||||||
|
spacing: 0.0,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn spacing(mut self, spacing: impl UiNum) -> Self {
|
||||||
|
self.spacing = spacing.to_f32();
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
fn setup(&mut self, ctx: &mut SizeCtx) -> SpanLenSums {
|
fn setup(&mut self, ctx: &mut SizeCtx) -> SpanLenSums {
|
||||||
self.children
|
self.children
|
||||||
.iter_mut()
|
.iter_mut()
|
||||||
|
|||||||
@@ -78,6 +78,7 @@ impl<const LEN: usize, Wa: WidgetArrLike<LEN, Tag>, Tag> CoreWidgetArr<LEN, Wa,
|
|||||||
move |ui| Span {
|
move |ui| Span {
|
||||||
children: self.ui(ui).arr.into_iter().zip(lengths).collect(),
|
children: self.ui(ui).arr.into_iter().zip(lengths).collect(),
|
||||||
dir,
|
dir,
|
||||||
|
spacing: 0.0,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fn stack(self) -> StackBuilder<LEN, Wa, Tag> {
|
fn stack(self) -> StackBuilder<LEN, Wa, Tag> {
|
||||||
|
|||||||
@@ -44,6 +44,7 @@ pub struct WidgetInstance {
|
|||||||
pub resize: Option<(Id, UiVec2)>,
|
pub resize: Option<(Id, UiVec2)>,
|
||||||
pub mask: MaskIdx,
|
pub mask: MaskIdx,
|
||||||
pub layer: usize,
|
pub layer: usize,
|
||||||
|
pub desired_size: UiVec2,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
@@ -178,6 +179,17 @@ impl<'a> PainterCtx<'a> {
|
|||||||
|
|
||||||
// draw widgets
|
// draw widgets
|
||||||
painter.ctx.widgets.get_dyn_dynamic(id).draw(&mut painter);
|
painter.ctx.widgets.get_dyn_dynamic(id).draw(&mut painter);
|
||||||
|
let desired_size = SizeCtx {
|
||||||
|
text: painter.ctx.text,
|
||||||
|
textures: painter.ctx.textures,
|
||||||
|
widgets: painter.ctx.widgets,
|
||||||
|
checked: &mut Default::default(),
|
||||||
|
screen_size: painter.ctx.screen_size,
|
||||||
|
px_dependent: painter.ctx.px_dependent,
|
||||||
|
id: painter.id,
|
||||||
|
region: UiRegion::full(),
|
||||||
|
}
|
||||||
|
.size_raw(id);
|
||||||
|
|
||||||
let sized_children = painter.sized_children;
|
let sized_children = painter.sized_children;
|
||||||
|
|
||||||
@@ -191,6 +203,7 @@ impl<'a> PainterCtx<'a> {
|
|||||||
children: painter.children,
|
children: painter.children,
|
||||||
resize,
|
resize,
|
||||||
mask: painter.mask,
|
mask: painter.mask,
|
||||||
|
desired_size,
|
||||||
layer,
|
layer,
|
||||||
};
|
};
|
||||||
for (cid, size) in sized_children {
|
for (cid, size) in sized_children {
|
||||||
@@ -394,6 +407,9 @@ impl SizeCtx<'_> {
|
|||||||
// }
|
// }
|
||||||
self.size_inner(id.id, self.region)
|
self.size_inner(id.id, self.region)
|
||||||
}
|
}
|
||||||
|
fn size_raw(&mut self, id: Id) -> UiVec2 {
|
||||||
|
self.size_inner(id, self.region)
|
||||||
|
}
|
||||||
pub fn size_within<W>(&mut self, id: &WidgetId<W>, region: UiRegion) -> UiVec2 {
|
pub fn size_within<W>(&mut self, id: &WidgetId<W>, region: UiRegion) -> UiVec2 {
|
||||||
self.size_inner(id.id, region.within(&self.region))
|
self.size_inner(id.id, region.within(&self.region))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
use std::marker::Destruct;
|
use std::{fmt::Display, marker::Destruct};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
layout::{Align, Axis, UiNum, Vec2},
|
layout::{Align, Axis, UiNum, Vec2},
|
||||||
@@ -114,6 +114,12 @@ impl UiVec2 {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Display for UiVec2 {
|
||||||
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
|
write!(f, "rel {} / abs {}", self.rel, self.abs)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl_op!(UiVec2 Add add; rel abs);
|
impl_op!(UiVec2 Add add; rel abs);
|
||||||
impl_op!(UiVec2 Sub sub; rel abs);
|
impl_op!(UiVec2 Sub sub; rel abs);
|
||||||
|
|
||||||
@@ -307,6 +313,12 @@ impl UiRegion {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Display for UiRegion {
|
||||||
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
|
write!(f, "{} -> {}", self.top_left, self.bot_right)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct ScreenRegion {
|
pub struct ScreenRegion {
|
||||||
pub top_left: Vec2,
|
pub top_left: Vec2,
|
||||||
|
|||||||
@@ -170,6 +170,19 @@ impl Ui {
|
|||||||
font_system: &mut self.data.text.font_system,
|
font_system: &mut self.data.text.font_system,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn debug(&self, label: &str) {
|
||||||
|
for (id, inst) in &self.data.active {
|
||||||
|
let l = &self.data.widgets.data(id).unwrap().label;
|
||||||
|
if l != label {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
println!("\"{label}\" {{");
|
||||||
|
println!(" region: {}", inst.region);
|
||||||
|
println!(" desired_size: {}", inst.desired_size);
|
||||||
|
println!("}}");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<W: Widget> Index<&WidgetId<W>> for Ui {
|
impl<W: Widget> Index<&WidgetId<W>> for Ui {
|
||||||
|
|||||||
@@ -96,3 +96,9 @@ impl std::fmt::Debug for Vec2 {
|
|||||||
write!(f, "({}, {})", self.x, self.y)
|
write!(f, "({}, {})", self.x, self.y)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl std::fmt::Display for Vec2 {
|
||||||
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
|
write!(f, "({}, {})", self.x, self.y)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -9,6 +9,10 @@ pub trait Widget: Any {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Widget for () {
|
||||||
|
fn draw(&mut self, painter: &mut Painter) {}
|
||||||
|
}
|
||||||
|
|
||||||
pub struct WidgetTag;
|
pub struct WidgetTag;
|
||||||
pub struct FnTag;
|
pub struct FnTag;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user