1616 BOOL suppressSizeChanged;
1717 int fullscreen;
1818 int borderless;
19+ int centered;
1920};
2021
2122@implementation uiprivNSWindow
@@ -172,9 +173,9 @@ static int uiWindowVisible(uiControl *c)
172173 return [w->window isVisible ];
173174}
174175
175- void uiWindowShow (uiControl *c )
176+ void uiWindowShow (uiWindow *w )
176177{
177- uiWindow *w = (uiWindow *) c;
178+ // uiWindow *w = (uiWindow *) c;
178179 // TODO: D4
179180 // https://developer.apple.com/documentation/appkit/nswindow/1419208-makekeyandorderfront?language=objc
180181 [w->window makeKeyAndOrderFront: w->window];
@@ -184,6 +185,13 @@ void uiWindowShow(uiControl *c)
184185 // [w->window orderFront: nil];
185186}
186187
188+ void uiWindowSetCentered (uiWindow *w, int centered) {
189+ w->centered = centered;
190+ if (centered) {
191+ [w->window center ];
192+ }
193+ }
194+
187195static void uiWindowHide (uiControl *c)
188196{
189197 uiWindow *w = (uiWindow *) c;
@@ -226,6 +234,10 @@ static void windowRelayout(uiWindow *w)
226234 uiDarwinControlHugsBottom (uiDarwinControl (w->child )),
227235 w->margined ,
228236 @" uiWindow" );
237+
238+ if (w->centered ) {
239+ [w->window center ];
240+ }
229241}
230242
231243uiDarwinControlDefaultHugsTrailingEdge (uiWindow, window)
@@ -386,6 +398,17 @@ static void defaultOnPositionContentSizeChanged(uiWindow *w, void *data)
386398 defer: YES ];
387399 [w->window setTitle: uiprivToNSString (title)];
388400
401+ w->centered = 1 ;
402+
403+ // https://github.com/andlabs/libui/pull/271/files
404+ // if (NSEqualPoints(lastTopLeftPoint, NSZeroPoint)) {
405+ // // issue "cascadeTopLeftFromPoint" twice on first time
406+ // // to have window position in a good place
407+ // lastTopLeftPoint = [w->window cascadeTopLeftFromPoint:lastTopLeftPoint];
408+ // }
409+ // lastTopLeftPoint = [w->window cascadeTopLeftFromPoint:lastTopLeftPoint];
410+
411+
389412 // do NOT release when closed
390413 // we manually do this in uiWindowDestroy() above
391414 [w->window setReleasedWhenClosed: NO ];
0 commit comments