Add Iris Android APK tooling
This commit is contained in:
1 parent
3246f397b5
commit
37f956707e
20 files changed
+1766
-54
No files matched your search
@@ -0,0 +1,2 @@
|
||||
/Cargo.lock
|
||||
/target/
|
||||
@@ -0,0 +1,12 @@
|
||||
[package]
|
||||
name = "iris-apk-fixture"
|
||||
version = "0.1.0"
|
||||
edition = "2024"
|
||||
|
||||
[lib]
|
||||
crate-type = ["cdylib", "rlib"]
|
||||
|
||||
[dependencies]
|
||||
iris = { path = "../../.." }
|
||||
|
||||
[workspace]
|
||||
@@ -0,0 +1,97 @@
|
||||
use iris::prelude::*;
|
||||
use std::sync::Arc;
|
||||
|
||||
#[derive(AndroidUiState)]
|
||||
pub struct State {
|
||||
ui_state: AndroidUiState,
|
||||
}
|
||||
|
||||
impl AndroidAppState for State {
|
||||
type Resources = Resources;
|
||||
}
|
||||
|
||||
#[iris::app_init]
|
||||
fn create(mut ui_state: AndroidUiState, rsc: &mut Resources) -> State {
|
||||
rsc.launches += 1;
|
||||
rect(PaintId::RED)
|
||||
.label("Iris APK fixture")
|
||||
.set_root(rsc, &mut ui_state);
|
||||
State { ui_state }
|
||||
}
|
||||
|
||||
pub struct Resources {
|
||||
ui: Ui,
|
||||
events: EventManager<Self>,
|
||||
tasks: Tasks<Self>,
|
||||
widget_state: WidgetState,
|
||||
launches: u32,
|
||||
}
|
||||
|
||||
impl AndroidResources<State> for Resources {
|
||||
fn new(redraw: Arc<dyn RequestRedraw>) -> (Self, TaskMsgReceiver<Self>) {
|
||||
let (tasks, receiver) = Tasks::init(redraw);
|
||||
(
|
||||
Self {
|
||||
ui: Ui::default(),
|
||||
events: EventManager::default(),
|
||||
tasks,
|
||||
widget_state: WidgetState::default(),
|
||||
launches: 0,
|
||||
},
|
||||
receiver,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
impl UiRsc for Resources {
|
||||
fn ui(&self) -> &Ui {
|
||||
&self.ui
|
||||
}
|
||||
|
||||
fn ui_mut(&mut self) -> &mut Ui {
|
||||
&mut self.ui
|
||||
}
|
||||
|
||||
fn on_draw(&mut self, active: &ActiveData) {
|
||||
self.events.draw(active);
|
||||
}
|
||||
|
||||
fn on_undraw(&mut self, active: &ActiveData) {
|
||||
self.events.undraw(active);
|
||||
}
|
||||
|
||||
fn on_remove(&mut self, id: WidgetId) {
|
||||
self.events.remove(id);
|
||||
self.widget_state.remove(id);
|
||||
}
|
||||
}
|
||||
|
||||
impl HasState for Resources {
|
||||
type State = State;
|
||||
}
|
||||
|
||||
impl HasEvents for Resources {
|
||||
fn events(&self) -> &EventManager<Self> {
|
||||
&self.events
|
||||
}
|
||||
|
||||
fn events_mut(&mut self) -> &mut EventManager<Self> {
|
||||
&mut self.events
|
||||
}
|
||||
}
|
||||
|
||||
impl HasTasks for Resources {
|
||||
fn tasks_mut(&mut self) -> &mut Tasks<Self> {
|
||||
&mut self.tasks
|
||||
}
|
||||
}
|
||||
|
||||
impl HasWidgetState for Resources {
|
||||
fn widget_state(&self) -> &WidgetState {
|
||||
&self.widget_state
|
||||
}
|
||||
|
||||
fn widget_state_mut(&mut self) -> &mut WidgetState {
|
||||
&mut self.widget_state
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user