@@ -5,39 +5,57 @@ use crate::*;
55use dpi:: { LogicalSize , PhysicalSize , Pixel , Size } ;
66use std:: marker:: PhantomData ;
77
8- pub struct WindowHandle {
9- window_handle : platform:: WindowHandle ,
8+ pub struct Window {
9+ inner : platform:: WindowHandle ,
1010 // so that WindowHandle is !Send on all platforms
1111 phantom : PhantomData < * mut ( ) > ,
1212}
1313
14- impl WindowHandle {
14+ impl Window {
1515 #[ inline]
16- fn new ( window_handle : platform:: WindowHandle ) -> Self {
17- Self { window_handle, phantom : PhantomData }
16+ pub fn create < H : WindowHandler > (
17+ builder : WindowOpenOptions ,
18+ handler : impl FnOnce ( WindowContext ) -> Result < H , HandlerError > + Send + ' static ,
19+ ) -> Result < Window , Error > {
20+ Self :: create_with_host ( builder, handler, None )
21+ }
22+
23+ pub fn create_with_host < H : WindowHandler > (
24+ builder : WindowOpenOptions ,
25+ handler : impl FnOnce ( WindowContext ) -> Result < H , HandlerError > + Send + ' static ,
26+ host : impl Into < Option < Host > > ,
27+ ) -> Result < Window , Error > {
28+ Ok ( Self {
29+ inner : platform:: WindowHandle :: create_window (
30+ builder,
31+ WindowHandlerBuilder :: new ( handler) ,
32+ host. into ( ) . unwrap_or_else ( Host :: default) ,
33+ ) ?,
34+ phantom : PhantomData ,
35+ } )
1836 }
1937
2038 /// Blocks the thread and runs an event loop until the window is closed.
2139 ///
2240 /// The window is shown automatically if it wasn't already.
2341 #[ inline]
2442 pub fn run_until_closed ( self ) -> Result < ( ) , Error > {
25- self . window_handle . run_until_closed ( ) ?;
43+ self . inner . run_until_closed ( ) ?;
2644 Ok ( ( ) )
2745 }
2846
2947 /// The current size of the window.
3048 #[ inline]
3149 pub fn size ( & self ) -> WindowSize {
32- self . window_handle . size ( )
50+ self . inner . size ( )
3351 }
3452
3553 /// Resizes the window to the given [`Size`].
3654 ///
3755 /// The `size` can be provided in either physical or logical pixels.
3856 #[ inline]
3957 pub fn resize ( & self , size : Size ) -> Result < ( ) , Error > {
40- self . window_handle . resize ( size) ?;
58+ self . inner . resize ( size) ?;
4159 Ok ( ( ) )
4260 }
4361
@@ -57,7 +75,7 @@ impl WindowHandle {
5775 /// On macOS, this function is always a no-op.
5876 #[ inline]
5977 pub fn suggest_fallback_scale_factor ( & self , scale_factor : f64 ) -> Result < ( ) , Error > {
60- self . window_handle . suggest_scale_factor ( scale_factor) ?;
78+ self . inner . suggest_scale_factor ( scale_factor) ?;
6179 Ok ( ( ) )
6280 }
6381
@@ -68,7 +86,7 @@ impl WindowHandle {
6886 /// It is guaranteed that no other objects (e.g. the parent window) are used by this window after
6987 /// this call.
7088 ///
71- /// Calling this method is more explicit, but otherwise identical to just dropping this [`WindowHandle `].
89+ /// Calling this method is more explicit, but otherwise identical to just dropping this [`Window `].
7290 #[ inline]
7391 pub fn close ( self ) {
7492 drop ( self )
@@ -78,7 +96,7 @@ impl WindowHandle {
7896 /// if the window was closed/dropped.
7997 #[ inline]
8098 pub fn is_open ( & self ) -> bool {
81- self . window_handle . is_open ( )
99+ self . inner . is_open ( )
82100 }
83101
84102 /// Performs the work the window thread had scheduled for the main thread.
@@ -92,22 +110,22 @@ impl WindowHandle {
92110 /// On Windows and macOS, this is always a no-op.
93111 #[ inline]
94112 pub fn host_main_thread_callback ( & mut self ) {
95- self . window_handle . handle_main_thread_callback ( )
113+ self . inner . handle_main_thread_callback ( )
96114 }
97115
98116 /// Reparents this window using the given `parent`.
99117 ///
100118 /// If the window was a floating window, it will become parented.
101119 #[ inline]
102120 pub fn set_parent ( & self , parent : impl Into < ParentWindowHandle > ) -> Result < ( ) , Error > {
103- self . window_handle . set_parent ( parent. into ( ) . inner ) ?;
121+ self . inner . set_parent ( parent. into ( ) . inner ) ?;
104122 Ok ( ( ) )
105123 }
106124
107125 /// Shows the window to the screen.
108126 #[ inline]
109127 pub fn show ( & self ) -> Result < ( ) , Error > {
110- self . window_handle . show ( ) ?;
128+ self . inner . show ( ) ?;
111129 Ok ( ( ) )
112130 }
113131
@@ -117,31 +135,11 @@ impl WindowHandle {
117135 /// paused and the user will not be able to see or interact with it.
118136 #[ inline]
119137 pub fn hide ( & self ) -> Result < ( ) , Error > {
120- self . window_handle . hide ( ) ?;
138+ self . inner . hide ( ) ?;
121139 Ok ( ( ) )
122140 }
123141}
124142
125- #[ inline]
126- pub fn create_window < H : WindowHandler > (
127- builder : WindowOpenOptions ,
128- handler : impl FnOnce ( WindowContext ) -> Result < H , HandlerError > + Send + ' static ,
129- ) -> Result < WindowHandle , Error > {
130- create_window_with_host ( builder, handler, None )
131- }
132-
133- pub fn create_window_with_host < H : WindowHandler > (
134- builder : WindowOpenOptions ,
135- handler : impl FnOnce ( WindowContext ) -> Result < H , HandlerError > + Send + ' static ,
136- host : impl Into < Option < Host > > ,
137- ) -> Result < WindowHandle , Error > {
138- Ok ( WindowHandle :: new ( platform:: WindowHandle :: create_window (
139- builder,
140- WindowHandlerBuilder :: new ( handler) ,
141- host. into ( ) . unwrap_or_else ( Host :: default) ,
142- ) ?) )
143- }
144-
145143/// A window's size, which can be read in either logical or physical pixels.
146144///
147145/// Methods that produce this type in baseview guarantee that either the physical or the logical
0 commit comments