kkx/kkx/src/main.rs

79 lines
2.0 KiB
Rust

use kkdisp::{
component::{Plan, Widget},
theme::Color,
token::Token,
view::Event,
View,
};
#[tokio::main]
async fn main() {
kkdisp::run(App::default()).await.unwrap()
}
pub struct App {
states: Vec<Plan>,
index: usize,
}
impl Default for App {
fn default() -> Self {
Self {
index: 0,
states: vec![
Plan::start().fill(vec![]).fixed(
4,
vec![Widget::new(
100,
vec![
Token::End,
Token::text("click me")
.bg(Color::BLUE)
.link("click"),
],
)],
),
Plan::start().fill(vec![]).fixed(
4,
vec![Widget::new(
100,
vec![
Token::End,
Token::text(
"you did it! now undo it u fuck",
)
.bg(Color::RED)
.link("click"),
],
)],
),
],
}
}
}
impl View for App {
fn init(
&mut self,
) -> std::result::Result<kkdisp::PlanLayers, anyhow::Error> {
Ok(vec![self.states[self.index].clone()])
}
fn update(
&mut self,
event: Event,
) -> std::result::Result<kkdisp::PlanLayers, anyhow::Error> {
match event {
Event::Link(lnk) => {
if lnk == "click" {
self.index ^= 1;
Ok(vec![self.states[self.index].clone()])
} else {
panic!("bad link");
}
}
_ => Ok(vec![self.states[self.index].clone()]),
}
}
}