widgetkit_runtime/
widget.rs1use crate::{
2 context::{DisposeCtx, MountCtx, RenderCtx, StartCtx, StopCtx, UpdateCtx},
3 event::Event,
4};
5use widgetkit_render::Canvas;
6
7pub trait Widget: Send + Sized + 'static {
8 type State;
9 type Message: Send + 'static;
10
11 fn mount(&mut self, ctx: &mut MountCtx<Self>) -> Self::State;
12
13 fn start(&mut self, _state: &mut Self::State, _ctx: &mut StartCtx<Self>) {}
14
15 fn update(
16 &mut self,
17 _state: &mut Self::State,
18 _event: Event<Self::Message>,
19 _ctx: &mut UpdateCtx<Self>,
20 ) {}
21
22 fn render(&self, _state: &Self::State, _canvas: &mut Canvas, _ctx: &RenderCtx<Self>) {}
23
24 fn stop(&mut self, _state: &mut Self::State, _ctx: &mut StopCtx<Self>) {}
25
26 fn dispose(&mut self, _state: Self::State, _ctx: &mut DisposeCtx<Self>) {}
27}