summaryrefslogtreecommitdiff
path: root/src/ui/root.c
diff options
context:
space:
mode:
authorJaakko Keränen <jaakko.keranen@iki.fi>2021-09-12 13:49:38 +0300
committerJaakko Keränen <jaakko.keranen@iki.fi>2021-09-12 13:49:38 +0300
commit33620846cca5678fbd662ea1a48fad302727dae7 (patch)
tree322fb4ab2c1dd7dd3eceee0834f3e90d27838de4 /src/ui/root.c
parent1410bbde7779efe3a20f603523547c8b8f55b6a1 (diff)
Mobile: Draw optimizations; focus handling
Widgets can now be marked for buffering their contents, which is useful if their contents change seldom but they are drawn often. For example, the navbar is always visible but doesn't change very often, and during animations menu contents are static but there is a moving animation so everything gets drawn 60 FPS. Focus handling was also improved so the lookup results can be scrolled while entering text, and one can tap outside an input field to unfocus it.
Diffstat (limited to 'src/ui/root.c')
-rw-r--r--src/ui/root.c54
1 files changed, 51 insertions, 3 deletions
diff --git a/src/ui/root.c b/src/ui/root.c
index a792e93d..7b2b5b15 100644
--- a/src/ui/root.c
+++ b/src/ui/root.c
@@ -685,6 +685,34 @@ static iBool handleNavBarCommands_(iWidget *navBar, const char *cmd) {
685 } 685 }
686 return iTrue; 686 return iTrue;
687 } 687 }
688 else if (deviceType_App() != desktop_AppDeviceType &&
689 (equal_Command(cmd, "focus.gained") || equal_Command(cmd, "focus.lost"))) {
690 iInputWidget *url = findChild_Widget(navBar, "url");
691 if (pointer_Command(cmd) == url) {
692 const iBool isFocused = equal_Command(cmd, "focus.gained");
693 setFlags_Widget(findChild_Widget(navBar, "navbar.clear"), hidden_WidgetFlag, !isFocused);
694 showCollapsed_Widget(findChild_Widget(navBar, "navbar.cancel"), isFocused);
695 showCollapsed_Widget(findChild_Widget(navBar, "pagemenubutton"), !isFocused);
696 showCollapsed_Widget(findChild_Widget(navBar, "reload"), !isFocused);
697 }
698 return iFalse;
699 }
700 else if (equal_Command(cmd, "navbar.clear")) {
701 iInputWidget *url = findChild_Widget(navBar, "url");
702 selectAll_InputWidget(url);
703 /* Emulate a Backspace keypress. */
704 class_InputWidget(url)->processEvent(
705 as_Widget(url),
706 (SDL_Event *) &(SDL_KeyboardEvent){ .type = SDL_KEYDOWN,
707 .timestamp = SDL_GetTicks(),
708 .state = SDL_PRESSED,
709 .keysym = { .sym = SDLK_BACKSPACE } });
710 return iTrue;
711 }
712 else if (equal_Command(cmd, "navbar.cancel")) {
713 setFocus_Widget(NULL);
714 return iTrue;
715 }
688 else if (equal_Command(cmd, "input.edited")) { 716 else if (equal_Command(cmd, "input.edited")) {
689 iAnyObject * url = findChild_Widget(navBar, "url"); 717 iAnyObject * url = findChild_Widget(navBar, "url");
690 const iString *text = text_InputWidget(url); 718 const iString *text = text_InputWidget(url);
@@ -941,7 +969,7 @@ void updateMetrics_Root(iRoot *d) {
941 setFixedSize_Widget(appIcon, init_I2(appIconSize_Root(), appMin->rect.size.y)); 969 setFixedSize_Widget(appIcon, init_I2(appIconSize_Root(), appMin->rect.size.y));
942 } 970 }
943 iWidget *navBar = findChild_Widget(d->widget, "navbar"); 971 iWidget *navBar = findChild_Widget(d->widget, "navbar");
944 iWidget *lock = findChild_Widget(navBar, "navbar.lock"); 972// iWidget *lock = findChild_Widget(navBar, "navbar.lock");
945 iWidget *url = findChild_Widget(d->widget, "url"); 973 iWidget *url = findChild_Widget(d->widget, "url");
946 iWidget *rightEmbed = findChild_Widget(navBar, "url.rightembed"); 974 iWidget *rightEmbed = findChild_Widget(navBar, "url.rightembed");
947 iWidget *embedPad = findChild_Widget(navBar, "url.embedpad"); 975 iWidget *embedPad = findChild_Widget(navBar, "url.embedpad");
@@ -1044,6 +1072,7 @@ void createUserInterface_Root(iRoot *d) {
1044 /* Navigation bar. */ { 1072 /* Navigation bar. */ {
1045 navBar = new_Widget(); 1073 navBar = new_Widget();
1046 setId_Widget(navBar, "navbar"); 1074 setId_Widget(navBar, "navbar");
1075 setDrawBufferEnabled_Widget(navBar, iTrue);
1047 setFlags_Widget(navBar, 1076 setFlags_Widget(navBar,
1048 hittable_WidgetFlag | /* context menu */ 1077 hittable_WidgetFlag | /* context menu */
1049 arrangeHeight_WidgetFlag | 1078 arrangeHeight_WidgetFlag |
@@ -1095,6 +1124,16 @@ void createUserInterface_Root(iRoot *d) {
1095 setFont_LabelWidget(lock, symbols_FontId + uiNormal_FontSize); 1124 setFont_LabelWidget(lock, symbols_FontId + uiNormal_FontSize);
1096 updateTextCStr_LabelWidget(lock, "\U0001f512"); 1125 updateTextCStr_LabelWidget(lock, "\U0001f512");
1097 } 1126 }
1127 /* Button for clearing the URL bar contents. */ {
1128 iLabelWidget *clear = addChildFlags_Widget(
1129 as_Widget(url),
1130 iClob(newIcon_LabelWidget(delete_Icon, 0, 0, "navbar.clear")),
1131 hidden_WidgetFlag | embedFlags | moveToParentLeftEdge_WidgetFlag);
1132 setId_Widget(as_Widget(clear), "navbar.clear");
1133 setFont_LabelWidget(clear, symbols2_FontId + uiNormal_FontSize);
1134 setFlags_Widget(as_Widget(clear), noBackground_WidgetFlag, iFalse);
1135 setBackgroundColor_Widget(as_Widget(clear), uiBackground_ColorId);
1136 }
1098 iWidget *rightEmbed = new_Widget(); 1137 iWidget *rightEmbed = new_Widget();
1099 setId_Widget(rightEmbed, "url.rightembed"); 1138 setId_Widget(rightEmbed, "url.rightembed");
1100 addChildFlags_Widget(as_Widget(url), 1139 addChildFlags_Widget(as_Widget(url),
@@ -1151,6 +1190,13 @@ void createUserInterface_Root(iRoot *d) {
1151 setFlags_Widget(urlButtons, embedFlags | arrangeHorizontal_WidgetFlag | arrangeSize_WidgetFlag, iTrue); 1190 setFlags_Widget(urlButtons, embedFlags | arrangeHorizontal_WidgetFlag | arrangeSize_WidgetFlag, iTrue);
1152 /* Mobile page menu. */ 1191 /* Mobile page menu. */
1153 if (deviceType_App() != desktop_AppDeviceType) { 1192 if (deviceType_App() != desktop_AppDeviceType) {
1193 iLabelWidget *navCancel = new_LabelWidget("${cancel}", "navbar.cancel");
1194 addChildFlags_Widget(urlButtons, iClob(navCancel),
1195 (embedFlags | tight_WidgetFlag | hidden_WidgetFlag |
1196 collapse_WidgetFlag) & ~noBackground_WidgetFlag);
1197 as_Widget(navCancel)->sizeRef = as_Widget(url);
1198// setFont_LabelWidget(navCancel, defaultBold_FontId);
1199 setId_Widget(as_Widget(navCancel), "navbar.cancel");
1154 iLabelWidget *pageMenuButton; 1200 iLabelWidget *pageMenuButton;
1155 /* In a mobile layout, the reload button is replaced with the Page/Ellipsis menu. */ 1201 /* In a mobile layout, the reload button is replaced with the Page/Ellipsis menu. */
1156 pageMenuButton = makeMenuButton_LabelWidget(pageMenuCStr_, 1202 pageMenuButton = makeMenuButton_LabelWidget(pageMenuCStr_,
@@ -1172,13 +1218,14 @@ void createUserInterface_Root(iRoot *d) {
1172 setId_Widget(as_Widget(pageMenuButton), "pagemenubutton"); 1218 setId_Widget(as_Widget(pageMenuButton), "pagemenubutton");
1173 setFont_LabelWidget(pageMenuButton, uiContentBold_FontId); 1219 setFont_LabelWidget(pageMenuButton, uiContentBold_FontId);
1174 setAlignVisually_LabelWidget(pageMenuButton, iTrue); 1220 setAlignVisually_LabelWidget(pageMenuButton, iTrue);
1175 addChildFlags_Widget(urlButtons, iClob(pageMenuButton), embedFlags | tight_WidgetFlag); 1221 addChildFlags_Widget(urlButtons, iClob(pageMenuButton),
1222 embedFlags | tight_WidgetFlag | collapse_WidgetFlag);
1176 updateSize_LabelWidget(pageMenuButton); 1223 updateSize_LabelWidget(pageMenuButton);
1177 } 1224 }
1178 /* Reload button. */ { 1225 /* Reload button. */ {
1179 iLabelWidget *reload = newIcon_LabelWidget(reloadCStr_, 0, 0, "navigate.reload"); 1226 iLabelWidget *reload = newIcon_LabelWidget(reloadCStr_, 0, 0, "navigate.reload");
1180 setId_Widget(as_Widget(reload), "reload"); 1227 setId_Widget(as_Widget(reload), "reload");
1181 addChildFlags_Widget(urlButtons, iClob(reload), embedFlags); 1228 addChildFlags_Widget(urlButtons, iClob(reload), embedFlags | collapse_WidgetFlag);
1182 updateSize_LabelWidget(reload); 1229 updateSize_LabelWidget(reload);
1183 } 1230 }
1184 addChildFlags_Widget(as_Widget(url), iClob(urlButtons), moveToParentRightEdge_WidgetFlag); 1231 addChildFlags_Widget(as_Widget(url), iClob(urlButtons), moveToParentRightEdge_WidgetFlag);
@@ -1287,6 +1334,7 @@ void createUserInterface_Root(iRoot *d) {
1287 iWidget *toolBar = new_Widget(); 1334 iWidget *toolBar = new_Widget();
1288 addChild_Widget(root, iClob(toolBar)); 1335 addChild_Widget(root, iClob(toolBar));
1289 setId_Widget(toolBar, "toolbar"); 1336 setId_Widget(toolBar, "toolbar");
1337 setDrawBufferEnabled_Widget(toolBar, iTrue);
1290 setCommandHandler_Widget(toolBar, handleToolBarCommands_); 1338 setCommandHandler_Widget(toolBar, handleToolBarCommands_);
1291 setFlags_Widget(toolBar, moveToParentBottomEdge_WidgetFlag | 1339 setFlags_Widget(toolBar, moveToParentBottomEdge_WidgetFlag |
1292 parentCannotResizeHeight_WidgetFlag | 1340 parentCannotResizeHeight_WidgetFlag |