fix reactivity 😭 + visual widget counter

This commit is contained in:
2025-08-24 22:02:50 -04:00
parent 6bb6db32a6
commit 74d01d14d4
9 changed files with 119 additions and 47 deletions

View File

@@ -1,10 +1,13 @@
use super::*;
use crate::layout::{Dir, UiPos, UiRegion, Vec2, WidgetArrLike, WidgetFnRet, WidgetLike};
use crate::layout::{
Dir, UiPos, UiRegion, Vec2, WidgetArrLike, WidgetFnRet, WidgetIdFnRet, WidgetLike,
};
pub trait CoreWidget<W: 'static, Ctx: 'static, Tag> {
pub trait CoreWidget<W, Ctx: 'static, Tag> {
fn pad(self, padding: impl Into<Padding>) -> WidgetFnRet!(Regioned, Ctx);
fn center(self, size: impl Into<Vec2>) -> WidgetFnRet!(Regioned, Ctx);
fn region(self, region: UiRegion) -> WidgetFnRet!(Regioned, Ctx);
fn label(self, label: impl Into<String>) -> WidgetIdFnRet!(W, Ctx);
}
impl<W: WidgetLike<Ctx, Tag>, Ctx: 'static, Tag> CoreWidget<W::Widget, Ctx, Tag> for W {
@@ -28,6 +31,14 @@ impl<W: WidgetLike<Ctx, Tag>, Ctx: 'static, Tag> CoreWidget<W::Widget, Ctx, Tag>
inner: self.add(ui).erase_type(),
}
}
fn label(self, label: impl Into<String>) -> WidgetIdFnRet!(W::Widget, Ctx) {
|ui| {
let id = self.add(ui);
ui.set_label(&id, label.into());
id
}
}
}
pub trait CoreWidgetArr<const LEN: usize, Ctx: 'static, Tag> {