summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/app.c10
-rw-r--r--src/ui/root.c41
-rw-r--r--src/ui/root.h5
-rw-r--r--src/ui/window.c79
4 files changed, 87 insertions, 48 deletions
diff --git a/src/app.c b/src/app.c
index 29a97c8f..74323b7d 100644
--- a/src/app.c
+++ b/src/app.c
@@ -375,7 +375,7 @@ static void savePrefs_App_(const iApp *d) {
375static const char *magicState_App_ = "lgL1"; 375static const char *magicState_App_ = "lgL1";
376static const char *magicTabDocument_App_ = "tabd"; 376static const char *magicTabDocument_App_ = "tabd";
377 377
378enum iDocumentStateFlag { 378enum iDocumentStateFlag {
379 current_DocumentStateFlag = iBit(1), 379 current_DocumentStateFlag = iBit(1),
380 rootIndex1_DocumentStateFlag = iBit(2) 380 rootIndex1_DocumentStateFlag = iBit(2)
381}; 381};
@@ -1127,9 +1127,9 @@ static int resizeWatcher_(void *user, SDL_Event *event) {
1127 resetFonts_Text(); { 1127 resetFonts_Text(); {
1128 SDL_Event u = { .type = SDL_USEREVENT }; 1128 SDL_Event u = { .type = SDL_USEREVENT };
1129 u.user.code = command_UserEventCode; 1129 u.user.code = command_UserEventCode;
1130 u.user.data1 = strdup("theme.changed"); 1130 u.user.data1 = strdup("theme.changed auto:1");
1131 /*u.user.windowID = id_Window(d->window);*/ 1131 /*u.user.windowID = id_Window(d->window);*/
1132 dispatchEvent_Widget(d->window->root, &u); 1132 dispatchEvent_Window(d->window, &u);
1133 } 1133 }
1134#endif 1134#endif
1135 drawWhileResizing_Window(d->window, winev->data1, winev->data2); 1135 drawWhileResizing_Window(d->window, winev->data1, winev->data2);
@@ -1328,7 +1328,7 @@ iAny *findWidget_App(const char *id) {
1328 if (found) { 1328 if (found) {
1329 return found; 1329 return found;
1330 } 1330 }
1331 } 1331 }
1332 } 1332 }
1333 return NULL; 1333 return NULL;
1334} 1334}
@@ -2364,7 +2364,7 @@ iObjectList *listDocuments_App(const iRoot *rootOrNull) {
2364 if (isInstance_Object(i.object, &Class_DocumentWidget)) { 2364 if (isInstance_Object(i.object, &Class_DocumentWidget)) {
2365 pushBack_ObjectList(docs, i.object); 2365 pushBack_ObjectList(docs, i.object);
2366 } 2366 }
2367 } 2367 }
2368 } 2368 }
2369 } 2369 }
2370 return docs; 2370 return docs;
diff --git a/src/ui/root.c b/src/ui/root.c
index 548c0ca8..3661229e 100644
--- a/src/ui/root.c
+++ b/src/ui/root.c
@@ -237,13 +237,13 @@ static int loadAnimIndex_ = 0;
237static iRoot * activeRoot_ = NULL; 237static iRoot * activeRoot_ = NULL;
238 238
239iDefineTypeConstruction(Root) 239iDefineTypeConstruction(Root)
240 240
241void init_Root(iRoot *d) { 241void init_Root(iRoot *d) {
242 iZap(*d); 242 iZap(*d);
243} 243}
244 244
245void deinit_Root(iRoot *d) { 245void deinit_Root(iRoot *d) {
246 iReleasePtr(&d->widget); 246 iReleasePtr(&d->widget);
247} 247}
248 248
249void setCurrent_Root(iRoot *root) { 249void setCurrent_Root(iRoot *root) {
@@ -267,7 +267,7 @@ iAnyObject *findWidget_Root(const char *id) {
267} 267}
268 268
269void destroyPending_Root(iRoot *d) { 269void destroyPending_Root(iRoot *d) {
270 setCurrent_Root(d); 270 setCurrent_Root(d);
271 iForEach(PtrSet, i, d->pendingDestruction) { 271 iForEach(PtrSet, i, d->pendingDestruction) {
272 iWidget *widget = *i.value; 272 iWidget *widget = *i.value;
273 if (!isFinished_Anim(&widget->visualOffset)) { 273 if (!isFinished_Anim(&widget->visualOffset)) {
@@ -852,7 +852,7 @@ static iLabelWidget *newLargeIcon_LabelWidget(const char *text, const char *cmd)
852 return lab; 852 return lab;
853} 853}
854 854
855static int appIconSize_(void) { 855int appIconSize_Root(void) {
856 return lineHeight_Text(uiContent_FontId); 856 return lineHeight_Text(uiContent_FontId);
857} 857}
858 858
@@ -872,7 +872,7 @@ void updateMetrics_Root(iRoot *d) {
872 setFixedSize_Widget(appMin, init_I2(gap_UI * 11.5f, height_Widget(appTitle))); 872 setFixedSize_Widget(appMin, init_I2(gap_UI * 11.5f, height_Widget(appTitle)));
873 setFixedSize_Widget(appMax, appMin->rect.size); 873 setFixedSize_Widget(appMax, appMin->rect.size);
874 setFixedSize_Widget(appClose, appMin->rect.size); 874 setFixedSize_Widget(appClose, appMin->rect.size);
875 setFixedSize_Widget(appIcon, init_I2(appIconSize_(), appMin->rect.size.y)); 875 setFixedSize_Widget(appIcon, init_I2(appIconSize_Root(), appMin->rect.size.y));
876 } 876 }
877 iWidget *navBar = findChild_Widget(d->widget, "navbar"); 877 iWidget *navBar = findChild_Widget(d->widget, "navbar");
878 iWidget *lock = findChild_Widget(navBar, "navbar.lock"); 878 iWidget *lock = findChild_Widget(navBar, "navbar.lock");
@@ -900,11 +900,11 @@ void createUserInterface_Root(iRoot *d) {
900 setFlags_Widget( 900 setFlags_Widget(
901 root, resizeChildren_WidgetFlag | fixedSize_WidgetFlag | focusRoot_WidgetFlag, iTrue); 901 root, resizeChildren_WidgetFlag | fixedSize_WidgetFlag | focusRoot_WidgetFlag, iTrue);
902 setCommandHandler_Widget(root, handleRootCommands_); 902 setCommandHandler_Widget(root, handleRootCommands_);
903 903
904 iWidget *div = makeVDiv_Widget(); 904 iWidget *div = makeVDiv_Widget();
905 setId_Widget(div, "navdiv"); 905 setId_Widget(div, "navdiv");
906 addChild_Widget(root, iClob(div)); 906 addChild_Widget(root, iClob(div));
907 907
908#if defined (LAGRANGE_ENABLE_CUSTOM_FRAME) 908#if defined (LAGRANGE_ENABLE_CUSTOM_FRAME)
909 /* Window title bar. */ 909 /* Window title bar. */
910 if (prefs_App()->customFrame) { 910 if (prefs_App()->customFrame) {
@@ -912,16 +912,17 @@ void createUserInterface_Root(iRoot *d) {
912 iWidget *winBar = new_Widget(); 912 iWidget *winBar = new_Widget();
913 setId_Widget(winBar, "winbar"); 913 setId_Widget(winBar, "winbar");
914 setFlags_Widget(winBar, 914 setFlags_Widget(winBar,
915 arrangeHeight_WidgetFlag | resizeChildren_WidgetFlag | 915 arrangeHeight_WidgetFlag | resizeWidthOfChildren_WidgetFlag |
916 arrangeHorizontal_WidgetFlag | collapse_WidgetFlag, 916 arrangeHorizontal_WidgetFlag | collapse_WidgetFlag,
917 iTrue); 917 iTrue);
918 iWidget *appIcon; 918 iWidget *appIcon;
919 setId_Widget( 919 setId_Widget(addChildFlags_Widget(
920 addChild_Widget(winBar, iClob(appIcon = makePadding_Widget(0))), "winbar.icon"); 920 winBar, iClob(appIcon = makePadding_Widget(0)), collapse_WidgetFlag),
921 iLabelWidget *appButton = 921 "winbar.icon");
922 addChildFlags_Widget(winBar, 922 iLabelWidget *appButton = addChildFlags_Widget(
923 iClob(new_LabelWidget("Lagrange", NULL)), 923 winBar,
924 fixedHeight_WidgetFlag | frameless_WidgetFlag); 924 iClob(new_LabelWidget("Lagrange", NULL)),
925 fixedHeight_WidgetFlag | frameless_WidgetFlag | collapse_WidgetFlag);
925 setTextColor_LabelWidget(appButton, uiTextAppTitle_ColorId); 926 setTextColor_LabelWidget(appButton, uiTextAppTitle_ColorId);
926 setId_Widget(as_Widget(appButton), "winbar.app"); 927 setId_Widget(as_Widget(appButton), "winbar.app");
927 iLabelWidget *appTitle; 928 iLabelWidget *appTitle;
@@ -936,16 +937,16 @@ void createUserInterface_Root(iRoot *d) {
936 setId_Widget(addChildFlags_Widget( 937 setId_Widget(addChildFlags_Widget(
937 winBar, 938 winBar,
938 iClob(appMin = newLargeIcon_LabelWidget("\u2013", "window.minimize")), 939 iClob(appMin = newLargeIcon_LabelWidget("\u2013", "window.minimize")),
939 frameless_WidgetFlag), 940 frameless_WidgetFlag | collapse_WidgetFlag),
940 "winbar.min"); 941 "winbar.min");
941 addChildFlags_Widget( 942 addChildFlags_Widget(
942 winBar, 943 winBar,
943 iClob(appMax = newLargeIcon_LabelWidget("\u25a1", "window.maximize toggle:1")), 944 iClob(appMax = newLargeIcon_LabelWidget("\u25a1", "window.maximize toggle:1")),
944 frameless_WidgetFlag); 945 frameless_WidgetFlag | collapse_WidgetFlag);
945 setId_Widget(as_Widget(appMax), "winbar.max"); 946 setId_Widget(as_Widget(appMax), "winbar.max");
946 addChildFlags_Widget(winBar, 947 addChildFlags_Widget(winBar,
947 iClob(appClose = newLargeIcon_LabelWidget(close_Icon, "window.close")), 948 iClob(appClose = newLargeIcon_LabelWidget(close_Icon, "window.close")),
948 frameless_WidgetFlag); 949 frameless_WidgetFlag | collapse_WidgetFlag);
949 setId_Widget(as_Widget(appClose), "winbar.close"); 950 setId_Widget(as_Widget(appClose), "winbar.close");
950 setFont_LabelWidget(appClose, uiContent_FontId); 951 setFont_LabelWidget(appClose, uiContent_FontId);
951 addChild_Widget(div, iClob(winBar)); 952 addChild_Widget(div, iClob(winBar));
@@ -1087,7 +1088,7 @@ void createUserInterface_Root(iRoot *d) {
1087 "navbar.home"); 1088 "navbar.home");
1088#if defined (iPlatformMobile) 1089#if defined (iPlatformMobile)
1089 const iBool isPhone = (deviceType_App() == phone_AppDeviceType); 1090 const iBool isPhone = (deviceType_App() == phone_AppDeviceType);
1090#endif 1091#endif
1091#if !defined (iHaveNativeMenus) 1092#if !defined (iHaveNativeMenus)
1092# if defined (iPlatformAppleMobile) 1093# if defined (iPlatformAppleMobile)
1093 iLabelWidget *navMenu = 1094 iLabelWidget *navMenu =
@@ -1310,7 +1311,7 @@ iRect rect_Root(const iRoot *d) {
1310 if (d && d->widget) { 1311 if (d && d->widget) {
1311 return d->widget->rect; 1312 return d->widget->rect;
1312 } 1313 }
1313 return zero_Rect(); 1314 return zero_Rect();
1314} 1315}
1315 1316
1316iRect safeRect_Root(const iRoot *d) { 1317iRect safeRect_Root(const iRoot *d) {
diff --git a/src/ui/root.h b/src/ui/root.h
index 039e67ad..00555224 100644
--- a/src/ui/root.h
+++ b/src/ui/root.h
@@ -6,7 +6,7 @@
6#include <the_Foundation/vec2.h> 6#include <the_Foundation/vec2.h>
7 7
8iDeclareType(Root) 8iDeclareType(Root)
9 9
10struct Impl_Root { 10struct Impl_Root {
11 iWidget * widget; 11 iWidget * widget;
12 iPtrArray *onTop; /* order is important; last one is topmost */ 12 iPtrArray *onTop; /* order is important; last one is topmost */
@@ -28,7 +28,7 @@ iAnyObject *findWidget_Root (const char *id); /* under curre
28 28
29iPtrArray * onTop_Root (iRoot *); 29iPtrArray * onTop_Root (iRoot *);
30void destroyPending_Root (iRoot *); 30void destroyPending_Root (iRoot *);
31 31
32void updateMetrics_Root (iRoot *); 32void updateMetrics_Root (iRoot *);
33void updatePadding_Root (iRoot *); /* TODO: is part of metrics? */ 33void updatePadding_Root (iRoot *); /* TODO: is part of metrics? */
34void dismissPortraitPhoneSidebars_Root (iRoot *); 34void dismissPortraitPhoneSidebars_Root (iRoot *);
@@ -39,3 +39,4 @@ iRect rect_Root (const iRoot *);
39iRect safeRect_Root (const iRoot *); 39iRect safeRect_Root (const iRoot *);
40iInt2 visibleSize_Root (const iRoot *); /* may be obstructed by software keyboard */ 40iInt2 visibleSize_Root (const iRoot *); /* may be obstructed by software keyboard */
41iBool isNarrow_Root (const iRoot *); 41iBool isNarrow_Root (const iRoot *);
42int appIconSize_Root (void); \ No newline at end of file
diff --git a/src/ui/window.c b/src/ui/window.c
index 61851ca5..b3840602 100644
--- a/src/ui/window.c
+++ b/src/ui/window.c
@@ -210,7 +210,7 @@ static void windowSizeChanged_Window_(iWindow *d) {
210 updatePadding_Root(root); 210 updatePadding_Root(root);
211 arrange_Widget(root->widget); 211 arrange_Widget(root->widget);
212 } 212 }
213 } 213 }
214} 214}
215 215
216static void updateSize_Window_(iWindow *d, iBool notifyAlways) { 216static void updateSize_Window_(iWindow *d, iBool notifyAlways) {
@@ -297,6 +297,16 @@ static void drawBlank_Window_(iWindow *d) {
297 SDL_RenderPresent(d->render); 297 SDL_RenderPresent(d->render);
298} 298}
299 299
300static iRoot *rootAt_Window_(const iWindow *d, iInt2 coord) {
301 iForIndices(i, d->roots) {
302 iRoot *root = d->roots[i];
303 if (root && contains_Rect(rect_Root(root), coord)) {
304 return root;
305 }
306 }
307 return d->roots[0];
308}
309
300#if defined (LAGRANGE_ENABLE_CUSTOM_FRAME) 310#if defined (LAGRANGE_ENABLE_CUSTOM_FRAME)
301static SDL_HitTestResult hitTest_Window_(SDL_Window *win, const SDL_Point *pos, void *data) { 311static SDL_HitTestResult hitTest_Window_(SDL_Window *win, const SDL_Point *pos, void *data) {
302 iWindow *d = data; 312 iWindow *d = data;
@@ -312,8 +322,10 @@ static SDL_HitTestResult hitTest_Window_(SDL_Window *win, const SDL_Point *pos,
312 const iBool isRight = pos->x >= w - gap_UI; 322 const iBool isRight = pos->x >= w - gap_UI;
313 const iBool isTop = pos->y < gap_UI && snap != yMaximized_WindowSnap; 323 const iBool isTop = pos->y < gap_UI && snap != yMaximized_WindowSnap;
314 const iBool isBottom = pos->y >= h - gap_UI && snap != yMaximized_WindowSnap; 324 const iBool isBottom = pos->y >= h - gap_UI && snap != yMaximized_WindowSnap;
315 const int captionHeight = lineHeight_Text(uiContent_FontId) + gap_UI * 2; 325 const int captionHeight = lineHeight_Text(uiContent_FontId) + gap_UI * 2;
316 const int rightEdge = left_Rect(bounds_Widget(findChild_Widget(d->root, "winbar.min"))); 326 const int rightEdge = left_Rect(bounds_Widget(findChild_Widget(
327 rootAt_Window_(d, init_I2(pos->x, pos->y))->widget,
328 "winbar.min")));
317 d->place.lastHit = SDL_HITTEST_NORMAL; 329 d->place.lastHit = SDL_HITTEST_NORMAL;
318 if (snap != maximized_WindowSnap) { 330 if (snap != maximized_WindowSnap) {
319 if (isLeft) { 331 if (isLeft) {
@@ -486,7 +498,7 @@ void init_Window(iWindow *d, iRect rect) {
486#if defined (LAGRANGE_ENABLE_CUSTOM_FRAME) 498#if defined (LAGRANGE_ENABLE_CUSTOM_FRAME)
487 /* Load the app icon for drawing in the title bar. */ 499 /* Load the app icon for drawing in the title bar. */
488 if (prefs_App()->customFrame) { 500 if (prefs_App()->customFrame) {
489 SDL_Surface *surf = loadImage_(&imageLagrange64_Embedded, appIconSize_()); 501 SDL_Surface *surf = loadImage_(&imageLagrange64_Embedded, appIconSize_Root());
490 SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "0"); 502 SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "0");
491 d->appIcon = SDL_CreateTextureFromSurface(d->render, surf); 503 d->appIcon = SDL_CreateTextureFromSurface(d->render, surf);
492 free(surf->pixels); 504 free(surf->pixels);
@@ -508,7 +520,7 @@ void deinit_Window(iWindow *d) {
508 deinit_Root(d->roots[i]); 520 deinit_Root(d->roots[i]);
509 } 521 }
510 } 522 }
511 setCurrent_Root(NULL); 523 setCurrent_Root(NULL);
512 deinit_Text(); 524 deinit_Text();
513 SDL_DestroyRenderer(d->render); 525 SDL_DestroyRenderer(d->render);
514 SDL_DestroyWindow(d->win); 526 SDL_DestroyWindow(d->win);
@@ -870,7 +882,7 @@ iBool processEvent_Window(iWindow *d, const SDL_Event *ev) {
870 } 882 }
871 } 883 }
872 if (isMetricsChange_UserEvent(&event)) { 884 if (isMetricsChange_UserEvent(&event)) {
873 iForIndices(i, d->roots) { 885 iForIndices(i, d->roots) {
874 updateMetrics_Root(d->roots[i]); 886 updateMetrics_Root(d->roots[i]);
875 } 887 }
876 } 888 }
@@ -1005,7 +1017,7 @@ void draw_Window(iWindow *d) {
1005 /* App icon. */ 1017 /* App icon. */
1006 const iWidget *appIcon = findChild_Widget(root->widget, "winbar.icon"); 1018 const iWidget *appIcon = findChild_Widget(root->widget, "winbar.icon");
1007 if (isVisible_Widget(appIcon)) { 1019 if (isVisible_Widget(appIcon)) {
1008 const int size = appIconSize_(); 1020 const int size = appIconSize_Root();
1009 const iRect rect = bounds_Widget(appIcon); 1021 const iRect rect = bounds_Widget(appIcon);
1010 const iInt2 mid = mid_Rect(rect); 1022 const iInt2 mid = mid_Rect(rect);
1011 const iBool isLight = isLight_ColorTheme(colorTheme_App()); 1023 const iBool isLight = isLight_ColorTheme(colorTheme_App());
@@ -1199,6 +1211,27 @@ void setSplitMode_Window(iWindow *d, int splitMode) {
1199 setCurrent_Root(NULL); 1211 setCurrent_Root(NULL);
1200 } 1212 }
1201 d->splitMode = splitMode; 1213 d->splitMode = splitMode;
1214#if defined (LAGRANGE_ENABLE_CUSTOM_FRAME)
1215 /* Update custom frame controls. */{
1216 const iBool hideCtl0 = numRoots_Window(d) != 1;
1217 iWidget *winBar = findChild_Widget(d->roots[0]->widget, "winbar");
1218 if (winBar) {
1219 setFlags_Widget(
1220 findChild_Widget(winBar, "winbar.min"), hidden_WidgetFlag, hideCtl0);
1221 setFlags_Widget(
1222 findChild_Widget(winBar, "winbar.max"), hidden_WidgetFlag, hideCtl0);
1223 setFlags_Widget(
1224 findChild_Widget(winBar, "winbar.close"), hidden_WidgetFlag, hideCtl0);
1225 if (d->roots[1]) {
1226 winBar = findChild_Widget(d->roots[1]->widget, "winbar");
1227 setFlags_Widget(
1228 findChild_Widget(winBar, "winbar.icon"), hidden_WidgetFlag, iTrue);
1229 setFlags_Widget(
1230 findChild_Widget(winBar, "winbar.app"), hidden_WidgetFlag, iTrue);
1231 }
1232 }
1233 }
1234#endif
1202// windowSizeChanged_Window_(d); 1235// windowSizeChanged_Window_(d);
1203 updateSize_Window_(d, iTrue); 1236 updateSize_Window_(d, iTrue);
1204// postCommand_App("window.resized"); 1237// postCommand_App("window.resized");
@@ -1277,20 +1310,24 @@ void setSnap_Window(iWindow *d, int snapMode) {
1277 newRect.pos.y += newRect.size.y; 1310 newRect.pos.y += newRect.size.y;
1278 } 1311 }
1279 /* Update window controls. */ 1312 /* Update window controls. */
1280 iWidget *winBar = findWidget_App("winbar"); 1313 iForIndices(rootIndex, d->roots) {
1281 updateTextCStr_LabelWidget(findChild_Widget(winBar, "winbar.max"), 1314 iRoot *root = d->roots[rootIndex];
1282 d->place.snap == maximized_WindowSnap ? "\u25a2" : "\u25a1"); 1315 if (!root) continue;
1283 /* Show and hide the title bar. */ 1316 iWidget *winBar = findChild_Widget(root->widget, "winbar");
1284 const iBool wasVisible = isVisible_Widget(winBar); 1317 updateTextCStr_LabelWidget(findChild_Widget(winBar, "winbar.max"),
1285 setFlags_Widget(winBar, hidden_WidgetFlag, d->place.snap == fullscreen_WindowSnap); 1318 d->place.snap == maximized_WindowSnap ? "\u25a2" : "\u25a1");
1286 if (newRect.size.x) { 1319 /* Show and hide the title bar. */
1287 SDL_SetWindowPosition(d->win, newRect.pos.x, newRect.pos.y); 1320 const iBool wasVisible = isVisible_Widget(winBar);
1288 SDL_SetWindowSize(d->win, newRect.size.x, newRect.size.y); 1321 setFlags_Widget(winBar, hidden_WidgetFlag, d->place.snap == fullscreen_WindowSnap);
1289 postCommand_App("window.resized"); 1322 if (newRect.size.x) {
1290 } 1323 SDL_SetWindowPosition(d->win, newRect.pos.x, newRect.pos.y);
1291 if (wasVisible != isVisible_Widget(winBar)) { 1324 SDL_SetWindowSize(d->win, newRect.size.x, newRect.size.y);
1292 arrange_Widget(d->root); 1325 postCommand_App("window.resized");
1293 postRefresh_App(); 1326 }
1327 if (wasVisible != isVisible_Widget(winBar)) {
1328 arrange_Widget(root->widget);
1329 postRefresh_App();
1330 }
1294 } 1331 }
1295#endif /* defined (LAGRANGE_ENABLE_CUSTOM_FRAME) */ 1332#endif /* defined (LAGRANGE_ENABLE_CUSTOM_FRAME) */
1296} 1333}