sized spans!

This commit is contained in:
2025-08-28 18:25:59 -04:00
parent d7d67e4ed3
commit a0e6623abe
7 changed files with 52 additions and 10 deletions

View File

@@ -75,4 +75,17 @@ impl Vec2 {
Axis::Y => &mut self.y,
}
}
pub const fn from_axis(axis: Axis, aligned: f32, ortho: f32) -> Self {
Self {
x: match axis {
Axis::X => aligned,
Axis::Y => ortho,
},
y: match axis {
Axis::Y => aligned,
Axis::X => ortho,
},
}
}
}

View File

@@ -151,11 +151,19 @@ impl<'a> Painter<'a> {
}
pub fn size<W>(&mut self, id: &WidgetId<W>) -> Vec2 {
self.widgets.get_dyn_dynamic(&id.id).size(SizeCtx {
self.widgets
.get_dyn_dynamic(&id.id)
.size(&mut self.size_ctx())
}
pub fn size_ctx(&mut self) -> SizeCtx {
SizeCtx {
screen_size: self.screen_size,
size: self.region().in_size(self.screen_size),
text: self.text,
textures: self.textures,
})
widgets: self.widgets,
}
}
pub(crate) fn redraw(&mut self, id: &Id) {

View File

@@ -1,18 +1,26 @@
use crate::layout::{Painter, TextData, Textures, Ui, Vec2, WidgetId, WidgetIdFnRet};
use crate::layout::{Painter, TextData, Textures, Ui, Vec2, WidgetId, WidgetIdFnRet, Widgets};
use std::{any::Any, marker::PhantomData};
pub trait Widget: Any {
fn draw(&mut self, painter: &mut Painter);
fn size(&mut self, ctx: SizeCtx) -> Vec2 {
fn size(&mut self, ctx: &mut SizeCtx) -> Vec2 {
ctx.size
}
}
pub struct SizeCtx<'a> {
pub screen_size: Vec2,
pub size: Vec2,
pub text: &'a mut TextData,
pub textures: &'a mut Textures,
pub(super) widgets: &'a Widgets,
}
impl SizeCtx<'_> {
pub fn size<W>(&mut self, id: &WidgetId<W>) -> Vec2 {
self.widgets.get_dyn_dynamic(&id.id).size(self)
}
}
pub struct WidgetTag;