1- use kas:: widgets:: { format_data , label_any , Adapt , Button , Slider } ;
2- use kas:: { messages :: MessageStack , Action , Window } ;
1+ use kas:: widgets:: { AdaptWidget , Button , Label , Slider , column , format_data , row } ;
2+ use kas:: window :: Window ;
33
44#[ derive( Clone , Debug ) ]
55struct Increment ( i32 ) ;
66
77#[ derive( Clone , Copy , Debug ) ]
88struct Count ( i32 ) ;
9-
10- impl kas:: app:: AppData for Count {
11- fn handle_messages ( & mut self , messages : & mut MessageStack ) -> Action {
9+ impl kas:: runner:: AppData for Count {
10+ fn handle_messages ( & mut self , messages : & mut kas:: runner:: MessageStack ) {
1211 if let Some ( Increment ( add) ) = messages. try_pop ( ) {
1312 self . 0 += add;
14- Action :: UPDATE
15- } else {
16- Action :: empty ( )
1713 }
1814 }
1915}
2016
21- fn counter ( ) -> impl kas :: Widget < Data = Count > {
17+ fn counter ( title : & str ) -> Window < Count > {
2218 // Per window state: (count, increment).
2319 type Data = ( Count , i32 ) ;
2420 let initial: Data = ( Count ( 0 ) , 1 ) ;
@@ -27,28 +23,32 @@ fn counter() -> impl kas::Widget<Data = Count> {
2723 struct SetValue ( i32 ) ;
2824
2925 let slider = Slider :: right ( 1 ..=10 , |_, data : & Data | data. 1 ) . with_msg ( SetValue ) ;
30- let ui = kas :: column![
26+ let ui = column ! [
3127 format_data!( data: & Data , "Count: {}" , data. 0.0 ) ,
3228 row![ slider, format_data!( data: & Data , "{}" , data. 1 ) ] ,
3329 row![
34- Button :: new( label_any ( "Sub" ) ) . with( |cx, data: & Data | cx. push( Increment ( -data. 1 ) ) ) ,
35- Button :: new( label_any ( "Add" ) ) . with( |cx, data: & Data | cx. push( Increment ( data. 1 ) ) ) ,
30+ Button :: new( Label :: new_any ( "Sub" ) ) . with( |cx, data: & Data | cx. push( Increment ( -data. 1 ) ) ) ,
31+ Button :: new( Label :: new_any ( "Add" ) ) . with( |cx, data: & Data | cx. push( Increment ( data. 1 ) ) ) ,
3632 ] ,
3733 ] ;
3834
39- Adapt :: new ( ui, initial)
35+ let ui = ui
36+ . with_state ( initial)
4037 . on_update ( |_, state, count| state. 0 = * count)
41- . on_message ( |_, state, SetValue ( v) | state. 1 = v)
38+ . on_message ( |_, state, SetValue ( v) | state. 1 = v) ;
39+ Window :: new ( ui, title) . escapable ( )
4240}
4341
44- fn main ( ) -> kas:: app :: Result < ( ) > {
42+ fn main ( ) -> kas:: runner :: Result < ( ) > {
4543 env_logger:: init ( ) ;
4644
47- let theme = kas_wgpu:: ShadedTheme :: new ( ) . with_font_size ( 24.0 ) ;
45+ let count = Count ( 0 ) ;
46+ let theme = kas_wgpu:: ShadedTheme :: new ( ) ;
4847
49- kas:: app:: Default :: with_theme ( theme)
50- . build ( Count ( 0 ) ) ?
51- . with ( Window :: new ( counter ( ) , "Counter 1" ) )
52- . with ( Window :: new ( counter ( ) , "Counter 2" ) )
48+ let mut runner = kas:: runner:: Runner :: with_theme ( theme) . build ( count) ?;
49+ let _ = runner. config_mut ( ) . font . set_size ( 24.0 ) ;
50+ runner
51+ . with ( counter ( "Counter 1" ) )
52+ . with ( counter ( "Counter 2" ) )
5353 . run ( )
5454}
0 commit comments