summaryrefslogtreecommitdiff
path: root/src/ui
diff options
context:
space:
mode:
authorJaakko Keränen <jaakko.keranen@iki.fi>2020-08-09 11:38:45 +0300
committerJaakko Keränen <jaakko.keranen@iki.fi>2020-08-09 11:38:45 +0300
commit67b430feae483f44078dd6f5ff96771073e746db (patch)
tree8233d7f5321e17389f0d9bbc4d550b6dc88d552d /src/ui
parent3530d4127b840c63e1a15b38844bf13483cf9490 (diff)
Tab button labels fitted to available space
Diffstat (limited to 'src/ui')
-rw-r--r--src/ui/documentwidget.c49
-rw-r--r--src/ui/documentwidget.h3
-rw-r--r--src/ui/util.c7
-rw-r--r--src/ui/util.h1
-rw-r--r--src/ui/window.c10
5 files changed, 64 insertions, 6 deletions
diff --git a/src/ui/documentwidget.c b/src/ui/documentwidget.c
index 53eb06bd..c8daa2e2 100644
--- a/src/ui/documentwidget.c
+++ b/src/ui/documentwidget.c
@@ -297,9 +297,46 @@ static void updateWindowTitle_DocumentWidget_(const iDocumentWidget *d) {
297 if (isEmpty_StringArray(title)) { 297 if (isEmpty_StringArray(title)) {
298 pushBackCStr_StringArray(title, "Lagrange"); 298 pushBackCStr_StringArray(title, "Lagrange");
299 } 299 }
300 const iString *text = collect_String(joinCStr_StringArray(title, " \u2014 ")); 300 /* Take away parts if it doesn't fit. */
301 setTitle_Window(get_Window(), text); 301 iLabelWidget *tabButton = tabPageButton_Widget(findWidget_App("doctabs"), d);
302 setTabPageLabel_Widget(findWidget_App("doctabs"), d, text); 302 const int avail = bounds_Widget(as_Widget(tabButton)).size.x - 3 * gap_UI;
303 iBool setWindow = (document_App() == d);
304 for (;;) {
305 iString *text = collect_String(joinCStr_StringArray(title, " \u2014 "));
306 if (setWindow) {
307 /* Longest version for the window title, and omit the icon. */
308 setTitle_Window(get_Window(), text);
309 setWindow = iFalse;
310 }
311 const iChar siteIcon = siteIcon_GmDocument(d->doc);
312 if (siteIcon) {
313 if (!isEmpty_String(text)) {
314 prependCStr_String(text, " ");
315 }
316 prependChar_String(text, siteIcon);
317 }
318 const int width = advanceRange_Text(default_FontId, range_String(text)).x;
319 if (width <= avail ||
320 isEmpty_StringArray(title)) {
321 updateText_LabelWidget(tabButton, text);
322 break;
323 }
324 if (size_StringArray(title) == 1) {
325 /* Just truncate to fit. */
326 const char *endPos;
327 tryAdvanceNoWrap_Text(default_FontId,
328 range_String(text),
329 avail - advance_Text(default_FontId, "...").x,
330 &endPos);
331 updateText_LabelWidget(
332 tabButton,
333 collectNewFormat_String("%s...",
334 cstrCollect_String(newRange_String(
335 (iRangecc){ constBegin_String(text), endPos }))));
336 break;
337 }
338 remove_StringArray(title, size_StringArray(title) - 1);
339 }
303} 340}
304 341
305static void setSource_DocumentWidget_(iDocumentWidget *d, const iString *source) { 342static void setSource_DocumentWidget_(iDocumentWidget *d, const iString *source) {
@@ -446,6 +483,10 @@ iHistory *history_DocumentWidget(iDocumentWidget *d) {
446 return d->history; 483 return d->history;
447} 484}
448 485
486const iString *url_DocumentWidget(const iDocumentWidget *d) {
487 return d->url;
488}
489
449void setUrlFromCache_DocumentWidget(iDocumentWidget *d, const iString *url, iBool isFromCache) { 490void setUrlFromCache_DocumentWidget(iDocumentWidget *d, const iString *url, iBool isFromCache) {
450 if (cmpStringSc_String(d->url, url, &iCaseInsensitive)) { 491 if (cmpStringSc_String(d->url, url, &iCaseInsensitive)) {
451 set_String(d->url, url); 492 set_String(d->url, url);
@@ -710,12 +751,14 @@ static iBool handleCommand_DocumentWidget_(iDocumentWidget *d, const char *cmd)
710 } 751 }
711 } 752 }
712 refresh_Widget(w); 753 refresh_Widget(w);
754 updateWindowTitle_DocumentWidget_(d);
713 } 755 }
714 else if (equal_Command(cmd, "tabs.changed")) { 756 else if (equal_Command(cmd, "tabs.changed")) {
715 if (cmp_String(id_Widget(w), suffixPtr_Command(cmd, "id")) == 0) { 757 if (cmp_String(id_Widget(w), suffixPtr_Command(cmd, "id")) == 0) {
716 /* Set palette for our document. */ 758 /* Set palette for our document. */
717 updateTheme_DocumentWidget_(d); 759 updateTheme_DocumentWidget_(d);
718 } 760 }
761 updateWindowTitle_DocumentWidget_(d);
719 return iFalse; 762 return iFalse;
720 } 763 }
721 else if (equal_Command(cmd, "server.showcert")) { 764 else if (equal_Command(cmd, "server.showcert")) {
diff --git a/src/ui/documentwidget.h b/src/ui/documentwidget.h
index 5ce28f4e..38fcf8e3 100644
--- a/src/ui/documentwidget.h
+++ b/src/ui/documentwidget.h
@@ -13,4 +13,5 @@ void setUrl_DocumentWidget (iDocumentWidget *, const iString *url);
13void setUrlFromCache_DocumentWidget (iDocumentWidget *d, const iString *url, iBool isFromCache); 13void setUrlFromCache_DocumentWidget (iDocumentWidget *d, const iString *url, iBool isFromCache);
14void setInitialScroll_DocumentWidget (iDocumentWidget *, int scrollY); /* set after content received */ 14void setInitialScroll_DocumentWidget (iDocumentWidget *, int scrollY); /* set after content received */
15 15
16iBool isRequestOngoing_DocumentWidget (const iDocumentWidget *); 16const iString * url_DocumentWidget (const iDocumentWidget *);
17iBool isRequestOngoing_DocumentWidget (const iDocumentWidget *);
diff --git a/src/ui/util.c b/src/ui/util.c
index 40debd28..9ac1913d 100644
--- a/src/ui/util.c
+++ b/src/ui/util.c
@@ -317,7 +317,8 @@ static void addTabPage_Widget_(iWidget *tabs, enum iWidgetAddPos addPos, iWidget
317 findChild_Widget(tabs, "tabs.buttons"), 317 findChild_Widget(tabs, "tabs.buttons"),
318 iClob(new_LabelWidget(label, key, kmods, format_CStr("tabs.switch page:%p", page))), 318 iClob(new_LabelWidget(label, key, kmods, format_CStr("tabs.switch page:%p", page))),
319 addPos); 319 addPos);
320 setFlags_Widget(button, selected_WidgetFlag | expand_WidgetFlag, isSel); 320 setFlags_Widget(button, selected_WidgetFlag, isSel);
321 setFlags_Widget(button, expand_WidgetFlag, iTrue);
321 addChildPos_Widget(pages, page, addPos); 322 addChildPos_Widget(pages, page, addPos);
322 setFlags_Widget(page, hidden_WidgetFlag | disabled_WidgetFlag, !isSel); 323 setFlags_Widget(page, hidden_WidgetFlag | disabled_WidgetFlag, !isSel);
323} 324}
@@ -383,6 +384,10 @@ void showTabPage_Widget(iWidget *tabs, const iWidget *page) {
383 } 384 }
384} 385}
385 386
387iLabelWidget *tabPageButton_Widget(iWidget *tabs, const iAnyObject *page) {
388 return tabButtonForPage_Widget_(tabs, page);
389}
390
386void setTabPageLabel_Widget(iWidget *tabs, const iAnyObject *page, const iString *label) { 391void setTabPageLabel_Widget(iWidget *tabs, const iAnyObject *page, const iString *label) {
387 iLabelWidget *button = tabButtonForPage_Widget_(tabs, page); 392 iLabelWidget *button = tabButtonForPage_Widget_(tabs, page);
388 setText_LabelWidget(button, label); 393 setText_LabelWidget(button, label);
diff --git a/src/ui/util.h b/src/ui/util.h
index 6eeea11d..6e210422 100644
--- a/src/ui/util.h
+++ b/src/ui/util.h
@@ -98,6 +98,7 @@ iWidget * makeTabs_Widget (iWidget *parent);
98void appendTabPage_Widget (iWidget *tabs, iWidget *page, const char *label, int key, int kmods); 98void appendTabPage_Widget (iWidget *tabs, iWidget *page, const char *label, int key, int kmods);
99void prependTabPage_Widget (iWidget *tabs, iWidget *page, const char *label, int key, int kmods); 99void prependTabPage_Widget (iWidget *tabs, iWidget *page, const char *label, int key, int kmods);
100iWidget * tabPage_Widget (iWidget *tabs, size_t index); 100iWidget * tabPage_Widget (iWidget *tabs, size_t index);
101iLabelWidget *tabPageButton_Widget (iWidget *tabs, const iAnyObject *page);
101iWidget * removeTabPage_Widget (iWidget *tabs, size_t index); /* returns the page */ 102iWidget * removeTabPage_Widget (iWidget *tabs, size_t index); /* returns the page */
102void showTabPage_Widget (iWidget *tabs, const iWidget *page); 103void showTabPage_Widget (iWidget *tabs, const iWidget *page);
103void setTabPageLabel_Widget (iWidget *tabs, const iAnyObject *page, const iString *label); 104void setTabPageLabel_Widget (iWidget *tabs, const iAnyObject *page, const iString *label);
diff --git a/src/ui/window.c b/src/ui/window.c
index 1f05b80d..bc690426 100644
--- a/src/ui/window.c
+++ b/src/ui/window.c
@@ -133,6 +133,13 @@ static iBool handleNavBarCommands_(iWidget *navBar, const char *cmd) {
133 } 133 }
134 } 134 }
135 } 135 }
136 else if (equal_Command(cmd, "tabs.changed")) {
137 /* Update navbar according to the current tab. */
138 iDocumentWidget *doc = document_App();
139 setText_InputWidget(findWidget_App("url"), url_DocumentWidget(doc));
140 updateTextCStr_LabelWidget(findChild_Widget(navBar, "reload"),
141 isRequestOngoing_DocumentWidget(doc) ? stopCStr_ : reloadCStr_);
142 }
136 else if (equal_Command(cmd, "navigate.reload")) { 143 else if (equal_Command(cmd, "navigate.reload")) {
137 iDocumentWidget *doc = document_Command(cmd); 144 iDocumentWidget *doc = document_Command(cmd);
138 if (isRequestOngoing_DocumentWidget(doc)) { 145 if (isRequestOngoing_DocumentWidget(doc)) {
@@ -409,7 +416,8 @@ static void setupUserInterface_Window(iWindow *d) {
409 } 416 }
410#endif 417#endif
411 /* Glboal keyboard shortcuts. */ { 418 /* Glboal keyboard shortcuts. */ {
412 // addAction_Widget(d->root, SDLK_LEFTBRACKET, KMOD_SHIFT | KMOD_PRIMARY, "tabs.prev"); 419 addAction_Widget(d->root, SDLK_LEFTBRACKET, KMOD_SHIFT | KMOD_PRIMARY, "tabs.prev");
420 addAction_Widget(d->root, SDLK_RIGHTBRACKET, KMOD_SHIFT | KMOD_PRIMARY, "tabs.next");
413 addAction_Widget(d->root, 'l', KMOD_PRIMARY, "focus.set id:url"); 421 addAction_Widget(d->root, 'l', KMOD_PRIMARY, "focus.set id:url");
414 addAction_Widget(d->root, 'f', KMOD_PRIMARY, "focus.set id:find.input"); 422 addAction_Widget(d->root, 'f', KMOD_PRIMARY, "focus.set id:find.input");
415 } 423 }