summaryrefslogtreecommitdiff
path: root/src/ui/window.c
diff options
context:
space:
mode:
authorJaakko Keränen <jaakko.keranen@iki.fi>2021-03-04 09:14:30 +0200
committerJaakko Keränen <jaakko.keranen@iki.fi>2021-03-04 09:14:30 +0200
commit1d735299127aaf0474d8fc2a1c5ec4947c1dca9a (patch)
tree926f4d136a2799c5fcf62589259ede57c04c35a9 /src/ui/window.c
parent2f6fd59952ce3d76b15a4b7b8f526e27edd39775 (diff)
Changing UI scaling at runtime
UI scaling factor is applied when closing the Preferences dialog. IssueID #83
Diffstat (limited to 'src/ui/window.c')
-rw-r--r--src/ui/window.c75
1 files changed, 54 insertions, 21 deletions
diff --git a/src/ui/window.c b/src/ui/window.c
index fb5daa80..4f9ac9c3 100644
--- a/src/ui/window.c
+++ b/src/ui/window.c
@@ -511,7 +511,7 @@ static int navBarAvailableSpace_(iWidget *navBar) {
511} 511}
512 512
513static iBool handleNavBarCommands_(iWidget *navBar, const char *cmd) { 513static iBool handleNavBarCommands_(iWidget *navBar, const char *cmd) {
514 if (equal_Command(cmd, "window.resized")) { 514 if (equal_Command(cmd, "window.resized") || equal_Command(cmd, "metrics.changed")) {
515 const iBool isPhone = deviceType_App() == phone_AppDeviceType; 515 const iBool isPhone = deviceType_App() == phone_AppDeviceType;
516 const iBool isNarrow = !isPhone && width_Rect(bounds_Widget(navBar)) / gap_UI < 140; 516 const iBool isNarrow = !isPhone && width_Rect(bounds_Widget(navBar)) / gap_UI < 140;
517 /* Adjust navbar padding. */ { 517 /* Adjust navbar padding. */ {
@@ -810,8 +810,43 @@ static int appIconSize_(void) {
810 return lineHeight_Text(uiContent_FontId); 810 return lineHeight_Text(uiContent_FontId);
811} 811}
812 812
813static void updateMetrics_Window_(iWindow *d) {
814 /* Custom frame. */
815 iWidget *winBar = findChild_Widget(d->root, "winbar");
816 if (winBar) {
817 iWidget *appIcon = findChild_Widget(winBar, "winbar.icon");
818 iWidget *appTitle = findChild_Widget(winBar, "winbar.title");
819 iWidget *appMin = findChild_Widget(winBar, "winbar.min");
820 iWidget *appMax = findChild_Widget(winBar, "winbar.max");
821 iWidget *appClose = findChild_Widget(winBar, "winbar.close");
822 setPadding_Widget(winBar, 0, gap_UI / 3, 0, 0);
823 setSize_Widget(appMin, init_I2(gap_UI * 11.5f, height_Widget(appTitle)));
824 setSize_Widget(appMax, appMin->rect.size);
825 setSize_Widget(appClose, appMin->rect.size);
826 setSize_Widget(appIcon, init_I2(appIconSize_(), appMin->rect.size.y));
827 }
828 iWidget *navBar = findChild_Widget(d->root, "navbar");
829 iWidget *lock = findChild_Widget(navBar, "navbar.lock");
830 iWidget *url = findChild_Widget(d->root, "url");
831 iWidget *fprog = findChild_Widget(navBar, "feeds.progress");
832 iWidget *docProg = findChild_Widget(navBar, "document.progress");
833 iWidget *indSearch = findChild_Widget(navBar, "input.indicator.search");
834 setPadding_Widget(as_Widget(url), 0, gap_UI, gap_UI, gap_UI);
835 navBar->rect.size.y = 0; /* recalculate height based on children (FIXME: shouldn't be needed) */
836 updateSize_LabelWidget((iLabelWidget *) lock);
837 setContentPadding_InputWidget((iInputWidget *) url, width_Widget(lock) * 0.75, -1);
838 fprog->rect.pos.y = gap_UI;
839 docProg->rect.pos.y = gap_UI;
840 indSearch->rect.pos.y = gap_UI;
841 updatePadding_Window_(d);
842 arrange_Widget(d->root);
843 postRefresh_App();
844}
845
813static void setupUserInterface_Window(iWindow *d) { 846static void setupUserInterface_Window(iWindow *d) {
847#if defined (iPlatformMobile)
814 const iBool isPhone = (deviceType_App() == phone_AppDeviceType); 848 const iBool isPhone = (deviceType_App() == phone_AppDeviceType);
849#endif
815 /* Children of root cover the entire window. */ 850 /* Children of root cover the entire window. */
816 setFlags_Widget(d->root, resizeChildren_WidgetFlag, iTrue); 851 setFlags_Widget(d->root, resizeChildren_WidgetFlag, iTrue);
817 setCommandHandler_Widget(d->root, handleRootCommands_); 852 setCommandHandler_Widget(d->root, handleRootCommands_);
@@ -825,7 +860,6 @@ static void setupUserInterface_Window(iWindow *d) {
825 if (prefs_App()->customFrame) { 860 if (prefs_App()->customFrame) {
826 setPadding1_Widget(div, 1); 861 setPadding1_Widget(div, 1);
827 iWidget *winBar = new_Widget(); 862 iWidget *winBar = new_Widget();
828 setPadding_Widget(winBar, 0, gap_UI / 3, 0, 0);
829 setId_Widget(winBar, "winbar"); 863 setId_Widget(winBar, "winbar");
830 setFlags_Widget(winBar, 864 setFlags_Widget(winBar,
831 arrangeHeight_WidgetFlag | resizeChildren_WidgetFlag | 865 arrangeHeight_WidgetFlag | resizeChildren_WidgetFlag |
@@ -854,8 +888,6 @@ static void setupUserInterface_Window(iWindow *d) {
854 iClob(appMin = newLargeIcon_LabelWidget("\u2013", "window.minimize")), 888 iClob(appMin = newLargeIcon_LabelWidget("\u2013", "window.minimize")),
855 frameless_WidgetFlag), 889 frameless_WidgetFlag),
856 "winbar.min"); 890 "winbar.min");
857 setSize_Widget(as_Widget(appMin),
858 init_I2(gap_UI * 11.5f, height_Widget(appTitle)));
859 addChildFlags_Widget( 891 addChildFlags_Widget(
860 winBar, 892 winBar,
861 iClob(appMax = newLargeIcon_LabelWidget("\u25a1", "window.maximize toggle:1")), 893 iClob(appMax = newLargeIcon_LabelWidget("\u25a1", "window.maximize toggle:1")),
@@ -864,10 +896,8 @@ static void setupUserInterface_Window(iWindow *d) {
864 addChildFlags_Widget(winBar, 896 addChildFlags_Widget(winBar,
865 iClob(appClose = newLargeIcon_LabelWidget("\u2a2f", "window.close")), 897 iClob(appClose = newLargeIcon_LabelWidget("\u2a2f", "window.close")),
866 frameless_WidgetFlag); 898 frameless_WidgetFlag);
899 setId_Widget(appClose, "winbar.close");
867 setFont_LabelWidget(appClose, uiContent_FontId); 900 setFont_LabelWidget(appClose, uiContent_FontId);
868 setSize_Widget(as_Widget(appMax), as_Widget(appMin)->rect.size);
869 setSize_Widget(as_Widget(appClose), as_Widget(appMin)->rect.size);
870 setSize_Widget(appIcon, init_I2(appIconSize_(), as_Widget(appMin)->rect.size.y));
871 addChild_Widget(div, iClob(winBar)); 901 addChild_Widget(div, iClob(winBar));
872 setBackgroundColor_Widget(winBar, uiBackground_ColorId); 902 setBackgroundColor_Widget(winBar, uiBackground_ColorId);
873 } 903 }
@@ -895,23 +925,23 @@ static void setupUserInterface_Window(iWindow *d) {
895 setId_Widget(addChildFlags_Widget(navBar, iClob(idMenu), collapse_WidgetFlag), "navbar.ident"); 925 setId_Widget(addChildFlags_Widget(navBar, iClob(idMenu), collapse_WidgetFlag), "navbar.ident");
896 /* URL input field. */ { 926 /* URL input field. */ {
897 iInputWidget *url = new_InputWidget(0); 927 iInputWidget *url = new_InputWidget(0);
928 setFlags_Widget(as_Widget(url), resizeHeightOfChildren_WidgetFlag, iTrue);
898 setSelectAllOnFocus_InputWidget(url, iTrue); 929 setSelectAllOnFocus_InputWidget(url, iTrue);
899 setId_Widget(as_Widget(url), "url"); 930 setId_Widget(as_Widget(url), "url");
900 setUrlContent_InputWidget(url, iTrue); 931 setUrlContent_InputWidget(url, iTrue);
901 setNotifyEdits_InputWidget(url, iTrue); 932 setNotifyEdits_InputWidget(url, iTrue);
902 setTextCStr_InputWidget(url, "gemini://"); 933 setTextCStr_InputWidget(url, "gemini://");
903 addChildFlags_Widget(navBar, iClob(url), 0); 934 addChildFlags_Widget(navBar, iClob(url), 0);
904 setPadding_Widget(as_Widget(url), 0, 0, gap_UI, 0);
905 /* Page information/certificate warning. */ { 935 /* Page information/certificate warning. */ {
906 iLabelWidget *lock = 936 iLabelWidget *lock =
907 addChildFlags_Widget(as_Widget(url), 937 addChildFlags_Widget(as_Widget(url),
908 iClob(newIcon_LabelWidget("\U0001f513", SDLK_i, KMOD_PRIMARY, "document.info")), 938 iClob(newIcon_LabelWidget("\U0001f513", SDLK_i, KMOD_PRIMARY, "document.info")),
909 noBackground_WidgetFlag | frameless_WidgetFlag | moveToParentLeftEdge_WidgetFlag | 939 noBackground_WidgetFlag | frameless_WidgetFlag | moveToParentLeftEdge_WidgetFlag |
940 unpadded_WidgetFlag |
910 (deviceType_App() == desktop_AppDeviceType ? tight_WidgetFlag : 0)); 941 (deviceType_App() == desktop_AppDeviceType ? tight_WidgetFlag : 0));
911 setId_Widget(as_Widget(lock), "navbar.lock"); 942 setId_Widget(as_Widget(lock), "navbar.lock");
912 setFont_LabelWidget(lock, defaultSymbols_FontId); 943 setFont_LabelWidget(lock, defaultSymbols_FontId);
913 updateTextCStr_LabelWidget(lock, "\U0001f512"); 944 updateTextCStr_LabelWidget(lock, "\U0001f512");
914 setContentPadding_InputWidget(url, width_Widget(lock) * 0.75, -1);
915 } 945 }
916 /* Feeds refresh indicator is inside the input field. */ { 946 /* Feeds refresh indicator is inside the input field. */ {
917 iLabelWidget *fprog = new_LabelWidget(uiTextCaution_ColorEscape 947 iLabelWidget *fprog = new_LabelWidget(uiTextCaution_ColorEscape
@@ -919,7 +949,7 @@ static void setupUserInterface_Window(iWindow *d) {
919 setId_Widget(as_Widget(fprog), "feeds.progress"); 949 setId_Widget(as_Widget(fprog), "feeds.progress");
920 setBackgroundColor_Widget(as_Widget(fprog), uiBackground_ColorId); 950 setBackgroundColor_Widget(as_Widget(fprog), uiBackground_ColorId);
921 setAlignVisually_LabelWidget(fprog, iTrue); 951 setAlignVisually_LabelWidget(fprog, iTrue);
922 shrink_Rect(&as_Widget(fprog)->rect, init_I2(0, gap_UI)); 952// shrink_Rect(&as_Widget(fprog)->rect, init_I2(0, gap_UI));
923 addChildFlags_Widget(as_Widget(url), 953 addChildFlags_Widget(as_Widget(url),
924 iClob(fprog), 954 iClob(fprog),
925 moveToParentRightEdge_WidgetFlag | hidden_WidgetFlag); 955 moveToParentRightEdge_WidgetFlag | hidden_WidgetFlag);
@@ -930,7 +960,7 @@ static void setupUserInterface_Window(iWindow *d) {
930 setId_Widget(as_Widget(progress), "document.progress"); 960 setId_Widget(as_Widget(progress), "document.progress");
931 setBackgroundColor_Widget(as_Widget(progress), uiBackground_ColorId); 961 setBackgroundColor_Widget(as_Widget(progress), uiBackground_ColorId);
932 setAlignVisually_LabelWidget(progress, iTrue); 962 setAlignVisually_LabelWidget(progress, iTrue);
933 shrink_Rect(&as_Widget(progress)->rect, init_I2(0, gap_UI)); 963// shrink_Rect(&as_Widget(progress)->rect, init_I2(0, gap_UI));
934 addChildFlags_Widget(as_Widget(url), 964 addChildFlags_Widget(as_Widget(url),
935 iClob(progress), 965 iClob(progress),
936 moveToParentRightEdge_WidgetFlag); 966 moveToParentRightEdge_WidgetFlag);
@@ -942,7 +972,7 @@ static void setupUserInterface_Window(iWindow *d) {
942 setBackgroundColor_Widget(as_Widget(queryInd), uiBackground_ColorId); 972 setBackgroundColor_Widget(as_Widget(queryInd), uiBackground_ColorId);
943 setFrameColor_Widget(as_Widget(queryInd), uiTextAction_ColorId); 973 setFrameColor_Widget(as_Widget(queryInd), uiTextAction_ColorId);
944 setAlignVisually_LabelWidget(queryInd, iTrue); 974 setAlignVisually_LabelWidget(queryInd, iTrue);
945 shrink_Rect(&as_Widget(queryInd)->rect, init_I2(0, gap_UI)); 975// shrink_Rect(&as_Widget(queryInd)->rect, init_I2(0, gap_UI));
946 addChildFlags_Widget(as_Widget(url), 976 addChildFlags_Widget(as_Widget(url),
947 iClob(queryInd), 977 iClob(queryInd),
948 moveToParentRightEdge_WidgetFlag | hidden_WidgetFlag); 978 moveToParentRightEdge_WidgetFlag | hidden_WidgetFlag);
@@ -1098,6 +1128,7 @@ static void setupUserInterface_Window(iWindow *d) {
1098 addAction_Widget(d->root, '4', rightSidebar_KeyModifier, "sidebar2.mode arg:3 toggle:1"); 1128 addAction_Widget(d->root, '4', rightSidebar_KeyModifier, "sidebar2.mode arg:3 toggle:1");
1099 addAction_Widget(d->root, '5', rightSidebar_KeyModifier, "sidebar2.mode arg:4 toggle:1"); 1129 addAction_Widget(d->root, '5', rightSidebar_KeyModifier, "sidebar2.mode arg:4 toggle:1");
1100 } 1130 }
1131 updateMetrics_Window_(d);
1101} 1132}
1102 1133
1103static void updateRootSize_Window_(iWindow *d, iBool notifyAlways) { 1134static void updateRootSize_Window_(iWindow *d, iBool notifyAlways) {
@@ -1636,6 +1667,9 @@ iBool processEvent_Window(iWindow *d, const SDL_Event *ev) {
1636 wasUsed = dispatchEvent_Widget(widget, &paste); 1667 wasUsed = dispatchEvent_Widget(widget, &paste);
1637 } 1668 }
1638 } 1669 }
1670 if (isMetricsChange_UserEvent(&event)) {
1671 updateMetrics_Window_(d);
1672 }
1639 if (oldHover != hover_Widget()) { 1673 if (oldHover != hover_Widget()) {
1640 postRefresh_App(); 1674 postRefresh_App();
1641 } 1675 }
@@ -1716,14 +1750,13 @@ void setTitle_Window(iWindow *d, const iString *title) {
1716void setUiScale_Window(iWindow *d, float uiScale) { 1750void setUiScale_Window(iWindow *d, float uiScale) {
1717 uiScale = iClamp(uiScale, 0.5f, 4.0f); 1751 uiScale = iClamp(uiScale, 0.5f, 4.0f);
1718 if (d) { 1752 if (d) {
1719 d->uiScale = uiScale; 1753 if (iAbs(d->uiScale - uiScale) > 0.0001f) {
1720#if 0 1754 d->uiScale = uiScale;
1721 deinit_Text(); 1755 /* Dynamic UI metrics change. Widgets need to update themselves. */
1722 setPixelRatio_Metrics(d->pixelRatio * d->uiScale); 1756 setPixelRatio_Metrics(d->pixelRatio * d->uiScale);
1723 init_Text(d->render); 1757 resetFonts_Text();
1724 postCommand_App("metrics.changed"); 1758 postCommand_App("metrics.changed");
1725 /* TODO: Dynamic UI metrics change. Widgets need to update themselves. */ 1759 }
1726#endif
1727 } 1760 }
1728 else { 1761 else {
1729 initialUiScale_ = uiScale; 1762 initialUiScale_ = uiScale;