remove state generic from a lot of things

This commit is contained in:
2025-12-17 21:37:55 -05:00
parent 7e6369029f
commit 30bc55c78e
45 changed files with 740 additions and 856 deletions

View File

@@ -1,14 +1,14 @@
use crate::prelude::*;
use std::marker::PhantomData;
pub struct Span<State> {
pub children: Vec<WidgetHandle<State>>,
pub struct Span {
pub children: Vec<WidgetHandle>,
pub dir: Dir,
pub gap: f32,
}
impl<State: 'static> Widget<State> for Span<State> {
fn draw(&mut self, painter: &mut Painter<State>) {
impl Widget for Span {
fn draw(&mut self, painter: &mut Painter) {
let total = self.len_sum(&mut painter.size_ctx());
let mut start = UiScalar::rel_min();
for child in &self.children {
@@ -33,14 +33,14 @@ impl<State: 'static> Widget<State> for Span<State> {
}
}
fn desired_width(&mut self, ctx: &mut SizeCtx<State>) -> Len {
fn desired_width(&mut self, ctx: &mut SizeCtx) -> Len {
match self.dir.axis {
Axis::X => self.desired_len(ctx),
Axis::Y => self.desired_ortho(ctx),
}
}
fn desired_height(&mut self, ctx: &mut SizeCtx<State>) -> Len {
fn desired_height(&mut self, ctx: &mut SizeCtx) -> Len {
match self.dir.axis {
Axis::X => self.desired_ortho(ctx),
Axis::Y => self.desired_len(ctx),
@@ -48,7 +48,7 @@ impl<State: 'static> Widget<State> for Span<State> {
}
}
impl<State: 'static> Span<State> {
impl Span {
pub fn empty(dir: Dir) -> Self {
Self {
children: Vec::new(),
@@ -62,7 +62,7 @@ impl<State: 'static> Span<State> {
self
}
fn len_sum(&mut self, ctx: &mut SizeCtx<State>) -> Len {
fn len_sum(&mut self, ctx: &mut SizeCtx) -> Len {
let gap = self.gap * self.children.len().saturating_sub(1) as f32;
self.children.iter().fold(Len::abs(gap), |mut s, id| {
// it's tempting to subtract the abs & rel from the ctx outer,
@@ -78,7 +78,7 @@ impl<State: 'static> Span<State> {
})
}
fn desired_len(&mut self, ctx: &mut SizeCtx<State>) -> Len {
fn desired_len(&mut self, ctx: &mut SizeCtx) -> Len {
let len = self.len_sum(ctx);
if len.rest == 0.0 && len.rel == 0.0 {
len
@@ -87,7 +87,7 @@ impl<State: 'static> Span<State> {
}
}
fn desired_ortho(&mut self, ctx: &mut SizeCtx<State>) -> Len {
fn desired_ortho(&mut self, ctx: &mut SizeCtx) -> Len {
// this is a weird hack to get text wrapping to work properly when in a downward span
// the correct solution here is to add a function to widget that lets them
// request that ctx.outer has an axis "resolved" before checking the other,
@@ -151,14 +151,14 @@ pub struct SpanBuilder<State, const LEN: usize, Wa: WidgetArrLike<State, LEN, Ta
_pd: PhantomData<(State, Tag)>,
}
impl<State, const LEN: usize, Wa: WidgetArrLike<State, LEN, Tag>, Tag> FnOnce<(&mut Ui<State>,)>
impl<State, const LEN: usize, Wa: WidgetArrLike<State, LEN, Tag>, Tag> FnOnce<(&mut State,)>
for SpanBuilder<State, LEN, Wa, Tag>
{
type Output = Span<State>;
type Output = Span;
extern "rust-call" fn call_once(self, args: (&mut Ui<State>,)) -> Self::Output {
extern "rust-call" fn call_once(self, args: (&mut State,)) -> Self::Output {
Span {
children: self.children.ui(args.0).arr.into_iter().collect(),
children: self.children.add(args.0).arr.into_iter().collect(),
dir: self.dir,
gap: self.gap,
}
@@ -183,15 +183,15 @@ impl<State, const LEN: usize, Wa: WidgetArrLike<State, LEN, Tag>, Tag>
}
}
impl<State> std::ops::Deref for Span<State> {
type Target = Vec<WidgetHandle<State>>;
impl std::ops::Deref for Span {
type Target = Vec<WidgetHandle>;
fn deref(&self) -> &Self::Target {
&self.children
}
}
impl<State> std::ops::DerefMut for Span<State> {
impl std::ops::DerefMut for Span {
fn deref_mut(&mut self) -> &mut Self::Target {
&mut self.children
}