/// RFC 33 验收 — Lifecycle hooks

use lv_tui::prelude::*;
use lv_tui::Component;

#[derive(Component)]
struct App {
    #[reactive(paint, copy)]
    count: i32,
    mount_count: i32,
}

impl App {
fn new() -> Self { Self { count: 0, mount_count: 0 } }
#[allow(dead_code)]
fn mount(&mut self, _cx: &mut EventCx) { self.mount_count += 1; }
}

impl Component for App {
fn render(&self, cx: &mut RenderCx) {
        cx.line(format!("mount: {}, events: {}", self.mount_count, self.get_count()));
        cx.line("press + to increment, q to quit");
    }
fn event(&mut self, event: &Event, cx: &mut EventCx) {
        if cx.phase() != lv_tui::event::EventPhase::Target { return; }
        if event.is_key(Key::Char('q')) { cx.quit(); }
        if event.is_key(Key::Char('+')) { self.set_count(self.get_count() + 1, cx); }
    }
}

fn main() -> lv_tui::Result<()> { lv_tui::app::App::new(App::new()).run() }
