diff options
author | Jaakko Keränen <jaakko.keranen@iki.fi> | 2020-08-10 06:53:55 +0300 |
---|---|---|
committer | Jaakko Keränen <jaakko.keranen@iki.fi> | 2020-08-10 06:53:55 +0300 |
commit | ef30731ff7ecc0687ebf4b85db89dc83a4748266 (patch) | |
tree | 6d031da3f2c8e342cf209980827fe92b36079ca0 /src | |
parent | cfcd6bd672829edfbb325e3d264570c034ccc0f1 (diff) |
Tab bar is hidden when there is a single tab
Needed some fixes in the widget arrangement behavior.
Diffstat (limited to 'src')
-rw-r--r-- | src/app.c | 3 | ||||
-rw-r--r-- | src/ui/util.c | 22 | ||||
-rw-r--r-- | src/ui/widget.c | 18 | ||||
-rw-r--r-- | src/ui/widget.h | 62 | ||||
-rw-r--r-- | src/ui/window.c | 43 |
5 files changed, 92 insertions, 56 deletions
@@ -394,6 +394,7 @@ iBool handleCommand_App(const char *cmd) { | |||
394 | } | 394 | } |
395 | else if (equal_Command(cmd, "tabs.new")) { | 395 | else if (equal_Command(cmd, "tabs.new")) { |
396 | iWidget *tabs = findWidget_App("doctabs"); | 396 | iWidget *tabs = findWidget_App("doctabs"); |
397 | setFlags_Widget(tabs, hidden_WidgetFlag, iFalse); | ||
397 | iWidget *newTabButton = findChild_Widget(tabs, "newtab"); | 398 | iWidget *newTabButton = findChild_Widget(tabs, "newtab"); |
398 | removeChild_Widget(newTabButton->parent, newTabButton); | 399 | removeChild_Widget(newTabButton->parent, newTabButton); |
399 | iDocumentWidget *newDoc; | 400 | iDocumentWidget *newDoc; |
@@ -410,7 +411,7 @@ iBool handleCommand_App(const char *cmd) { | |||
410 | postCommandf_App("tabs.switch page:%p", newDoc); | 411 | postCommandf_App("tabs.switch page:%p", newDoc); |
411 | if (!isDuplicate) { | 412 | if (!isDuplicate) { |
412 | postCommand_App("navigate.home"); | 413 | postCommand_App("navigate.home"); |
413 | } | 414 | } |
414 | arrange_Widget(tabs); | 415 | arrange_Widget(tabs); |
415 | refresh_Widget(tabs); | 416 | refresh_Widget(tabs); |
416 | return iTrue; | 417 | return iTrue; |
diff --git a/src/ui/util.c b/src/ui/util.c index 5868e9d7..94528817 100644 --- a/src/ui/util.c +++ b/src/ui/util.c | |||
@@ -297,10 +297,9 @@ static iBool tabSwitcher_(iWidget *tabs, const char *cmd) { | |||
297 | iWidget *makeTabs_Widget(iWidget *parent) { | 297 | iWidget *makeTabs_Widget(iWidget *parent) { |
298 | iWidget *tabs = makeVDiv_Widget(); | 298 | iWidget *tabs = makeVDiv_Widget(); |
299 | iWidget *buttons = addChild_Widget(tabs, iClob(new_Widget())); | 299 | iWidget *buttons = addChild_Widget(tabs, iClob(new_Widget())); |
300 | buttons->rect.size.y = 2 * gap_UI + lineHeight_Text(default_FontId); | ||
301 | setFlags_Widget(buttons, | 300 | setFlags_Widget(buttons, |
302 | resizeChildren_WidgetFlag | arrangeHorizontal_WidgetFlag | | 301 | resizeWidthOfChildren_WidgetFlag | arrangeHorizontal_WidgetFlag | |
303 | fixedHeight_WidgetFlag, | 302 | arrangeHeight_WidgetFlag, |
304 | iTrue); | 303 | iTrue); |
305 | setId_Widget(buttons, "tabs.buttons"); | 304 | setId_Widget(buttons, "tabs.buttons"); |
306 | iWidget *pages = addChildFlags_Widget( | 305 | iWidget *pages = addChildFlags_Widget( |
@@ -313,12 +312,14 @@ iWidget *makeTabs_Widget(iWidget *parent) { | |||
313 | 312 | ||
314 | static void addTabPage_Widget_(iWidget *tabs, enum iWidgetAddPos addPos, iWidget *page, | 313 | static void addTabPage_Widget_(iWidget *tabs, enum iWidgetAddPos addPos, iWidget *page, |
315 | const char *label, int key, int kmods) { | 314 | const char *label, int key, int kmods) { |
316 | iWidget * pages = findChild_Widget(tabs, "tabs.pages"); | 315 | iWidget * pages = findChild_Widget(tabs, "tabs.pages"); |
317 | const iBool isSel = childCount_Widget(pages) == 0; | 316 | const iBool isSel = childCount_Widget(pages) == 0; |
318 | iWidget * button = addChildPos_Widget( | 317 | iWidget * buttons = findChild_Widget(tabs, "tabs.buttons"); |
319 | findChild_Widget(tabs, "tabs.buttons"), | 318 | iWidget * button = addChildPos_Widget( |
319 | buttons, | ||
320 | iClob(new_LabelWidget(label, key, kmods, format_CStr("tabs.switch page:%p", page))), | 320 | iClob(new_LabelWidget(label, key, kmods, format_CStr("tabs.switch page:%p", page))), |
321 | addPos); | 321 | addPos); |
322 | setFlags_Widget(buttons, hidden_WidgetFlag, iFalse); | ||
322 | setFlags_Widget(button, selected_WidgetFlag, isSel); | 323 | setFlags_Widget(button, selected_WidgetFlag, isSel); |
323 | setFlags_Widget(button, commandOnClick_WidgetFlag | expand_WidgetFlag, iTrue); | 324 | setFlags_Widget(button, commandOnClick_WidgetFlag | expand_WidgetFlag, iTrue); |
324 | addChildPos_Widget(pages, page, addPos); | 325 | addChildPos_Widget(pages, page, addPos); |
@@ -340,13 +341,16 @@ iWidget *tabPage_Widget(iWidget *tabs, size_t index) { | |||
340 | 341 | ||
341 | iWidget *removeTabPage_Widget(iWidget *tabs, size_t index) { | 342 | iWidget *removeTabPage_Widget(iWidget *tabs, size_t index) { |
342 | iWidget *buttons = findChild_Widget(tabs, "tabs.buttons"); | 343 | iWidget *buttons = findChild_Widget(tabs, "tabs.buttons"); |
343 | iWidget *pages = findChild_Widget(tabs, "tabs.pages"); | 344 | iWidget *pages = findChild_Widget(tabs, "tabs.pages"); |
344 | iWidget *button = removeChild_Widget(buttons, child_Widget(buttons, index)); | 345 | iWidget *button = removeChild_Widget(buttons, child_Widget(buttons, index)); |
345 | iRelease(button); | 346 | iRelease(button); |
346 | iWidget *page = child_Widget(pages, index); | 347 | iWidget *page = child_Widget(pages, index); |
347 | ref_Object(page); | 348 | ref_Object(page); |
348 | setFlags_Widget(page, hidden_WidgetFlag | disabled_WidgetFlag, iFalse); | 349 | setFlags_Widget(page, hidden_WidgetFlag | disabled_WidgetFlag, iFalse); |
349 | removeChild_Widget(pages, page); | 350 | removeChild_Widget(pages, page); |
351 | if (tabCount_Widget(tabs) <= 1 && flags_Widget(buttons) & collapse_WidgetFlag) { | ||
352 | setFlags_Widget(buttons, hidden_WidgetFlag, iTrue); | ||
353 | } | ||
350 | return page; | 354 | return page; |
351 | } | 355 | } |
352 | 356 | ||
diff --git a/src/ui/widget.c b/src/ui/widget.c index 51841d64..3e34c285 100644 --- a/src/ui/widget.c +++ b/src/ui/widget.c | |||
@@ -186,6 +186,8 @@ void arrange_Widget(iWidget *d) { | |||
186 | /* Resize children to fill the parent widget. */ | 186 | /* Resize children to fill the parent widget. */ |
187 | const size_t childCount = size_ObjectList(d->children); | 187 | const size_t childCount = size_ObjectList(d->children); |
188 | if (d->flags & resizeChildren_WidgetFlag) { | 188 | if (d->flags & resizeChildren_WidgetFlag) { |
189 | const iInt2 dirs = init_I2((d->flags & resizeWidthOfChildren_WidgetFlag) != 0, | ||
190 | (d->flags & resizeHeightOfChildren_WidgetFlag) != 0); | ||
189 | /* Collapse hidden children. */ | 191 | /* Collapse hidden children. */ |
190 | iForEach(ObjectList, c, d->children) { | 192 | iForEach(ObjectList, c, d->children) { |
191 | iWidget *child = as_Widget(c.object); | 193 | iWidget *child = as_Widget(c.object); |
@@ -221,21 +223,21 @@ void arrange_Widget(iWidget *d) { | |||
221 | if (isCollapsed_Widget_(child)) continue; | 223 | if (isCollapsed_Widget_(child)) continue; |
222 | if (child->flags & expand_WidgetFlag) { | 224 | if (child->flags & expand_WidgetFlag) { |
223 | if (d->flags & arrangeHorizontal_WidgetFlag) { | 225 | if (d->flags & arrangeHorizontal_WidgetFlag) { |
224 | setWidth_Widget_(child, avail.x); | 226 | if (dirs.x) setWidth_Widget_(child, avail.x); |
225 | setHeight_Widget_(child, d->rect.size.y); | 227 | if (dirs.y) setHeight_Widget_(child, d->rect.size.y); |
226 | } | 228 | } |
227 | else if (d->flags & arrangeVertical_WidgetFlag) { | 229 | else if (d->flags & arrangeVertical_WidgetFlag) { |
228 | setWidth_Widget_(child, d->rect.size.x); | 230 | if (dirs.x) setWidth_Widget_(child, d->rect.size.x); |
229 | setHeight_Widget_(child, avail.y); | 231 | if (dirs.y) setHeight_Widget_(child, avail.y); |
230 | } | 232 | } |
231 | } | 233 | } |
232 | else { | 234 | else { |
233 | /* Fill the off axis, though. */ | 235 | /* Fill the off axis, though. */ |
234 | if (d->flags & arrangeHorizontal_WidgetFlag) { | 236 | if (d->flags & arrangeHorizontal_WidgetFlag) { |
235 | setHeight_Widget_(child, d->rect.size.y); | 237 | if (dirs.y) setHeight_Widget_(child, d->rect.size.y); |
236 | } | 238 | } |
237 | else if (d->flags & arrangeVertical_WidgetFlag) { | 239 | else if (d->flags & arrangeVertical_WidgetFlag) { |
238 | setWidth_Widget_(child, d->rect.size.x); | 240 | if (dirs.x) setWidth_Widget_(child, d->rect.size.x); |
239 | } | 241 | } |
240 | } | 242 | } |
241 | } | 243 | } |
@@ -252,8 +254,8 @@ void arrange_Widget(iWidget *d) { | |||
252 | iForEach(ObjectList, i, d->children) { | 254 | iForEach(ObjectList, i, d->children) { |
253 | iWidget *child = as_Widget(i.object); | 255 | iWidget *child = as_Widget(i.object); |
254 | if (!isCollapsed_Widget_(child)) { | 256 | if (!isCollapsed_Widget_(child)) { |
255 | setWidth_Widget_(child, childSize.x); | 257 | if (dirs.x) setWidth_Widget_(child, childSize.x); |
256 | setHeight_Widget_(child, childSize.y); | 258 | if (dirs.y) setHeight_Widget_(child, childSize.y); |
257 | } | 259 | } |
258 | } | 260 | } |
259 | } | 261 | } |
diff --git a/src/ui/widget.h b/src/ui/widget.h index 1cea7147..bf6489a0 100644 --- a/src/ui/widget.h +++ b/src/ui/widget.h | |||
@@ -22,35 +22,39 @@ iBeginDeclareClass(Widget) | |||
22 | iEndDeclareClass(Widget) | 22 | iEndDeclareClass(Widget) |
23 | 23 | ||
24 | enum iWidgetFlag { | 24 | enum iWidgetFlag { |
25 | hidden_WidgetFlag = iBit(1), | 25 | hidden_WidgetFlag = iBit(1), |
26 | disabled_WidgetFlag = iBit(2), | 26 | disabled_WidgetFlag = iBit(2), |
27 | hover_WidgetFlag = iBit(3), /* eligible for mouse hover */ | 27 | hover_WidgetFlag = iBit(3), /* eligible for mouse hover */ |
28 | selected_WidgetFlag = iBit(4), | 28 | selected_WidgetFlag = iBit(4), |
29 | pressed_WidgetFlag = iBit(5), | 29 | pressed_WidgetFlag = iBit(5), |
30 | alignLeft_WidgetFlag = iBit(6), | 30 | alignLeft_WidgetFlag = iBit(6), |
31 | alignRight_WidgetFlag = iBit(7), | 31 | alignRight_WidgetFlag = iBit(7), |
32 | frameless_WidgetFlag = iBit(8), | 32 | frameless_WidgetFlag = iBit(8), |
33 | commandOnClick_WidgetFlag = iBit(9), | 33 | commandOnClick_WidgetFlag = iBit(9), |
34 | drawKey_WidgetFlag = iBit(10), | 34 | drawKey_WidgetFlag = iBit(10), |
35 | focusable_WidgetFlag = iBit(11), | 35 | focusable_WidgetFlag = iBit(11), |
36 | tight_WidgetFlag = iBit(31), /* smaller padding */ | 36 | tight_WidgetFlag = iBit(12), /* smaller padding */ |
37 | keepOnTop_WidgetFlag = iBit(12), /* gets events first; drawn last */ | 37 | keepOnTop_WidgetFlag = iBit(13), /* gets events first; drawn last */ |
38 | arrangeHorizontal_WidgetFlag = iBit(17), /* arrange children horizontally */ | 38 | /* arrange behavior */ |
39 | arrangeVertical_WidgetFlag = iBit(18), /* arrange children vertically */ | 39 | arrangeHorizontal_WidgetFlag = iBit(17), /* arrange children horizontally */ |
40 | arrangeWidth_WidgetFlag = iBit(19), /* area of children becomes parent size */ | 40 | arrangeVertical_WidgetFlag = iBit(18), /* arrange children vertically */ |
41 | arrangeHeight_WidgetFlag = iBit(20), /* area of children becomes parent size */ | 41 | arrangeWidth_WidgetFlag = iBit(19), /* area of children becomes parent size */ |
42 | arrangeSize_WidgetFlag = arrangeWidth_WidgetFlag | arrangeHeight_WidgetFlag, | 42 | arrangeHeight_WidgetFlag = iBit(20), /* area of children becomes parent size */ |
43 | resizeChildren_WidgetFlag = iBit(21), /* resize children to fill parent size */ | 43 | resizeWidthOfChildren_WidgetFlag = iBit(21), |
44 | expand_WidgetFlag = iBit(22), | 44 | resizeHeightOfChildren_WidgetFlag = iBit(22), |
45 | fixedWidth_WidgetFlag = iBit(23), | 45 | expand_WidgetFlag = iBit(23), |
46 | fixedHeight_WidgetFlag = iBit(24), | 46 | fixedWidth_WidgetFlag = iBit(24), |
47 | fixedSize_WidgetFlag = fixedWidth_WidgetFlag | fixedHeight_WidgetFlag, | 47 | fixedHeight_WidgetFlag = iBit(25), |
48 | resizeChildrenToWidestChild_WidgetFlag = iBit(25), | 48 | resizeChildrenToWidestChild_WidgetFlag = iBit(26), |
49 | resizeToParentWidth_WidgetFlag = iBit(26), | 49 | resizeToParentWidth_WidgetFlag = iBit(27), |
50 | resizeToParentHeight_WidgetFlag = iBit(27), | 50 | resizeToParentHeight_WidgetFlag = iBit(28), |
51 | moveToParentRightEdge_WidgetFlag = iBit(28), | 51 | moveToParentRightEdge_WidgetFlag = iBit(29), |
52 | collapse_WidgetFlag = iBit(29), /* when hidden, arrange size to zero */ | 52 | collapse_WidgetFlag = iBit(30), /* when hidden, arrange size to zero */ |
53 | wasCollapsed_WidgetFlag = iBit(30), | 53 | wasCollapsed_WidgetFlag = iBit(31), |
54 | /* combinations */ | ||
55 | arrangeSize_WidgetFlag = arrangeWidth_WidgetFlag | arrangeHeight_WidgetFlag, | ||
56 | resizeChildren_WidgetFlag = resizeWidthOfChildren_WidgetFlag | resizeHeightOfChildren_WidgetFlag, | ||
57 | fixedSize_WidgetFlag = fixedWidth_WidgetFlag | fixedHeight_WidgetFlag, | ||
54 | }; | 58 | }; |
55 | 59 | ||
56 | enum iWidgetAddPos { | 60 | enum iWidgetAddPos { |
diff --git a/src/ui/window.c b/src/ui/window.c index 296b8d05..e5050308 100644 --- a/src/ui/window.c +++ b/src/ui/window.c | |||
@@ -61,11 +61,28 @@ static iBool handleRootCommands_(iWidget *root, const char *cmd) { | |||
61 | return iFalse; | 61 | return iFalse; |
62 | } | 62 | } |
63 | 63 | ||
64 | static const iMenuItem fileMenuItems[] = { | ||
65 | #if !defined (iPlatformApple) | 64 | #if !defined (iPlatformApple) |
65 | # define iHaveNativeMenus | ||
66 | #endif | ||
67 | |||
68 | #if !defined (iHaveNativeMenus) | ||
69 | static const iMenuItem navMenuItems[] = { | ||
70 | { "New Tab", 't', KMOD_PRIMARY, "tabs.new" }, | ||
71 | { "Open Location...", SDLK_l, KMOD_PRIMARY, "focus.set id:url" }, | ||
72 | { "---", 0, 0, NULL }, | ||
73 | { "Preferences...", SDLK_COMMA, KMOD_PRIMARY, "preferences" }, | ||
74 | { "---", 0, 0, NULL }, | ||
66 | { "Quit Lagrange", 'q', KMOD_PRIMARY, "quit" } | 75 | { "Quit Lagrange", 'q', KMOD_PRIMARY, "quit" } |
76 | }; | ||
67 | #endif | 77 | #endif |
78 | |||
79 | #if defined (iHaveNativeMenus) | ||
80 | /* Using native menus. */ | ||
81 | static const iMenuItem fileMenuItems[] = { | ||
82 | { "New Tab", SDLK_t, KMOD_PRIMARY, "tabs.new" }, | ||
83 | { "Open Location...", SDLK_l, KMOD_PRIMARY, "focus.set id:url" }, | ||
68 | }; | 84 | }; |
85 | #endif | ||
69 | 86 | ||
70 | static const iMenuItem editMenuItems[] = { | 87 | static const iMenuItem editMenuItems[] = { |
71 | #if !defined (iPlatformApple) | 88 | #if !defined (iPlatformApple) |
@@ -136,9 +153,11 @@ static iBool handleNavBarCommands_(iWidget *navBar, const char *cmd) { | |||
136 | else if (equal_Command(cmd, "tabs.changed")) { | 153 | else if (equal_Command(cmd, "tabs.changed")) { |
137 | /* Update navbar according to the current tab. */ | 154 | /* Update navbar according to the current tab. */ |
138 | iDocumentWidget *doc = document_App(); | 155 | iDocumentWidget *doc = document_App(); |
139 | setText_InputWidget(findWidget_App("url"), url_DocumentWidget(doc)); | 156 | if (doc) { |
140 | updateTextCStr_LabelWidget(findChild_Widget(navBar, "reload"), | 157 | setText_InputWidget(findWidget_App("url"), url_DocumentWidget(doc)); |
141 | isRequestOngoing_DocumentWidget(doc) ? stopCStr_ : reloadCStr_); | 158 | updateTextCStr_LabelWidget(findChild_Widget(navBar, "reload"), |
159 | isRequestOngoing_DocumentWidget(doc) ? stopCStr_ : reloadCStr_); | ||
160 | } | ||
142 | } | 161 | } |
143 | else if (equal_Command(cmd, "mouse.clicked")) { | 162 | else if (equal_Command(cmd, "mouse.clicked")) { |
144 | iWidget *widget = pointer_Command(cmd); | 163 | iWidget *widget = pointer_Command(cmd); |
@@ -241,10 +260,14 @@ static void setupUserInterface_Window(iWindow *d) { | |||
241 | "reload"); | 260 | "reload"); |
242 | addChild_Widget(navBar, iClob(newIcon_LabelWidget("\U0001f464", 0, 0, "cert.client"))); | 261 | addChild_Widget(navBar, iClob(newIcon_LabelWidget("\U0001f464", 0, 0, "cert.client"))); |
243 | 262 | ||
244 | iLabelWidget *fileMenu = | 263 | #if !defined (iHaveNativeMenus) |
245 | makeMenuButton_LabelWidget("\U0001d362", fileMenuItems, iElemCount(fileMenuItems)); | 264 | iLabelWidget *navMenu = |
246 | setAlignVisually_LabelWidget(fileMenu, iTrue); | 265 | makeMenuButton_LabelWidget("\U0001d362", navMenuItems, iElemCount(navMenuItems)); |
247 | addChild_Widget(navBar, iClob(fileMenu)); | 266 | setAlignVisually_LabelWidget(navMenu, iTrue); |
267 | addChild_Widget(navBar, iClob(navMenu)); | ||
268 | #else | ||
269 | insertMenuItems_MacOS("File", fileMenuItems, iElemCount(fileMenuItems)); | ||
270 | #endif | ||
248 | } | 271 | } |
249 | /* Tab bar. */ { | 272 | /* Tab bar. */ { |
250 | iWidget *tabBar = makeTabs_Widget(div); | 273 | iWidget *tabBar = makeTabs_Widget(div); |
@@ -252,8 +275,10 @@ static void setupUserInterface_Window(iWindow *d) { | |||
252 | setFlags_Widget(tabBar, expand_WidgetFlag, iTrue); | 275 | setFlags_Widget(tabBar, expand_WidgetFlag, iTrue); |
253 | setBackgroundColor_Widget(tabBar, gray25_ColorId); | 276 | setBackgroundColor_Widget(tabBar, gray25_ColorId); |
254 | appendTabPage_Widget(tabBar, iClob(new_DocumentWidget()), "Document", '1', KMOD_PRIMARY); | 277 | appendTabPage_Widget(tabBar, iClob(new_DocumentWidget()), "Document", '1', KMOD_PRIMARY); |
278 | iWidget *buttons = findChild_Widget(tabBar, "tabs.buttons"); | ||
279 | setFlags_Widget(buttons, collapse_WidgetFlag | hidden_WidgetFlag, iTrue); | ||
255 | setId_Widget( | 280 | setId_Widget( |
256 | addChild_Widget(findChild_Widget(tabBar, "tabs.buttons"), | 281 | addChild_Widget(buttons, |
257 | iClob(newIcon_LabelWidget("\u2795", 't', KMOD_PRIMARY, "tabs.new"))), | 282 | iClob(newIcon_LabelWidget("\u2795", 't', KMOD_PRIMARY, "tabs.new"))), |
258 | "newtab"); | 283 | "newtab"); |
259 | } | 284 | } |