Simplify Iris app initialization and task updates

This commit is contained in:
iris committed 2026-09-11 12:28:33 -04:00
1 parent b5666cdef9
commit 166bac2a93
25 files changed
+330 -282

No files matched your search

+5 -13
View File
@@ -2,19 +2,11 @@ use iris::prelude::*;
#[path = "lib.rs"]
mod app;
use app::*;
#[derive(AndroidUiState)]
struct State {
ui_state: AndroidUiState,
}
impl AndroidAppState for State {
type Resources = StdRsc<Self>;
}
#[iris::app_init]
fn create(mut ui_state: AndroidUiState, rsc: &mut StdRsc<State>) -> State {
let _ = build(rsc, &mut ui_state);
State { ui_state }
fn create(
ui_state: &mut AndroidUiState,
rsc: &mut StdRsc<AndroidUiState>,
) {
let _ = app::build(rsc, ui_state);
}
+2 -3
View File
@@ -3,7 +3,6 @@ use winit::event::WindowEvent;
#[path = "lib.rs"]
mod app;
use app::*;
const SETTLE_FRAMES: usize = 4;
const FRAMES: usize = 6;
@@ -17,8 +16,8 @@ struct State {
}
impl DesktopAppState for State {
fn new(mut ui_state: DesktopUiState, rsc: &mut StdRsc<Self>, _: Proxy<Self::Event>) -> Self {
let span = build(rsc, &mut ui_state);
fn new(mut ui_state: DesktopUiState, rsc: &mut StdRsc<Self>) -> Self {
let span = app::build(rsc, &mut ui_state);
Self {
ui_state,
span,
+5 -13
View File
@@ -2,19 +2,11 @@ use iris::prelude::*;
#[path = "lib.rs"]
mod app;
use app::*;
#[derive(AndroidUiState)]
struct State {
ui_state: AndroidUiState,
}
impl AndroidAppState for State {
type Resources = StdRsc<Self>;
}
#[iris::app_init]
fn create(mut ui_state: AndroidUiState, rsc: &mut StdRsc<State>) -> State {
build(rsc, &mut ui_state);
State { ui_state }
fn create(
ui_state: &mut AndroidUiState,
rsc: &mut StdRsc<AndroidUiState>,
) {
app::build(rsc, ui_state);
}
+4 -18
View File
@@ -3,24 +3,10 @@ use winit::{dpi::LogicalSize, window::WindowAttributes};
#[path = "lib.rs"]
mod app;
use app::*;
#[derive(DesktopUiState)]
struct State {
ui_state: DesktopUiState,
}
impl DesktopAppState for State {
fn window_attributes() -> WindowAttributes {
WindowAttributes::default().with_inner_size(LogicalSize::new(420.0, 900.0))
}
fn new(mut ui_state: DesktopUiState, rsc: &mut StdRsc<Self>, _: Proxy<Self::Event>) -> Self {
build(rsc, &mut ui_state);
Self { ui_state }
}
}
fn main() {
DesktopApp::<State>::run();
let attributes = WindowAttributes::default().with_inner_size(LogicalSize::new(420.0, 900.0));
DesktopApp::<DesktopUiState>::run_with_attributes(attributes, |ui_state, rsc| {
app::build(rsc, ui_state)
});
}
+5 -13
View File
@@ -2,19 +2,11 @@ use iris::prelude::*;
#[path = "lib.rs"]
mod app;
use app::*;
#[derive(AndroidUiState)]
struct State {
ui_state: AndroidUiState,
}
impl AndroidAppState for State {
type Resources = StdRsc<Self>;
}
#[iris::app_init]
fn create(mut ui_state: AndroidUiState, rsc: &mut StdRsc<State>) -> State {
build(rsc, &mut ui_state);
State { ui_state }
fn create(
ui_state: &mut AndroidUiState,
rsc: &mut StdRsc<AndroidUiState>,
) {
app::build(rsc, ui_state);
}
+1 -14
View File
@@ -2,20 +2,7 @@ use iris::prelude::*;
#[path = "lib.rs"]
mod app;
use app::*;
#[derive(DesktopUiState)]
struct State {
ui_state: DesktopUiState,
}
impl DesktopAppState for State {
fn new(mut ui_state: DesktopUiState, rsc: &mut StdRsc<Self>, _: Proxy<Self::Event>) -> Self {
build(rsc, &mut ui_state);
Self { ui_state }
}
}
fn main() {
DesktopApp::<State>::run();
DesktopApp::<DesktopUiState>::run_with(|ui_state, rsc| app::build(rsc, ui_state));
}
+3 -4
View File
@@ -2,7 +2,6 @@ use iris::prelude::*;
#[path = "lib.rs"]
mod app;
use app::*;
#[derive(AndroidUiState)]
struct Client {
@@ -19,14 +18,14 @@ impl AndroidAppState for Client {
.renderer
.as_ref()
.map_or(0, |renderer| renderer.ui.view_count());
update_info(rsc, self.info, views);
app::update_info(rsc, self.info, views);
}
}
#[iris::app_init]
fn create(mut ui_state: AndroidUiState, rsc: &mut StdRsc<Client>) -> Client {
let widgets = build(rsc, &mut ui_state);
update_info(rsc, widgets.info, 0);
let widgets = app::build(rsc, &mut ui_state);
app::update_info(rsc, widgets.info, 0);
Client {
ui_state,
info: widgets.info,
+4 -5
View File
@@ -3,7 +3,6 @@ use winit::event::WindowEvent;
#[path = "lib.rs"]
mod app;
use app::*;
#[derive(DesktopUiState)]
struct Client {
@@ -12,9 +11,9 @@ struct Client {
}
impl DesktopAppState for Client {
fn new(mut ui_state: DesktopUiState, rsc: &mut StdRsc<Self>, _: Proxy<Self::Event>) -> Self {
let widgets = build(rsc, &mut ui_state);
update_info(rsc, widgets.info, 0);
fn new(mut ui_state: DesktopUiState, rsc: &mut StdRsc<Self>) -> Self {
let widgets = app::build(rsc, &mut ui_state);
app::update_info(rsc, widgets.info, 0);
Self {
ui_state,
info: widgets.info,
@@ -22,7 +21,7 @@ impl DesktopAppState for Client {
}
fn window_event(&mut self, _: WindowEvent, rsc: &mut StdRsc<Self>) {
update_info(rsc, self.info, self.ui_state.renderer.ui.view_count());
app::update_info(rsc, self.info, self.ui_state.renderer.ui.view_count());
}
}
+5 -13
View File
@@ -2,19 +2,11 @@ use iris::prelude::*;
#[path = "lib.rs"]
mod app;
use app::*;
#[derive(AndroidUiState)]
struct State {
ui_state: AndroidUiState,
}
impl AndroidAppState for State {
type Resources = StdRsc<Self>;
}
#[iris::app_init]
fn create(mut ui_state: AndroidUiState, rsc: &mut StdRsc<State>) -> State {
build(rsc, &mut ui_state);
State { ui_state }
fn create(
ui_state: &mut AndroidUiState,
rsc: &mut StdRsc<AndroidUiState>,
) {
app::build(rsc, ui_state);
}
+1 -14
View File
@@ -2,20 +2,7 @@ use iris::prelude::*;
#[path = "lib.rs"]
mod app;
use app::*;
#[derive(DesktopUiState)]
struct State {
ui_state: DesktopUiState,
}
impl DesktopAppState for State {
fn new(mut ui_state: DesktopUiState, rsc: &mut StdRsc<Self>, _: Proxy<Self::Event>) -> Self {
build(rsc, &mut ui_state);
Self { ui_state }
}
}
fn main() {
DesktopApp::<State>::run();
DesktopApp::<DesktopUiState>::run_with(|ui_state, rsc| app::build(rsc, ui_state));
}
+13 -12
View File
@@ -6,16 +6,17 @@ where
Rsc::State: FocusHost,
{
let rect = rect(PaintId::RED).add(rsc);
rect.task_on(CursorSense::click(), async move |mut ctx| {
iris::task::sleep(Duration::from_secs(1)).await;
ctx.update(move |_, rsc| {
let rect = rect(rsc);
if rect.is_paint(&PaintId::RED) {
rect.set_paint(PaintId::BLUE);
} else {
rect.set_paint(PaintId::RED);
}
});
})
.set_root(rsc, ui_state);
rect.label("Toggle color")
.task_on(CursorSense::click(), async move |mut ctx| {
iris::task::sleep(Duration::from_secs(1)).await;
ctx.update(move |_, rsc| {
let rect = rect(rsc);
if rect.is_paint(&PaintId::RED) {
rect.set_paint(PaintId::BLUE);
} else {
rect.set_paint(PaintId::RED);
}
});
})
.set_root(rsc, ui_state);
}
+5 -13
View File
@@ -2,19 +2,11 @@ use iris::prelude::*;
#[path = "lib.rs"]
mod app;
use app::*;
#[derive(AndroidUiState)]
struct State {
ui_state: AndroidUiState,
}
impl AndroidAppState for State {
type Resources = StdRsc<Self>;
}
#[iris::app_init]
fn create(mut ui_state: AndroidUiState, rsc: &mut StdRsc<State>) -> State {
build(rsc, &mut ui_state);
State { ui_state }
fn create(
ui_state: &mut AndroidUiState,
rsc: &mut StdRsc<AndroidUiState>,
) {
app::build(rsc, ui_state);
}
+1 -14
View File
@@ -2,20 +2,7 @@ use iris::prelude::*;
#[path = "lib.rs"]
mod app;
use app::*;
#[derive(DesktopUiState)]
struct State {
ui_state: DesktopUiState,
}
impl DesktopAppState for State {
fn new(mut ui_state: DesktopUiState, rsc: &mut StdRsc<Self>, _: Proxy<Self::Event>) -> Self {
build(rsc, &mut ui_state);
Self { ui_state }
}
}
fn main() {
DesktopApp::<State>::run();
DesktopApp::<DesktopUiState>::run_with(|ui_state, rsc| app::build(rsc, ui_state));
}