From 963ad5fad6905a94c077246b8045e139e1139fc8 Mon Sep 17 00:00:00 2001 From: Jaakko Keränen Date: Sat, 10 Apr 2021 13:44:46 +0300 Subject: SidebarWidget: Action button fonts --- src/ui/sidebarwidget.c | 44 ++++++++++++++++++++++++++------------------ src/ui/widget.h | 1 + src/ui/window.c | 2 ++ 3 files changed, 29 insertions(+), 18 deletions(-) (limited to 'src') diff --git a/src/ui/sidebarwidget.c b/src/ui/sidebarwidget.c index 5c71ef0d..1a769f64 100644 --- a/src/ui/sidebarwidget.c +++ b/src/ui/sidebarwidget.c @@ -100,6 +100,7 @@ struct Impl_SidebarWidget { iLabelWidget * modeButtons[max_SidebarMode]; int maxButtonLabelWidth; int widthAsGaps; + int buttonFont; int itemFonts[2]; size_t numUnreadEntries; iWidget * resizer; @@ -133,6 +134,17 @@ static int cmpTitle_Bookmark_(const iBookmark **a, const iBookmark **b) { return cmpStringCase_String(&bm1->title, &bm2->title); } +static iLabelWidget *addActionButton_SidebarWidget_(iSidebarWidget *d, const char *label, + const char *command, int64_t flags) { + iLabelWidget *btn = addChildFlags_Widget(d->actions, + iClob(new_LabelWidget(label, command)), + (deviceType_App() != desktop_AppDeviceType ? + extraPadding_WidgetFlag : 0) | flags); + setFont_LabelWidget(btn, d->buttonFont == uiLabelLarge_FontId ? defaultBig_FontId : d->buttonFont); + checkIcon_LabelWidget(btn); + return btn; +} + static void updateItems_SidebarWidget_(iSidebarWidget *d) { clear_ListWidget(d->list); releaseChildren_Widget(d->blank); @@ -216,14 +228,10 @@ static void updateItems_SidebarWidget_(iSidebarWidget *d) { } } /* Actions. */ { - addChildFlags_Widget( - d->actions, - iClob(new_LabelWidget("${sidebar.action.feeds.showall}", "feeds.mode arg:0")), - d->feedsMode == all_FeedsMode ? selected_WidgetFlag : 0); - addChildFlags_Widget(d->actions, - iClob(new_LabelWidget("${sidebar.action.feeds.showunread}", - "feeds.mode arg:1")), - d->feedsMode == unread_FeedsMode ? selected_WidgetFlag : 0); + addActionButton_SidebarWidget_(d, "${sidebar.action.feeds.showall}", "feeds.mode arg:0", + d->feedsMode == all_FeedsMode ? selected_WidgetFlag : 0); + addActionButton_SidebarWidget_(d, "${sidebar.action.feeds.showunread}", "feeds.mode arg:1", + d->feedsMode == unread_FeedsMode ? selected_WidgetFlag : 0); } d->menu = makeMenu_Widget( as_Widget(d), @@ -293,9 +301,9 @@ static void updateItems_SidebarWidget_(iSidebarWidget *d) { { copy_Icon " ${menu.dup}", 0, 0, "bookmark.dup" }, { "${menu.copyurl}", 0, 0, "bookmark.copy" }, { "---", 0, 0, NULL }, - { "?", 0, 0, "bookmark.tag tag:subscribed" }, - { "?", 0, 0, "bookmark.tag tag:homepage" }, - { "?", 0, 0, "bookmark.tag tag:remotesource" }, + { "", 0, 0, "bookmark.tag tag:subscribed" }, + { "", 0, 0, "bookmark.tag tag:homepage" }, + { "", 0, 0, "bookmark.tag tag:remotesource" }, { "---", 0, 0, NULL }, { delete_Icon " " uiTextCaution_ColorEscape "${bookmark.delete}", 0, 0, "bookmark.delete" }, { "---", 0, 0, NULL }, @@ -359,12 +367,8 @@ static void updateItems_SidebarWidget_(iSidebarWidget *d) { } case identities_SidebarMode: { /* Actions. */ { - checkIcon_LabelWidget(addChild_Widget( - d->actions, - iClob(new_LabelWidget(add_Icon " ${sidebar.action.ident.new}", "ident.new")))); - checkIcon_LabelWidget(addChild_Widget( - d->actions, - iClob(new_LabelWidget("${sidebar.action.ident.import}", "ident.import")))); + addActionButton_SidebarWidget_(d, add_Icon " ${sidebar.action.ident.new}", "ident.new", 0); + addActionButton_SidebarWidget_(d, "${sidebar.action.ident.import}", "ident.import", 0); } const iString *tabUrl = url_DocumentWidget(document_App()); isEmpty = iTrue; @@ -460,15 +464,16 @@ static void updateItems_SidebarWidget_(iSidebarWidget *d) { } // arrange_Widget(d->blank); } +#if 0 if (deviceType_App() != desktop_AppDeviceType) { /* Touch-friendly action buttons. */ iForEach(ObjectList, i, children_Widget(d->actions)) { if (isInstance_Object(i.object, &Class_LabelWidget)) { setPadding_Widget(i.object, 0, gap_UI, 0, gap_UI); - setFont_LabelWidget(i.object, defaultBig_FontId); } } } +#endif arrange_Widget(d->actions); arrange_Widget(as_Widget(d)); } @@ -561,6 +566,7 @@ void init_SidebarWidget(iSidebarWidget *d, enum iSidebarSide side) { d->mode = -1; d->feedsMode = all_FeedsMode; d->numUnreadEntries = 0; + d->buttonFont = uiLabel_FontId; d->itemFonts[0] = uiContent_FontId; d->itemFonts[1] = uiContentBold_FontId; #if defined (iPlatformAppleMobile) @@ -578,6 +584,7 @@ void init_SidebarWidget(iSidebarWidget *d, enum iSidebarSide side) { iZap(d->modeButtons); d->resizer = NULL; d->list = NULL; + d->actions = NULL; /* On a phone, the right sidebar is used exclusively for Identities. */ const iBool isPhone = deviceType_App() == phone_AppDeviceType; if (!isPhone || d->side == left_SideBarSide) { @@ -660,6 +667,7 @@ void deinit_SidebarWidget(iSidebarWidget *d) { } void setButtonFont_SidebarWidget(iSidebarWidget *d, int font) { + d->buttonFont = font; for (int i = 0; i < max_SidebarMode; i++) { if (d->modeButtons[i]) { setFont_LabelWidget(d->modeButtons[i], font); diff --git a/src/ui/widget.h b/src/ui/widget.h index dc79a22c..27295149 100644 --- a/src/ui/widget.h +++ b/src/ui/widget.h @@ -198,6 +198,7 @@ iLocalDef int height_Widget(const iAnyObject *d) { return 0; } iLocalDef iObjectList *children_Widget(iAnyObject *d) { + if (d == NULL) return NULL; iAssert(isInstance_Object(d, &Class_Widget)); return ((iWidget *) d)->children; } diff --git a/src/ui/window.c b/src/ui/window.c index 642bcba5..d00d19a7 100644 --- a/src/ui/window.c +++ b/src/ui/window.c @@ -151,8 +151,10 @@ static iBool handleRootCommands_(iWidget *root, const char *cmd) { else if (deviceType_App() == phone_AppDeviceType && equal_Command(cmd, "window.resized")) { /* Place the sidebar next to or under doctabs depending on orientation. */ iSidebarWidget *sidebar = findChild_Widget(root, "sidebar"); + iSidebarWidget *sidebar2 = findChild_Widget(root, "sidebar2"); removeChild_Widget(parent_Widget(sidebar), sidebar); setButtonFont_SidebarWidget(sidebar, isLandscape_App() ? uiLabel_FontId : uiLabelLarge_FontId); + setButtonFont_SidebarWidget(sidebar2, isLandscape_App() ? uiLabel_FontId : uiLabelLarge_FontId); // setBackgroundColor_Widget(findChild_Widget(as_Widget(sidebar), "buttons"), // isPortrait_App() ? uiBackgroundUnfocusedSelection_ColorId // : uiBackgroundSidebar_ColorId); -- cgit v1.2.3