Update app structure
This commit is contained in:
+12
-6
@@ -4,22 +4,28 @@ pub mod unit;
|
|||||||
pub mod widget;
|
pub mod widget;
|
||||||
|
|
||||||
pub trait App {
|
pub trait App {
|
||||||
|
// State
|
||||||
|
fn init(&mut self);
|
||||||
|
fn update(&mut self);
|
||||||
|
fn tick(&self);
|
||||||
|
|
||||||
// Rendering
|
// Rendering
|
||||||
fn layout(&self) -> layout::Allocation;
|
fn layout(&self) -> layout::Allocation;
|
||||||
fn render(&mut self, layout: layout::Allocation);
|
fn render(&mut self, layout: layout::Allocation);
|
||||||
|
|
||||||
// State
|
|
||||||
fn init(&mut self);
|
|
||||||
|
|
||||||
fn update(&mut self);
|
|
||||||
|
|
||||||
fn refresh(&mut self) {
|
fn refresh(&mut self) {
|
||||||
self.render(self.layout());
|
self.render(self.layout());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Run
|
// Running
|
||||||
fn run(&mut self) {
|
fn run(&mut self) {
|
||||||
self.init();
|
self.init();
|
||||||
self.refresh();
|
self.refresh();
|
||||||
|
|
||||||
|
loop {
|
||||||
|
self.tick();
|
||||||
|
self.update();
|
||||||
|
self.refresh();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user