finished moving out render_state

This commit is contained in:
2026-01-19 18:00:24 -05:00
parent 79813db3ba
commit 06dd015092
26 changed files with 497 additions and 221 deletions

View File

@@ -10,8 +10,12 @@ struct State {
}
impl DefaultAppState for State {
fn new(ui_state: DefaultUiState, rsc: &mut DefaultRsc<Self>, _: Proxy<Self::Event>) -> Self {
rect(Color::RED).set_root(rsc);
fn new(
mut ui_state: DefaultUiState,
rsc: &mut DefaultRsc<Self>,
_: Proxy<Self::Event>,
) -> Self {
rect(Color::RED).set_root(rsc, &mut ui_state);
Self { ui_state }
}
}

View File

@@ -16,7 +16,11 @@ pub struct Client {
}
impl DefaultAppState for Client {
fn new(ui_state: DefaultUiState, rsc: &mut DefaultRsc<Self>, _: Proxy<Self::Event>) -> Self {
fn new(
mut ui_state: DefaultUiState,
rsc: &mut DefaultRsc<Self>,
_: Proxy<Self::Event>,
) -> Self {
let rrect = rect(Color::WHITE).radius(20);
let pad_test = (
rrect.color(Color::BLUE),
@@ -197,20 +201,25 @@ impl DefaultAppState for Client {
((tabs.height(40), main.pad(10)).span(Dir::DOWN), info_sect)
.stack()
.set_root(rsc);
.set_root(rsc, &mut ui_state);
Self { ui_state, info }
}
fn window_event(&mut self, _: WindowEvent, rsc: &mut DefaultRsc<Self>) {
fn window_event(
&mut self,
_: WindowEvent,
rsc: &mut DefaultRsc<Self>,
render: &mut UiRenderState,
) {
let new = format!(
"widgets: {}\nactive: {}\nviews: {}",
rsc.ui.num_widgets(),
rsc.ui.active_widgets(),
self.ui_state.renderer.ui.view_count()
rsc.widgets().len(),
render.active_widgets(),
self.ui_state.renderer.ui.view_count(),
);
if new != *rsc.ui[self.info].content {
*rsc.ui[self.info].content = new;
if new != *rsc.widgets()[self.info].content {
*rsc.widgets_mut()[self.info].content = new;
}
}
}

View File

@@ -11,11 +11,15 @@ struct State {
}
impl DefaultAppState for State {
fn new(ui_state: DefaultUiState, rsc: &mut DefaultRsc<Self>, _: Proxy<Self::Event>) -> Self {
fn new(
mut ui_state: DefaultUiState,
rsc: &mut DefaultRsc<Self>,
_: Proxy<Self::Event>,
) -> Self {
let rect = rect(Color::RED).add(rsc);
rect.task_on(CursorSense::click(), async move |mut ctx| {
tokio::time::sleep(Duration::from_secs(1)).await;
ctx.task.update(move |_, rsc| {
ctx.update(move |_, rsc| {
let rect = rect(rsc);
if rect.color == Color::RED {
rect.color = Color::BLUE;
@@ -24,7 +28,7 @@ impl DefaultAppState for State {
}
});
})
.set_root(rsc);
.set_root(rsc, &mut ui_state);
Self { ui_state }
}
}

View File

@@ -33,13 +33,17 @@ impl Test {
}
impl DefaultAppState for State {
fn new(ui_state: DefaultUiState, rsc: &mut DefaultRsc<Self>, _: Proxy<Self::Event>) -> Self {
fn new(
mut ui_state: DefaultUiState,
rsc: &mut DefaultRsc<Self>,
_: Proxy<Self::Event>,
) -> Self {
let test = Test::new(rsc);
test.on(CursorSense::click(), move |_, rsc| {
test.toggle(rsc);
})
.set_root(rsc);
.set_root(rsc, &mut ui_state);
Self { ui_state }
}