[gnome-text-editor: 1/2] infobar: wrap text so it can fit narrow screens




commit bf66820ee7d5cb2cc57a3102b3fe44c7abe63031
Author: Arnaud Ferraris <arnaud ferraris collabora com>
Date:   Fri Jun 3 11:54:08 2022 +0200

    infobar: wrap text so it can fit narrow screens
    
    Currently, the infobar is the one element taking up the most horizontal
    space, making this application unusable on narrow screens such as mobile
    phones.
    
    Wrapping all the labels (including those of buttons with long labels)
    allows resizing the window to less than 360px under Phosh (where the
    window controls buttons are hidden), therefore allowing it to be used
    on mobile phones.

 src/editor-info-bar.c  | 21 +++++++++++++++++++++
 src/editor-info-bar.ui |  4 ++++
 2 files changed, 25 insertions(+)
---
diff --git a/src/editor-info-bar.c b/src/editor-info-bar.c
index 830d398..c0afd34 100644
--- a/src/editor-info-bar.c
+++ b/src/editor-info-bar.c
@@ -113,6 +113,20 @@ editor_info_bar_update (EditorInfoBar *self)
     }
 }
 
+static void
+editor_info_bar_wrap_button_label (GtkButton *button)
+{
+  GtkWidget *label;
+
+  g_assert (GTK_IS_BUTTON (button));
+
+  label = gtk_button_get_child (button);
+  g_assert (GTK_IS_LABEL (label));
+
+  gtk_label_set_wrap (GTK_LABEL (label), TRUE);
+  gtk_label_set_justify (GTK_LABEL (label), GTK_JUSTIFY_CENTER);
+}
+
 static void
 on_notify_cb (EditorInfoBar  *self,
               GParamSpec     *pspec,
@@ -266,6 +280,13 @@ editor_info_bar_init (EditorInfoBar *self)
 {
   gtk_widget_init_template (GTK_WIDGET (self));
 
+  /*
+   * Ensure buttons with long labels can wrap text and are
+   * center-justified, so the infobar can fit narrow screens.
+   */
+  editor_info_bar_wrap_button_label (self->access_try_admin);
+  editor_info_bar_wrap_button_label (self->discard);
+
   g_signal_connect_object (self->discard_infobar,
                            "response",
                            G_CALLBACK (on_response_cb),
diff --git a/src/editor-info-bar.ui b/src/editor-info-bar.ui
index e1f4f01..4283f4e 100644
--- a/src/editor-info-bar.ui
+++ b/src/editor-info-bar.ui
@@ -17,6 +17,7 @@
                   <object class="GtkLabel" id="access_title">
                     <property name="halign">start</property>
                     <property name="label" translatable="yes">Could Not Open File</property>
+                    <property name="wrap">True</property>
                     <attributes>
                       <attribute name="weight" value="bold"/>
                     </attributes>
@@ -26,6 +27,7 @@
                   <object class="GtkLabel" id="access_subtitle">
                     <property name="halign">start</property>
                     <property name="label" translatable="yes">You do not have permission to open the 
file.</property>
+                    <property name="wrap">True</property>
                   </object>
                 </child>
               </object>
@@ -59,6 +61,7 @@
                   <object class="GtkLabel" id="title">
                     <property name="halign">start</property>
                     <property name="label" translatable="yes">Document Restored</property>
+                    <property name="wrap">True</property>
                     <attributes>
                       <attribute name="weight" value="bold"/>
                     </attributes>
@@ -68,6 +71,7 @@
                   <object class="GtkLabel" id="subtitle">
                     <property name="halign">start</property>
                     <property name="label" translatable="yes">Unsaved document has been restored.</property>
+                    <property name="wrap">True</property>
                   </object>
                 </child>
               </object>


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]