@@ -2,25 +2,28 @@ use std::rc::Rc;
22
33use inherit_methods_macro:: inherit_methods;
44use objc2:: { MainThreadOnly , rc:: Retained } ;
5- use objc2_foundation:: { MainThreadMarker , NSArray , NSSize } ;
5+ use objc2_foundation:: { MainThreadMarker , NSArray , NSSize , NSString } ;
66use objc2_ui_kit:: { NSLayoutConstraint , UIView , UIViewController , UIWindow } ;
77use winio_callback:: Callback ;
88use winio_handle:: {
99 AsContainer , AsWidget , AsWindow , BorrowedContainer , BorrowedWidget , BorrowedWindow ,
1010} ;
1111use winio_primitive:: { Point , Size } ;
12+ use winio_ui_apple_common:: from_nsstring;
1213
1314use crate :: {
14- Error , RESIZE_SLAB , Result , catch, first_ui_window_scene, from_cgpoint, from_cgsize,
15+ Error , MOVE_SLAB , RESIZE_SLAB , Result , catch, first_ui_window_scene, from_cgpoint, from_cgsize,
1516 to_cgpoint, to_cgsize,
1617} ;
1718
1819#[ derive( Debug ) ]
1920pub struct Window {
2021 wnd : Retained < UIWindow > ,
2122 content_view : Retained < UIView > ,
22- did_resize : Rc < Callback < Size > > ,
23+ did_resize : Rc < Callback > ,
24+ did_move : Rc < Callback > ,
2325 resize_index : usize ,
26+ move_index : usize ,
2427}
2528
2629impl Window {
@@ -35,7 +38,9 @@ impl Window {
3538 let controller = UIViewController :: new ( mtm) ;
3639
3740 let did_resize = Rc :: new ( Callback :: new ( ) ) ;
38- let index = RESIZE_SLAB . with_borrow_mut ( |s| s. insert ( did_resize. clone ( ) ) ) ;
41+ let resize_index = RESIZE_SLAB . with_borrow_mut ( |s| s. insert ( did_resize. clone ( ) ) ) ;
42+ let did_move = Rc :: new ( Callback :: new ( ) ) ;
43+ let move_index = MOVE_SLAB . with_borrow_mut ( |s| s. insert ( did_move. clone ( ) ) ) ;
3944
4045 wnd. setRootViewController ( Some ( & controller) ) ;
4146 wnd. makeKeyWindow ( ) ;
@@ -65,7 +70,9 @@ impl Window {
6570 wnd,
6671 content_view,
6772 did_resize,
68- resize_index : index,
73+ resize_index,
74+ did_move,
75+ move_index,
6976 } )
7077 } )
7178 . flatten ( )
@@ -103,19 +110,30 @@ impl Window {
103110 }
104111
105112 pub fn text ( & self ) -> Result < String > {
106- Ok ( String :: new ( ) )
113+ catch ( || {
114+ self . wnd
115+ . windowScene ( )
116+ . map ( |s| s. title ( ) )
117+ . as_deref ( )
118+ . map ( from_nsstring)
119+ . unwrap_or_default ( )
120+ } )
107121 }
108122
109- pub fn set_text ( & mut self , _s : impl AsRef < str > ) -> Result < ( ) > {
110- Ok ( ( ) )
123+ pub fn set_text ( & mut self , s : impl AsRef < str > ) -> Result < ( ) > {
124+ catch ( || {
125+ if let Some ( scene) = self . wnd . windowScene ( ) {
126+ scene. setTitle ( Some ( & NSString :: from_str ( s. as_ref ( ) ) ) ) ;
127+ }
128+ } )
111129 }
112130
113131 pub async fn wait_size ( & self ) {
114132 self . did_resize . wait ( ) . await ;
115133 }
116134
117135 pub async fn wait_move ( & self ) {
118- std :: future :: pending ( ) . await
136+ self . did_move . wait ( ) . await ;
119137 }
120138
121139 pub async fn wait_close ( & self ) {
@@ -130,6 +148,7 @@ impl Window {
130148impl Drop for Window {
131149 fn drop ( & mut self ) {
132150 RESIZE_SLAB . with_borrow_mut ( |s| s. remove ( self . resize_index ) ) ;
151+ MOVE_SLAB . with_borrow_mut ( |s| s. remove ( self . move_index ) ) ;
133152 }
134153}
135154
0 commit comments