summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJaakko Keränen <jaakko.keranen@iki.fi>2021-11-29 12:33:00 +0200
committerJaakko Keränen <jaakko.keranen@iki.fi>2021-11-29 12:33:00 +0200
commit7e6e4eb9deb80783e8757fd999819e308e098ab5 (patch)
treec53a55597c5d130af5912ea01bfab0dc80856171 /src
parent31a5b9499688341353b3946dca208adc67560d2e (diff)
Fixed issues with tab button labels
Fixed issue with very short text not being truncated at all. A short truncated label will now just show the icon, if one is set. The tab close buttons don't appear if the buttons are too small.
Diffstat (limited to 'src')
-rw-r--r--src/ui/documentwidget.c15
-rw-r--r--src/ui/text.c4
2 files changed, 16 insertions, 3 deletions
diff --git a/src/ui/documentwidget.c b/src/ui/documentwidget.c
index aac77572..746e03e0 100644
--- a/src/ui/documentwidget.c
+++ b/src/ui/documentwidget.c
@@ -1007,17 +1007,26 @@ static void updateWindowTitle_DocumentWidget_(const iDocumentWidget *d) {
1007 prependCStr_String(text, escape_Color(uiIcon_ColorId)); 1007 prependCStr_String(text, escape_Color(uiIcon_ColorId));
1008 } 1008 }
1009 const int width = measureRange_Text(font, range_String(text)).advance.x; 1009 const int width = measureRange_Text(font, range_String(text)).advance.x;
1010 if (width <= avail || 1010 const int ellipsisWidth = measure_Text(font, "...").advance.x;
1011 isEmpty_StringArray(title)) { 1011 setTextColor_LabelWidget(tabButton, none_ColorId);
1012 iWidget *tabCloseButton = child_Widget(as_Widget(tabButton), 0);
1013 setFlags_Widget(tabCloseButton, visibleOnParentHover_WidgetFlag,
1014 avail > width_Widget(tabCloseButton));
1015 if (width <= avail || isEmpty_StringArray(title)) {
1012 updateText_LabelWidget(tabButton, text); 1016 updateText_LabelWidget(tabButton, text);
1013 break; 1017 break;
1014 } 1018 }
1015 if (size_StringArray(title) == 1) { 1019 if (size_StringArray(title) == 1) {
1016 /* Just truncate to fit. */ 1020 /* Just truncate to fit. */
1021 if (siteIcon && avail <= 4 * ellipsisWidth) {
1022 updateText_LabelWidget(tabButton, collect_String(newUnicodeN_String(&siteIcon, 1)));
1023 setTextColor_LabelWidget(tabButton, uiIcon_ColorId);
1024 break;
1025 }
1017 const char *endPos; 1026 const char *endPos;
1018 tryAdvanceNoWrap_Text(font, 1027 tryAdvanceNoWrap_Text(font,
1019 range_String(text), 1028 range_String(text),
1020 avail - measure_Text(font, "...").advance.x, 1029 avail - ellipsisWidth,
1021 &endPos); 1030 &endPos);
1022 updateText_LabelWidget( 1031 updateText_LabelWidget(
1023 tabButton, 1032 tabButton,
diff --git a/src/ui/text.c b/src/ui/text.c
index 91ff137a..977cac9c 100644
--- a/src/ui/text.c
+++ b/src/ui/text.c
@@ -1871,6 +1871,10 @@ iInt2 tryAdvance_Text(int fontId, iRangecc text, int width, const char **endPos)
1871} 1871}
1872 1872
1873iInt2 tryAdvanceNoWrap_Text(int fontId, iRangecc text, int width, const char **endPos) { 1873iInt2 tryAdvanceNoWrap_Text(int fontId, iRangecc text, int width, const char **endPos) {
1874 if (width <= 1) {
1875 *endPos = text.start;
1876 return zero_I2();
1877 }
1874 /* "NoWrap" means words aren't wrapped; the line is broken at nearest character. */ 1878 /* "NoWrap" means words aren't wrapped; the line is broken at nearest character. */
1875 iWrapText wrap = { .mode = anyCharacter_WrapTextMode, 1879 iWrapText wrap = { .mode = anyCharacter_WrapTextMode,
1876 .text = text, 1880 .text = text,