summaryrefslogtreecommitdiff
path: root/src/ui/root.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/ui/root.c')
-rw-r--r--src/ui/root.c78
1 files changed, 40 insertions, 38 deletions
diff --git a/src/ui/root.c b/src/ui/root.c
index f6b93abd..1fa36851 100644
--- a/src/ui/root.c
+++ b/src/ui/root.c
@@ -234,23 +234,27 @@ static const char *stopSeqCStr_[] = {
234static const int loadAnimIntervalMs_ = 133; 234static const int loadAnimIntervalMs_ = 133;
235static int loadAnimIndex_ = 0; 235static int loadAnimIndex_ = 0;
236 236
237static iWidget * activeRoot_ = NULL; 237static iRoot * activeRoot_ = NULL;
238static iRootData * activeRootData_ = NULL;
239 238
240void setCurrent_Root(iWidget *root, iRootData *rootData) { 239iDefineTypeConstruction(Root)
241 activeRoot_ = root; 240
242 activeRootData_ = rootData; 241void init_Root(iRoot *d) {
242 iZap(*d);
243} 243}
244 244
245iWidget *get_Root(void) { 245void deinit_Root(iRoot *d) {
246 return activeRoot_; 246 iReleasePtr(&d->widget);
247}
248
249void setCurrent_Root(iRoot *root) {
250 activeRoot_ = root;
247} 251}
248 252
249iRootData *data_Root(void) { 253iRoot *get_Root(void) {
250 return activeRootData_; 254 return activeRoot_;
251} 255}
252 256
253void destroyPending_RootData(iRootData *d) { 257void destroyPending_Root(iRoot *d) {
254 iForEach(PtrSet, i, d->pendingDestruction) { 258 iForEach(PtrSet, i, d->pendingDestruction) {
255 iWidget *widget = *i.value; 259 iWidget *widget = *i.value;
256 if (!isFinished_Anim(&widget->visualOffset)) { 260 if (!isFinished_Anim(&widget->visualOffset)) {
@@ -265,12 +269,11 @@ void destroyPending_RootData(iRootData *d) {
265 } 269 }
266} 270}
267 271
268iPtrArray *onTop_RootData(void) { 272iPtrArray *onTop_Root(iRoot *d) {
269 iAssert(activeRootData_); 273 if (!d->onTop) {
270 if (!activeRootData_->onTop) { 274 d->onTop = new_PtrArray();
271 activeRootData_->onTop = new_PtrArray();
272 } 275 }
273 return activeRootData_->onTop; 276 return d->onTop;
274} 277}
275 278
276static iBool handleRootCommands_(iWidget *root, const char *cmd) { 279static iBool handleRootCommands_(iWidget *root, const char *cmd) {
@@ -423,7 +426,7 @@ static uint32_t updateReloadAnimation_Window_(uint32_t interval, void *window) {
423 426
424static void setReloadLabel_Window_(iWindow *d, iBool animating) { 427static void setReloadLabel_Window_(iWindow *d, iBool animating) {
425 const iBool isMobile = deviceType_App() != desktop_AppDeviceType; 428 const iBool isMobile = deviceType_App() != desktop_AppDeviceType;
426 iLabelWidget *label = findChild_Widget(d->root, "reload"); 429 iLabelWidget *label = findChild_Widget(d->root.widget, "reload");
427 updateTextCStr_LabelWidget(label, animating ? loadAnimationCStr_() : 430 updateTextCStr_LabelWidget(label, animating ? loadAnimationCStr_() :
428 (isMobile ? pageMenuCStr_ : reloadCStr_)); 431 (isMobile ? pageMenuCStr_ : reloadCStr_));
429 if (isMobile) { 432 if (isMobile) {
@@ -444,13 +447,13 @@ static void checkLoadAnimation_Window_(iWindow *d) {
444 setReloadLabel_Window_(d, isOngoing); 447 setReloadLabel_Window_(d, isOngoing);
445} 448}
446 449
447void updatePadding_Root(iWidget *d) { 450void updatePadding_Root(iRoot *d) {
448#if defined (iPlatformAppleMobile) 451#if defined (iPlatformAppleMobile)
449 iWidget *toolBar = findChild_Widget(d, "toolbar"); 452 iWidget *toolBar = findChild_Widget(d->widget, "toolbar");
450 float left, top, right, bottom; 453 float left, top, right, bottom;
451 safeAreaInsets_iOS(&left, &top, &right, &bottom); 454 safeAreaInsets_iOS(&left, &top, &right, &bottom);
452 /* Respect the safe area insets. */ { 455 /* Respect the safe area insets. */ {
453 setPadding_Widget(findChild_Widget(d, "navdiv"), left, top, right, 0); 456 setPadding_Widget(findChild_Widget(d->widget, "navdiv"), left, top, right, 0);
454 if (toolBar) { 457 if (toolBar) {
455 setPadding_Widget(toolBar, left, 0, right, bottom); 458 setPadding_Widget(toolBar, left, 0, right, bottom);
456 } 459 }
@@ -458,8 +461,8 @@ void updatePadding_Root(iWidget *d) {
458 if (toolBar) { 461 if (toolBar) {
459 /* TODO: get this from toolBar height, but it's buggy for some reason */ 462 /* TODO: get this from toolBar height, but it's buggy for some reason */
460 const int sidebarBottomPad = isPortrait_App() ? 11 * gap_UI + bottom : 0; 463 const int sidebarBottomPad = isPortrait_App() ? 11 * gap_UI + bottom : 0;
461 setPadding_Widget(findChild_Widget(d, "sidebar"), 0, 0, 0, sidebarBottomPad); 464 setPadding_Widget(findChild_Widget(d->widget, "sidebar"), 0, 0, 0, sidebarBottomPad);
462 setPadding_Widget(findChild_Widget(d, "sidebar2"), 0, 0, 0, sidebarBottomPad); 465 setPadding_Widget(findChild_Widget(d->widget, "sidebar2"), 0, 0, 0, sidebarBottomPad);
463 /* TODO: There seems to be unrelated layout glitch in the sidebar where its children 466 /* TODO: There seems to be unrelated layout glitch in the sidebar where its children
464 are not arranged correctly until it's hidden and reshown. */ 467 are not arranged correctly until it's hidden and reshown. */
465 } 468 }
@@ -469,10 +472,10 @@ void updatePadding_Root(iWidget *d) {
469#endif 472#endif
470} 473}
471 474
472void dismissPortraitPhoneSidebars_Root(iWidget *root) { 475void dismissPortraitPhoneSidebars_Root(iRoot *d) {
473 if (deviceType_App() == phone_AppDeviceType && isPortrait_App()) { 476 if (deviceType_App() == phone_AppDeviceType && isPortrait_App()) {
474 iWidget *sidebar = findChild_Widget(root, "sidebar"); 477 iWidget *sidebar = findChild_Widget(d->widget, "sidebar");
475 iWidget *sidebar2 = findChild_Widget(root, "sidebar2"); 478 iWidget *sidebar2 = findChild_Widget(d->widget, "sidebar2");
476 if (isVisible_Widget(sidebar)) { 479 if (isVisible_Widget(sidebar)) {
477 postCommand_App("sidebar.toggle"); 480 postCommand_App("sidebar.toggle");
478 setVisualOffset_Widget(sidebar, height_Widget(sidebar), 250, easeIn_AnimFlag); 481 setVisualOffset_Widget(sidebar, height_Widget(sidebar), 250, easeIn_AnimFlag);
@@ -564,7 +567,7 @@ static iBool handleNavBarCommands_(iWidget *navBar, const char *cmd) {
564 updateSize_LabelWidget(btn); 567 updateSize_LabelWidget(btn);
565 } 568 }
566 } 569 }
567 arrange_Widget(get_Window()->root); 570 arrange_Widget(get_Window()->root.widget);
568 } 571 }
569 /* Resize the URL input field. */ { 572 /* Resize the URL input field. */ {
570 iWidget *urlBar = findChild_Widget(navBar, "url"); 573 iWidget *urlBar = findChild_Widget(navBar, "url");
@@ -716,7 +719,7 @@ static iBool handleSearchBarCommands_(iWidget *searchBar, const char *cmd) {
716 if (pointer_Command(cmd) == findChild_Widget(searchBar, "find.input")) { 719 if (pointer_Command(cmd) == findChild_Widget(searchBar, "find.input")) {
717 if (!isVisible_Widget(searchBar)) { 720 if (!isVisible_Widget(searchBar)) {
718 setFlags_Widget(searchBar, hidden_WidgetFlag | disabled_WidgetFlag, iFalse); 721 setFlags_Widget(searchBar, hidden_WidgetFlag | disabled_WidgetFlag, iFalse);
719 arrange_Widget(get_Window()->root); 722 arrange_Widget(get_Window()->root.widget);
720 postRefresh_App(); 723 postRefresh_App();
721 } 724 }
722 } 725 }
@@ -824,9 +827,9 @@ static int appIconSize_(void) {
824 return lineHeight_Text(uiContent_FontId); 827 return lineHeight_Text(uiContent_FontId);
825} 828}
826 829
827void updateMetrics_Root(iWidget *d) { 830void updateMetrics_Root(iRoot *d) {
828 /* Custom frame. */ 831 /* Custom frame. */
829 iWidget *winBar = findChild_Widget(d, "winbar"); 832 iWidget *winBar = findChild_Widget(d->widget, "winbar");
830 if (winBar) { 833 if (winBar) {
831 iWidget *appIcon = findChild_Widget(winBar, "winbar.icon"); 834 iWidget *appIcon = findChild_Widget(winBar, "winbar.icon");
832 iWidget *appTitle = findChild_Widget(winBar, "winbar.title"); 835 iWidget *appTitle = findChild_Widget(winBar, "winbar.title");
@@ -839,9 +842,9 @@ void updateMetrics_Root(iWidget *d) {
839 setFixedSize_Widget(appClose, appMin->rect.size); 842 setFixedSize_Widget(appClose, appMin->rect.size);
840 setFixedSize_Widget(appIcon, init_I2(appIconSize_(), appMin->rect.size.y)); 843 setFixedSize_Widget(appIcon, init_I2(appIconSize_(), appMin->rect.size.y));
841 } 844 }
842 iWidget *navBar = findChild_Widget(d, "navbar"); 845 iWidget *navBar = findChild_Widget(d->widget, "navbar");
843 iWidget *lock = findChild_Widget(navBar, "navbar.lock"); 846 iWidget *lock = findChild_Widget(navBar, "navbar.lock");
844 iWidget *url = findChild_Widget(d, "url"); 847 iWidget *url = findChild_Widget(d->widget, "url");
845 iWidget *rightEmbed = findChild_Widget(navBar, "url.rightembed"); 848 iWidget *rightEmbed = findChild_Widget(navBar, "url.rightembed");
846 iWidget *embedPad = findChild_Widget(navBar, "url.embedpad"); 849 iWidget *embedPad = findChild_Widget(navBar, "url.embedpad");
847 setPadding_Widget(as_Widget(url), 0, gap_UI, 0, gap_UI); 850 setPadding_Widget(as_Widget(url), 0, gap_UI, 0, gap_UI);
@@ -852,12 +855,12 @@ void updateMetrics_Root(iWidget *d) {
852 width_Widget(lock) * 0.75); 855 width_Widget(lock) * 0.75);
853 rightEmbed->rect.pos.y = gap_UI; 856 rightEmbed->rect.pos.y = gap_UI;
854 updatePadding_Root(d); 857 updatePadding_Root(d);
855 arrange_Widget(d); 858 arrange_Widget(d->widget);
856 postRefresh_App(); 859 postRefresh_App();
857} 860}
858 861
859iWidget *createUserInterface_Root(void) { 862void createUserInterface_Root(iRoot *d) {
860 iWidget *root = new_Widget(); 863 iWidget *root = d->widget = new_Widget();
861 setId_Widget(root, "root"); 864 setId_Widget(root, "root");
862 /* Children of root cover the entire window. */ 865 /* Children of root cover the entire window. */
863 setFlags_Widget( 866 setFlags_Widget(
@@ -1180,7 +1183,7 @@ iWidget *createUserInterface_Root(void) {
1180 setId_Widget(menu, "toolbar.menu"); /* view menu */ 1183 setId_Widget(menu, "toolbar.menu"); /* view menu */
1181 } 1184 }
1182#endif 1185#endif
1183 updatePadding_Root(root); 1186 updatePadding_Root(d);
1184 /* Global context menus. */ { 1187 /* Global context menus. */ {
1185 iWidget *tabsMenu = makeMenu_Widget( 1188 iWidget *tabsMenu = makeMenu_Widget(
1186 root, 1189 root,
@@ -1226,14 +1229,13 @@ iWidget *createUserInterface_Root(void) {
1226 addAction_Widget(root, '4', rightSidebar_KeyModifier, "sidebar2.mode arg:3 toggle:1"); 1229 addAction_Widget(root, '4', rightSidebar_KeyModifier, "sidebar2.mode arg:3 toggle:1");
1227 addAction_Widget(root, '5', rightSidebar_KeyModifier, "sidebar2.mode arg:4 toggle:1"); 1230 addAction_Widget(root, '5', rightSidebar_KeyModifier, "sidebar2.mode arg:4 toggle:1");
1228 } 1231 }
1229 updateMetrics_Root(root); 1232 updateMetrics_Root(d);
1230 return root;
1231} 1233}
1232 1234
1233void showToolbars_Root(iWidget *root, iBool show) { 1235void showToolbars_Root(iRoot *d, iBool show) {
1234 /* The toolbar is only used on phone portrait layout. */ 1236 /* The toolbar is only used on phone portrait layout. */
1235 if (isLandscape_App()) return; 1237 if (isLandscape_App()) return;
1236 iWidget *toolBar = findChild_Widget(root, "toolbar"); 1238 iWidget *toolBar = findChild_Widget(d->widget, "toolbar");
1237 if (!toolBar) return; 1239 if (!toolBar) return;
1238 const int height = rootSize_Window(get_Window()).y - top_Rect(boundsWithoutVisualOffset_Widget(toolBar)); 1240 const int height = rootSize_Window(get_Window()).y - top_Rect(boundsWithoutVisualOffset_Widget(toolBar));
1239 if (show && !isVisible_Widget(toolBar)) { 1241 if (show && !isVisible_Widget(toolBar)) {