diff options
author | Jaakko Keränen <jaakko.keranen@iki.fi> | 2021-02-26 10:26:31 +0200 |
---|---|---|
committer | Jaakko Keränen <jaakko.keranen@iki.fi> | 2021-02-26 10:26:31 +0200 |
commit | ce377bd4b703b3fb6ac8ae40b9bbd1ede2e4ca26 (patch) | |
tree | e1a5d7d506a06ba26764b0892e26b0de1875365e /src/ui/window.c | |
parent | 91a6225d8508db01574d7da2c013cb30d6a87ec8 (diff) |
Visual design improvements
URL input field has a maximum width. Adjusted navbar appearance and margins.
Tuned UI palette and added UI accent color preference.
Diffstat (limited to 'src/ui/window.c')
-rw-r--r-- | src/ui/window.c | 62 |
1 files changed, 42 insertions, 20 deletions
diff --git a/src/ui/window.c b/src/ui/window.c index bc19fd09..89b3d9ef 100644 --- a/src/ui/window.c +++ b/src/ui/window.c | |||
@@ -433,8 +433,8 @@ static uint32_t updateReloadAnimation_Window_(uint32_t interval, void *window) { | |||
433 | } | 433 | } |
434 | 434 | ||
435 | static void setReloadLabel_Window_(iWindow *d, iBool animating) { | 435 | static void setReloadLabel_Window_(iWindow *d, iBool animating) { |
436 | updateTextCStr_LabelWidget(findChild_Widget(d->root, "reload"), | 436 | iLabelWidget *label = findChild_Widget(d->root, "reload"); |
437 | animating ? loadAnimationCStr_() : reloadCStr_); | 437 | updateTextCStr_LabelWidget(label, animating ? loadAnimationCStr_() : reloadCStr_); |
438 | } | 438 | } |
439 | 439 | ||
440 | static void checkLoadAnimation_Window_(iWindow *d) { | 440 | static void checkLoadAnimation_Window_(iWindow *d) { |
@@ -495,10 +495,30 @@ static void showSearchQueryIndicator_(iBool show) { | |||
495 | (iInputWidget *) parent_Widget(indicator), -1, show ? width_Widget(indicator) : 0); | 495 | (iInputWidget *) parent_Widget(indicator), -1, show ? width_Widget(indicator) : 0); |
496 | } | 496 | } |
497 | 497 | ||
498 | static int navBarAvailableSpace_(iWidget *navBar) { | ||
499 | int avail = width_Rect(innerBounds_Widget(navBar)); | ||
500 | iConstForEach(ObjectList, i, children_Widget(navBar)) { | ||
501 | const iWidget *child = i.object; | ||
502 | if (~flags_Widget(child) & expand_WidgetFlag && | ||
503 | isVisible_Widget(child) && | ||
504 | cmp_String(id_Widget(child), "url")) { | ||
505 | avail -= width_Widget(child); | ||
506 | } | ||
507 | } | ||
508 | return avail; | ||
509 | } | ||
510 | |||
498 | static iBool handleNavBarCommands_(iWidget *navBar, const char *cmd) { | 511 | static iBool handleNavBarCommands_(iWidget *navBar, const char *cmd) { |
499 | if (equal_Command(cmd, "window.resized")) { | 512 | if (equal_Command(cmd, "window.resized")) { |
500 | const iBool isPhone = deviceType_App() == phone_AppDeviceType; | 513 | const iBool isPhone = deviceType_App() == phone_AppDeviceType; |
501 | const iBool isNarrow = !isPhone && width_Rect(bounds_Widget(navBar)) / gap_UI < 140; | 514 | const iBool isNarrow = !isPhone && width_Rect(bounds_Widget(navBar)) / gap_UI < 140; |
515 | /* Adjust navbar padding. */ { | ||
516 | int hPad = isPhone || isNarrow ? gap_UI / 2 : gap_UI * 3 / 2; | ||
517 | int vPad = gap_UI * 3 / 2; | ||
518 | int topPad = !findWidget_App("winbar") ? gap_UI / 2 : 0; | ||
519 | setPadding_Widget(navBar, hPad, vPad / 2 + topPad, hPad, vPad / 2); | ||
520 | } | ||
521 | /* Button sizing. */ | ||
502 | if (isNarrow ^ ((flags_Widget(navBar) & tight_WidgetFlag) != 0)) { | 522 | if (isNarrow ^ ((flags_Widget(navBar) & tight_WidgetFlag) != 0)) { |
503 | setFlags_Widget(navBar, tight_WidgetFlag, isNarrow); | 523 | setFlags_Widget(navBar, tight_WidgetFlag, isNarrow); |
504 | iForEach(ObjectList, i, navBar->children) { | 524 | iForEach(ObjectList, i, navBar->children) { |
@@ -531,7 +551,9 @@ static iBool handleNavBarCommands_(iWidget *navBar, const char *cmd) { | |||
531 | } | 551 | } |
532 | arrange_Widget(get_Window()->root); | 552 | arrange_Widget(get_Window()->root); |
533 | } | 553 | } |
534 | else { | 554 | /* Resize the URL input field. */ { |
555 | iWidget *urlBar = findChild_Widget(navBar, "url"); | ||
556 | urlBar->rect.size.x = iMini(navBarAvailableSpace_(navBar), 167 * gap_UI); | ||
535 | arrange_Widget(navBar); | 557 | arrange_Widget(navBar); |
536 | } | 558 | } |
537 | refresh_Widget(navBar); | 559 | refresh_Widget(navBar); |
@@ -795,9 +817,9 @@ static void setupUserInterface_Window(iWindow *d) { | |||
795 | iWidget *div = makeVDiv_Widget(); | 817 | iWidget *div = makeVDiv_Widget(); |
796 | setId_Widget(div, "navdiv"); | 818 | setId_Widget(div, "navdiv"); |
797 | addChild_Widget(d->root, iClob(div)); | 819 | addChild_Widget(d->root, iClob(div)); |
798 | 820 | ||
799 | #if defined (LAGRANGE_CUSTOM_FRAME) | 821 | #if defined (LAGRANGE_CUSTOM_FRAME) |
800 | /* Window title bar. */ | 822 | /* Window title bar. */ |
801 | if (prefs_App()->customFrame) { | 823 | if (prefs_App()->customFrame) { |
802 | setPadding1_Widget(div, 1); | 824 | setPadding1_Widget(div, 1); |
803 | iWidget *winBar = new_Widget(); | 825 | iWidget *winBar = new_Widget(); |
@@ -852,8 +874,6 @@ static void setupUserInterface_Window(iWindow *d) { | |||
852 | /* Navigation bar. */ { | 874 | /* Navigation bar. */ { |
853 | iWidget *navBar = new_Widget(); | 875 | iWidget *navBar = new_Widget(); |
854 | setId_Widget(navBar, "navbar"); | 876 | setId_Widget(navBar, "navbar"); |
855 | int topPad = !findChild_Widget(div, "winbar") ? gap_UI / 2 : 0; | ||
856 | setPadding_Widget(navBar, gap_UI, topPad, gap_UI, gap_UI / 2); | ||
857 | setFlags_Widget(navBar, | 877 | setFlags_Widget(navBar, |
858 | arrangeHeight_WidgetFlag | | 878 | arrangeHeight_WidgetFlag | |
859 | resizeChildren_WidgetFlag | | 879 | resizeChildren_WidgetFlag | |
@@ -866,6 +886,7 @@ static void setupUserInterface_Window(iWindow *d) { | |||
866 | setCommandHandler_Widget(navBar, handleNavBarCommands_); | 886 | setCommandHandler_Widget(navBar, handleNavBarCommands_); |
867 | setId_Widget(addChildFlags_Widget(navBar, iClob(newIcon_LabelWidget("\U0001f870", 0, 0, "navigate.back")), collapse_WidgetFlag), "navbar.back"); | 887 | setId_Widget(addChildFlags_Widget(navBar, iClob(newIcon_LabelWidget("\U0001f870", 0, 0, "navigate.back")), collapse_WidgetFlag), "navbar.back"); |
868 | setId_Widget(addChildFlags_Widget(navBar, iClob(newIcon_LabelWidget("\U0001f872", 0, 0, "navigate.forward")), collapse_WidgetFlag), "navbar.forward"); | 888 | setId_Widget(addChildFlags_Widget(navBar, iClob(newIcon_LabelWidget("\U0001f872", 0, 0, "navigate.forward")), collapse_WidgetFlag), "navbar.forward"); |
889 | addChildFlags_Widget(navBar, iClob(new_Widget()), expand_WidgetFlag); | ||
869 | iLabelWidget *idMenu = makeMenuButton_LabelWidget( | 890 | iLabelWidget *idMenu = makeMenuButton_LabelWidget( |
870 | "\U0001f464", identityButtonMenuItems_, iElemCount(identityButtonMenuItems_)); | 891 | "\U0001f464", identityButtonMenuItems_, iElemCount(identityButtonMenuItems_)); |
871 | setAlignVisually_LabelWidget(idMenu, iTrue); | 892 | setAlignVisually_LabelWidget(idMenu, iTrue); |
@@ -877,7 +898,7 @@ static void setupUserInterface_Window(iWindow *d) { | |||
877 | setUrlContent_InputWidget(url, iTrue); | 898 | setUrlContent_InputWidget(url, iTrue); |
878 | setNotifyEdits_InputWidget(url, iTrue); | 899 | setNotifyEdits_InputWidget(url, iTrue); |
879 | setTextCStr_InputWidget(url, "gemini://"); | 900 | setTextCStr_InputWidget(url, "gemini://"); |
880 | addChildFlags_Widget(navBar, iClob(url), expand_WidgetFlag); | 901 | addChildFlags_Widget(navBar, iClob(url), 0); |
881 | setPadding_Widget(as_Widget(url), 0, 0, gap_UI, 0); | 902 | setPadding_Widget(as_Widget(url), 0, 0, gap_UI, 0); |
882 | /* Page information/certificate warning. */ { | 903 | /* Page information/certificate warning. */ { |
883 | iLabelWidget *lock = | 904 | iLabelWidget *lock = |
@@ -928,7 +949,7 @@ static void setupUserInterface_Window(iWindow *d) { | |||
928 | setId_Widget(addChild_Widget( | 949 | setId_Widget(addChild_Widget( |
929 | navBar, iClob(newIcon_LabelWidget(reloadCStr_, 0, 0, "navigate.reload"))), | 950 | navBar, iClob(newIcon_LabelWidget(reloadCStr_, 0, 0, "navigate.reload"))), |
930 | "reload"); | 951 | "reload"); |
931 | 952 | addChildFlags_Widget(navBar, iClob(new_Widget()), expand_WidgetFlag); | |
932 | setId_Widget(addChildFlags_Widget(navBar, | 953 | setId_Widget(addChildFlags_Widget(navBar, |
933 | iClob(newIcon_LabelWidget( | 954 | iClob(newIcon_LabelWidget( |
934 | "\U0001f3e0", SDLK_h, KMOD_PRIMARY | KMOD_SHIFT, "navigate.home")), | 955 | "\U0001f3e0", SDLK_h, KMOD_PRIMARY | KMOD_SHIFT, "navigate.home")), |
@@ -1137,7 +1158,7 @@ static SDL_HitTestResult hitTest_Window_(SDL_Window *win, const SDL_Point *pos, | |||
1137 | const int snap = snap_Window(d); | 1158 | const int snap = snap_Window(d); |
1138 | int w, h; | 1159 | int w, h; |
1139 | SDL_GetWindowSize(win, &w, &h); | 1160 | SDL_GetWindowSize(win, &w, &h); |
1140 | /* TODO: Check if inside the caption label widget. */ | 1161 | /* TODO: Check if inside the caption label widget. */ |
1141 | const iBool isLeft = pos->x < gap_UI; | 1162 | const iBool isLeft = pos->x < gap_UI; |
1142 | const iBool isRight = pos->x >= w - gap_UI; | 1163 | const iBool isRight = pos->x >= w - gap_UI; |
1143 | const iBool isTop = pos->y < gap_UI && snap != yMaximized_WindowSnap; | 1164 | const iBool isTop = pos->y < gap_UI && snap != yMaximized_WindowSnap; |
@@ -1306,7 +1327,7 @@ void init_Window(iWindow *d, iRect rect) { | |||
1306 | updateRootSize_Window_(d, iFalse); | 1327 | updateRootSize_Window_(d, iFalse); |
1307 | d->appIcon = NULL; | 1328 | d->appIcon = NULL; |
1308 | #if defined (LAGRANGE_CUSTOM_FRAME) | 1329 | #if defined (LAGRANGE_CUSTOM_FRAME) |
1309 | /* Load the app icon for drawing in the title bar. */ | 1330 | /* Load the app icon for drawing in the title bar. */ |
1310 | if (prefs_App()->customFrame) { | 1331 | if (prefs_App()->customFrame) { |
1311 | SDL_Surface *surf = loadAppIconSurface_(appIconSize_()); | 1332 | SDL_Surface *surf = loadAppIconSurface_(appIconSize_()); |
1312 | SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "0"); | 1333 | SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "0"); |
@@ -1416,7 +1437,7 @@ static iBool handleWindowEvent_Window_(iWindow *d, const SDL_WindowEvent *ev) { | |||
1416 | #endif | 1437 | #endif |
1417 | return iFalse; | 1438 | return iFalse; |
1418 | case SDL_WINDOWEVENT_MOVED: { | 1439 | case SDL_WINDOWEVENT_MOVED: { |
1419 | if (d->isMinimized) { | 1440 | if (d->isMinimized) { |
1420 | return iFalse; | 1441 | return iFalse; |
1421 | } | 1442 | } |
1422 | const iInt2 newPos = init_I2(ev->data1, ev->data2); | 1443 | const iInt2 newPos = init_I2(ev->data1, ev->data2); |
@@ -1426,7 +1447,7 @@ static iBool handleWindowEvent_Window_(iWindow *d, const SDL_WindowEvent *ev) { | |||
1426 | return iFalse; | 1447 | return iFalse; |
1427 | } | 1448 | } |
1428 | #if defined (LAGRANGE_CUSTOM_FRAME) | 1449 | #if defined (LAGRANGE_CUSTOM_FRAME) |
1429 | /* Set the snap position depending on where the mouse cursor is. */ | 1450 | /* Set the snap position depending on where the mouse cursor is. */ |
1430 | if (prefs_App()->customFrame) { | 1451 | if (prefs_App()->customFrame) { |
1431 | SDL_Rect usable; | 1452 | SDL_Rect usable; |
1432 | iInt2 mouse = cursor_Win32(); /* SDL is unaware of the current cursor pos */ | 1453 | iInt2 mouse = cursor_Win32(); /* SDL is unaware of the current cursor pos */ |
@@ -1473,7 +1494,7 @@ static iBool handleWindowEvent_Window_(iWindow *d, const SDL_WindowEvent *ev) { | |||
1473 | } | 1494 | } |
1474 | case SDL_WINDOWEVENT_RESIZED: | 1495 | case SDL_WINDOWEVENT_RESIZED: |
1475 | updatePadding_Window_(d); | 1496 | updatePadding_Window_(d); |
1476 | if (d->isMinimized) { | 1497 | if (d->isMinimized) { |
1477 | updateRootSize_Window_(d, iTrue); | 1498 | updateRootSize_Window_(d, iTrue); |
1478 | return iTrue; | 1499 | return iTrue; |
1479 | } | 1500 | } |
@@ -1485,16 +1506,16 @@ static iBool handleWindowEvent_Window_(iWindow *d, const SDL_WindowEvent *ev) { | |||
1485 | //printf("normal rect set (resize)\n"); fflush(stdout); | 1506 | //printf("normal rect set (resize)\n"); fflush(stdout); |
1486 | } | 1507 | } |
1487 | updateRootSize_Window_(d, iTrue /* we were already redrawing during the resize */); | 1508 | updateRootSize_Window_(d, iTrue /* we were already redrawing during the resize */); |
1509 | postRefresh_App(); | ||
1488 | return iTrue; | 1510 | return iTrue; |
1489 | case SDL_WINDOWEVENT_RESTORED: | 1511 | case SDL_WINDOWEVENT_RESTORED: |
1490 | //updateRootSize_Window_(d, iTrue); | 1512 | updateRootSize_Window_(d, iTrue); |
1491 | invalidate_Window_(d); | 1513 | invalidate_Window_(d); |
1492 | d->isMinimized = iFalse; | 1514 | d->isMinimized = iFalse; |
1493 | postRefresh_App(); | 1515 | postRefresh_App(); |
1494 | return iTrue; | 1516 | return iTrue; |
1495 | case SDL_WINDOWEVENT_MINIMIZED: | 1517 | case SDL_WINDOWEVENT_MINIMIZED: |
1496 | d->isMinimized = iTrue; | 1518 | d->isMinimized = iTrue; |
1497 | //printf("minimized\n"); fflush(stdout); | ||
1498 | return iTrue; | 1519 | return iTrue; |
1499 | case SDL_WINDOWEVENT_LEAVE: | 1520 | case SDL_WINDOWEVENT_LEAVE: |
1500 | unhover_Widget(); | 1521 | unhover_Widget(); |
@@ -1507,6 +1528,7 @@ static iBool handleWindowEvent_Window_(iWindow *d, const SDL_WindowEvent *ev) { | |||
1507 | return iTrue; | 1528 | return iTrue; |
1508 | case SDL_WINDOWEVENT_TAKE_FOCUS: | 1529 | case SDL_WINDOWEVENT_TAKE_FOCUS: |
1509 | SDL_SetWindowInputFocus(d->win); | 1530 | SDL_SetWindowInputFocus(d->win); |
1531 | postRefresh_App(); | ||
1510 | return iTrue; | 1532 | return iTrue; |
1511 | case SDL_WINDOWEVENT_FOCUS_GAINED: | 1533 | case SDL_WINDOWEVENT_FOCUS_GAINED: |
1512 | d->focusGainedAt = SDL_GetTicks(); | 1534 | d->focusGainedAt = SDL_GetTicks(); |
@@ -1532,13 +1554,13 @@ iBool processEvent_Window(iWindow *d, const SDL_Event *ev) { | |||
1532 | switch (ev->type) { | 1554 | switch (ev->type) { |
1533 | #if defined (LAGRANGE_CUSTOM_FRAME) | 1555 | #if defined (LAGRANGE_CUSTOM_FRAME) |
1534 | case SDL_SYSWMEVENT: { | 1556 | case SDL_SYSWMEVENT: { |
1535 | /* We observe native Win32 messages for better user interaction with the | 1557 | /* We observe native Win32 messages for better user interaction with the |
1536 | window frame. Mouse clicks especially will not generate normal SDL | 1558 | window frame. Mouse clicks especially will not generate normal SDL |
1537 | events if they happen on the custom hit-tested regions. These events | 1559 | events if they happen on the custom hit-tested regions. These events |
1538 | are processed only there; the UI widgets do not get involved. */ | 1560 | are processed only there; the UI widgets do not get involved. */ |
1539 | processNativeEvent_Win32(ev->syswm.msg, d); | 1561 | processNativeEvent_Win32(ev->syswm.msg, d); |
1540 | break; | 1562 | break; |
1541 | } | 1563 | } |
1542 | #endif | 1564 | #endif |
1543 | case SDL_WINDOWEVENT: { | 1565 | case SDL_WINDOWEVENT: { |
1544 | return handleWindowEvent_Window_(d, &ev->window); | 1566 | return handleWindowEvent_Window_(d, &ev->window); |
@@ -1778,7 +1800,7 @@ void setSnap_Window(iWindow *d, int snapMode) { | |||
1778 | return; | 1800 | return; |
1779 | } | 1801 | } |
1780 | const int snapDist = gap_UI * 4; | 1802 | const int snapDist = gap_UI * 4; |
1781 | iRect newRect = zero_Rect(); | 1803 | iRect newRect = zero_Rect(); |
1782 | SDL_Rect usable; | 1804 | SDL_Rect usable; |
1783 | SDL_GetDisplayUsableBounds(SDL_GetWindowDisplayIndex(d->win), &usable); | 1805 | SDL_GetDisplayUsableBounds(SDL_GetWindowDisplayIndex(d->win), &usable); |
1784 | if (d->place.snap == fullscreen_WindowSnap) { | 1806 | if (d->place.snap == fullscreen_WindowSnap) { |