[nautilus/gtk4-preparation-trunk: 24/84] pathbar: Set a minimum ellipsized width on labels
- From: António Fernandes <antoniof src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [nautilus/gtk4-preparation-trunk: 24/84] pathbar: Set a minimum ellipsized width on labels
- Date: Thu, 23 Dec 2021 23:08:37 +0000 (UTC)
commit 215a7aa95f9ee3ae548bbb6f4fafcef591edfefb
Author: António Fernandes <antoniof gnome org>
Date: Fri Nov 26 13:43:12 2021 +0000
pathbar: Set a minimum ellipsized width on labels
Such that they don't become single a ellipsis before overflowing.
src/nautilus-pathbar.c | 33 ++++++++++++++++++++++++++++++++-
1 file changed, 32 insertions(+), 1 deletion(-)
---
diff --git a/src/nautilus-pathbar.c b/src/nautilus-pathbar.c
index 3d9637887..8b5f095af 100644
--- a/src/nautilus-pathbar.c
+++ b/src/nautilus-pathbar.c
@@ -59,6 +59,8 @@ typedef enum
static guint path_bar_signals[LAST_SIGNAL] = { 0 };
+#define NAUTILUS_PATH_BAR_BUTTON_ELLISPIZE_MINIMUM_CHARS 7
+
typedef struct
{
GtkWidget *button;
@@ -808,11 +810,41 @@ nautilus_path_bar_update_button_appearance (ButtonData *button_data,
gboolean current_dir)
{
const gchar *dir_name = get_dir_name (button_data);
+ gint min_chars = NAUTILUS_PATH_BAR_BUTTON_ELLISPIZE_MINIMUM_CHARS;
GIcon *icon;
if (button_data->label != NULL)
{
gtk_label_set_text (GTK_LABEL (button_data->label), dir_name);
+
+ if (current_dir)
+ {
+ /* We want to avoid ellipsizing the current directory name, but
+ * still need to set a limit. */
+ min_chars = 4 * min_chars;
+ }
+
+ /* Labels can ellipsize until they become a single ellipsis character.
+ * We don't want that, so we must set a minimum.
+ *
+ * However, for labels shorter than the minimum, setting this minimum
+ * width would make them unnecessarily wide. In that case, just make it
+ * not ellipsize instead.
+ *
+ * Although th minimum width is set in number of characters, it may be
+ * wider than a label with that number of characters, due to variable
+ * width fonts. Compensate for this with a tolerance of +2 characters.
+ */
+ if (g_utf8_strlen (dir_name, -1) >= min_chars + 2)
+ {
+ gtk_label_set_width_chars (GTK_LABEL (button_data->label), min_chars);
+ gtk_label_set_ellipsize (GTK_LABEL (button_data->label), PANGO_ELLIPSIZE_MIDDLE);
+ }
+ else
+ {
+ gtk_label_set_width_chars (GTK_LABEL (button_data->label), -1);
+ gtk_label_set_ellipsize (GTK_LABEL (button_data->label), PANGO_ELLIPSIZE_NONE);
+ }
}
icon = get_gicon (button_data);
@@ -1116,7 +1148,6 @@ make_button_data (NautilusPathBar *self,
if (button_data->label != NULL)
{
- gtk_label_set_ellipsize (GTK_LABEL (button_data->label), PANGO_ELLIPSIZE_MIDDLE);
gtk_label_set_single_line_mode (GTK_LABEL (button_data->label), TRUE);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]