11use baseview:: dpi:: LogicalSize ;
22use baseview:: {
3- Event , EventStatus , WindowContext , WindowHandle , WindowHandler , WindowOpenOptions , WindowSize ,
3+ Event , EventStatus , HandlerError , WindowContext , WindowHandle , WindowHandler ,
4+ WindowOpenOptions , WindowSize ,
45} ;
56use std:: cell:: { Cell , RefCell } ;
67use std:: num:: NonZeroU32 ;
@@ -13,22 +14,25 @@ struct ParentWindowHandler {
1314}
1415
1516impl ParentWindowHandler {
16- pub fn new ( window : WindowContext ) -> Self {
17- let ctx = softbuffer:: Context :: new ( window. clone ( ) ) . unwrap ( ) ;
18- let mut surface = softbuffer:: Surface :: new ( & ctx, window. clone ( ) ) . unwrap ( ) ;
17+ pub fn new ( window : WindowContext ) -> Result < Self , HandlerError > {
18+ let ctx = softbuffer:: Context :: new ( window. clone ( ) ) ? ;
19+ let mut surface = softbuffer:: Surface :: new ( & ctx, window. clone ( ) ) ? ;
1920 let size = window. size ( ) . physical ;
2021 surface
21- . resize ( NonZeroU32 :: new ( size. width ) . unwrap ( ) , NonZeroU32 :: new ( size. height ) . unwrap ( ) )
22- . unwrap ( ) ;
22+ . resize ( NonZeroU32 :: new ( size. width ) . unwrap ( ) , NonZeroU32 :: new ( size. height ) . unwrap ( ) ) ?;
2323
2424 let window_open_options = WindowOpenOptions :: new ( )
2525 . with_size ( LogicalSize :: new ( 256 , 256 ) )
2626 . with_parent ( & window)
2727 . with_title ( "baseview child" ) ;
2828
29- let child_window = baseview:: create_window ( window_open_options, ChildWindowHandler :: new) ;
29+ let child_window = baseview:: create_window ( window_open_options, ChildWindowHandler :: new) ? ;
3030
31- Self { surface : surface. into ( ) , damaged : true . into ( ) , _child_window : Some ( child_window) }
31+ Ok ( Self {
32+ surface : surface. into ( ) ,
33+ damaged : true . into ( ) ,
34+ _child_window : Some ( child_window) ,
35+ } )
3236 }
3337}
3438
@@ -72,15 +76,14 @@ struct ChildWindowHandler {
7276}
7377
7478impl ChildWindowHandler {
75- pub fn new ( window : WindowContext ) -> Self {
76- let ctx = softbuffer:: Context :: new ( window. clone ( ) ) . unwrap ( ) ;
77- let mut surface = softbuffer:: Surface :: new ( & ctx, window. clone ( ) ) . unwrap ( ) ;
79+ pub fn new ( window : WindowContext ) -> Result < Self , HandlerError > {
80+ let ctx = softbuffer:: Context :: new ( window. clone ( ) ) ? ;
81+ let mut surface = softbuffer:: Surface :: new ( & ctx, window. clone ( ) ) ? ;
7882 let size = window. size ( ) . physical ;
7983 surface
80- . resize ( NonZeroU32 :: new ( size. width ) . unwrap ( ) , NonZeroU32 :: new ( size. height ) . unwrap ( ) )
81- . unwrap ( ) ;
84+ . resize ( NonZeroU32 :: new ( size. width ) . unwrap ( ) , NonZeroU32 :: new ( size. height ) . unwrap ( ) ) ?;
8285
83- Self { surface : surface. into ( ) , damaged : true . into ( ) }
86+ Ok ( Self { surface : surface. into ( ) , damaged : true . into ( ) } )
8487 }
8588}
8689
@@ -121,5 +124,7 @@ impl WindowHandler for ChildWindowHandler {
121124fn main ( ) {
122125 let window_open_options = WindowOpenOptions :: new ( ) . with_size ( LogicalSize :: new ( 512.0 , 512.0 ) ) ;
123126
124- baseview:: create_window ( window_open_options, ParentWindowHandler :: new) . run_until_closed ( ) ;
127+ baseview:: create_window ( window_open_options, ParentWindowHandler :: new)
128+ . unwrap ( )
129+ . run_until_closed ( ) ;
125130}
0 commit comments