[goffice] GOFontSel: improve sizing a bit.
- From: Morten Welinder <mortenw src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [goffice] GOFontSel: improve sizing a bit.
- Date: Fri, 20 Apr 2018 00:55:53 +0000 (UTC)
commit f50d4311c1a0bf6606234a9bf6f3a90cf25f8441
Author: Morten Welinder <terra gnome org>
Date: Thu Apr 19 20:55:06 2018 -0400
GOFontSel: improve sizing a bit.
ChangeLog | 7 +++++
NEWS | 1 +
goffice/gtk/go-color-palette.c | 6 ++--
goffice/gtk/go-color-selector.c | 22 +++++++----------
goffice/gtk/go-font-sel.c | 38 +++++++++++++++++++++++++++---
goffice/gtk/go-font-sel.ui | 49 ++++++++-------------------------------
goffice/gtk/go-optionmenu.c | 12 +++++++++
goffice/gtk/go-optionmenu.h | 1 +
8 files changed, 77 insertions(+), 59 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index dddc06d..4e7de01 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2018-04-19 Morten Welinder <terra gnome org>
+
+ * goffice/gtk/go-font-sel.c (gfs_screen_changed): Set a minimum
+ size for the family name picker so it's wide enough for 95% of the
+ possible values. (That leaves room for 5% of families with crazy
+ names, just in case.)
+
2018-04-18 Morten Welinder <terra gnome org>
* goffice/app/go-doc.c (go_doc_finalize): Plug leak.
diff --git a/NEWS b/NEWS
index 7619b45..1cc993a 100644
--- a/NEWS
+++ b/NEWS
@@ -8,6 +8,7 @@ Morten:
* Store last-known modtime for GODoc.
* Option menus: handle markup for labels.
* Introspection fixes
+ * Improve font selector sizing a bit.
--------------------------------------------------------------------------
goffice 0.10.39:
diff --git a/goffice/gtk/go-color-palette.c b/goffice/gtk/go-color-palette.c
index 4549ab8..3b6cab6 100644
--- a/goffice/gtk/go-color-palette.c
+++ b/goffice/gtk/go-color-palette.c
@@ -475,9 +475,9 @@ go_color_palette_set_group (GOColorPalette *p, GOColorGroup *cg)
static GtkWidget *
go_color_palette_setup (GOColorPalette *pal,
- char const *no_color_label,
- int cols, int rows,
- GONamedColor const *color_names)
+ char const *no_color_label,
+ int cols, int rows,
+ GONamedColor const *color_names)
{
GtkWidget *w, *grid;
int pos, row, col = 0;
diff --git a/goffice/gtk/go-color-selector.c b/goffice/gtk/go-color-selector.c
index 36efd24..10553ed 100644
--- a/goffice/gtk/go-color-selector.c
+++ b/goffice/gtk/go-color-selector.c
@@ -353,13 +353,12 @@ go_color_selector_new (GOColor initial_color,
/**
* go_color_selector_set_color:
- * @selector: a color selector
- * @color: a color
+ * @selector: #GOColorSelector to change
+ * @color: a #GOColor
*
- * Sets current selection to @color. An "activate" signal will be emited.
- * Selector has to be a selector created via @go_color_selector_new.
+ * Sets current selection to @color. An "activate" signal will be emitted.
*
- * Returns: TRUE if selection changed.
+ * Returns: %TRUE if selection changed.
**/
gboolean
go_color_selector_set_color (GOSelector *selector, GOColor color)
@@ -381,13 +380,10 @@ go_color_selector_set_color (GOSelector *selector, GOColor color)
/**
* go_color_selector_get_color:
* @selector: a #GOSelector
- * @is_auto: non-NULL result storage
+ * @is_auto: (out) (optional): %TRUE if the current selection was set
+ * by clicking on automatic palette item.
*
- * Retrieves current color selection of a #GOSelector
- * created via @go_color_selector_new. @is_auto will be set to
- * TRUE if current selection was set by clicking on automatic palette item.
- *
- * Returns: current color selection.
+ * Returns: current color selection of @selector.
**/
GOColor
go_color_selector_get_color (GOSelector *selector, gboolean *is_auto)
@@ -414,9 +410,9 @@ go_color_selector_get_color (GOSelector *selector, gboolean *is_auto)
/**
* go_color_selector_set_allow_alpha:
* @selector: #GOColorSelector
- * @allow_alpha: boolean
+ * @allow_alpha: If %TRUE, the selector will have an alpha channel.
*
- * Should the custom colour selector allow the use of opacity.
+ * Seta whether the custom colour selector should allow the use of opacity.
**/
void
go_color_selector_set_allow_alpha (GOSelector *selector, gboolean allow_alpha)
diff --git a/goffice/gtk/go-font-sel.c b/goffice/gtk/go-font-sel.c
index d3440db..fa315cb 100644
--- a/goffice/gtk/go-font-sel.c
+++ b/goffice/gtk/go-font-sel.c
@@ -622,6 +622,14 @@ reload_families (GOFontSel *gfs)
}
#undef ADD_OBSERVED
+static int
+by_integer (gconstpointer a_, gconstpointer b_)
+{
+ int a = *(int *)a_;
+ int b = *(int *)b_;
+ return (a < b ? -1 : (a == b ? 0 : +1));
+}
+
static void
gfs_screen_changed (GtkWidget *w, GdkScreen *previous_screen)
{
@@ -629,6 +637,12 @@ gfs_screen_changed (GtkWidget *w, GdkScreen *previous_screen)
PangoFontDescription *desc;
GdkScreen *screen;
GOFontSel *gfs = GO_FONT_SEL (w);
+ PangoContext *pctxt = gtk_widget_get_pango_context (w);
+ PangoLayout *layout = gtk_widget_create_pango_layout (w, NULL);
+ GHashTableIter iter;
+ gpointer key;
+ GArray *widths;
+ GtkWidget *label = go_option_menu_get_label (GO_OPTION_MENU (gfs->family_picker));
screen = gtk_widget_get_screen (w);
if (!previous_screen)
@@ -641,14 +655,30 @@ gfs_screen_changed (GtkWidget *w, GdkScreen *previous_screen)
desc = pango_font_description_from_string ("Sans 72");
g_object_set (w, "font-desc", desc, NULL);
- width = go_pango_measure_string
- (gtk_widget_get_pango_context (w),
- desc,
- "M");
+ width = go_pango_measure_string (pctxt, desc, "M");
pango_font_description_free (desc);
/* Let's hope pixels are roughly square. */
gtk_widget_set_size_request (GTK_WIDGET (gfs->preview_label),
5 * width, width * 11 / 10);
+
+ // Compute the 95% percentile of family name widths. This is in the
+ // hope that less than 5% are crazy.
+ widths = g_array_new (FALSE, FALSE, sizeof (int));
+ g_hash_table_iter_init (&iter, gfs->family_by_name);
+ while (g_hash_table_iter_next (&iter, &key, NULL)) {
+ const char *name = key;
+ pango_layout_set_text (layout, name, -1);
+ pango_layout_get_pixel_size (layout, &width, NULL);
+ g_array_append_val (widths, width);
+ }
+ g_array_sort (widths, by_integer);
+ width = widths->len > 0
+ ? g_array_index (widths, int, widths->len * 95 / 100)
+ : -1;
+ gtk_widget_set_size_request (label, width, -1);
+ gtk_widget_set_halign (label, GTK_ALIGN_START);
+ g_array_free (widths, TRUE);
+ g_object_unref (layout);
}
static void
diff --git a/goffice/gtk/go-font-sel.ui b/goffice/gtk/go-font-sel.ui
index 1e4e88d..4b08177 100644
--- a/goffice/gtk/go-font-sel.ui
+++ b/goffice/gtk/go-font-sel.ui
@@ -1,6 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
+<!-- Generated with glade 3.18.3 -->
<interface>
- <!-- interface-requires gtk+ 3.0 -->
+ <requires lib="gtk+" version="3.8"/>
<object class="GtkBox" id="font-selector">
<property name="visible">True</property>
<property name="can_focus">False</property>
@@ -13,20 +14,19 @@
<property name="halign">center</property>
<property name="row_spacing">4</property>
<property name="column_spacing">4</property>
+ <property name="row_homogeneous">True</property>
<child>
<object class="GtkLabel" id="label1">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="tooltip_text" translatable="yes">Select the font family</property>
- <property name="xalign">0</property>
<property name="label" translatable="yes">Font:</property>
<property name="justify">center</property>
+ <property name="xalign">0</property>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">0</property>
- <property name="width">1</property>
- <property name="height">1</property>
</packing>
</child>
<child>
@@ -40,8 +40,6 @@
<packing>
<property name="left_attach">1</property>
<property name="top_attach">0</property>
- <property name="width">1</property>
- <property name="height">1</property>
</packing>
</child>
<child>
@@ -49,15 +47,13 @@
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="tooltip_text" translatable="yes">Select the size</property>
- <property name="xalign">0</property>
<property name="label" translatable="yes">Size:</property>
<property name="justify">center</property>
+ <property name="xalign">0</property>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">2</property>
- <property name="width">1</property>
- <property name="height">1</property>
</packing>
</child>
<child>
@@ -65,15 +61,13 @@
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="tooltip_text" translatable="yes">Select the font face</property>
- <property name="xalign">0</property>
<property name="label" translatable="yes">Style:</property>
<property name="justify">center</property>
+ <property name="xalign">0</property>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">1</property>
- <property name="width">1</property>
- <property name="height">1</property>
</packing>
</child>
<child>
@@ -87,8 +81,6 @@
<packing>
<property name="left_attach">1</property>
<property name="top_attach">1</property>
- <property name="width">1</property>
- <property name="height">1</property>
</packing>
</child>
<child>
@@ -96,8 +88,6 @@
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="has_entry">True</property>
- <property name="entry_text_column">0</property>
- <property name="id_column">1</property>
<child internal-child="entry">
<object class="GtkEntry" id="comboboxtext-entry2">
<property name="can_focus">True</property>
@@ -107,8 +97,6 @@
<packing>
<property name="left_attach">1</property>
<property name="top_attach">2</property>
- <property name="width">1</property>
- <property name="height">1</property>
</packing>
</child>
<child>
@@ -118,15 +106,13 @@
<property name="has_tooltip">True</property>
<property name="tooltip_markup" translatable="yes">Select whether a line should be drawn through
the text</property>
<property name="tooltip_text" translatable="yes">Select whether a line should be drawn through
the text</property>
- <property name="xalign">0</property>
<property name="label" translatable="yes">Strikethrough:</property>
<property name="justify">center</property>
+ <property name="xalign">0</property>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">5</property>
- <property name="width">1</property>
- <property name="height">1</property>
</packing>
</child>
<child>
@@ -137,15 +123,12 @@
<property name="receives_default">False</property>
<property name="halign">start</property>
<property name="valign">center</property>
- <property name="use_action_appearance">False</property>
<property name="xalign">0</property>
<property name="draw_indicator">True</property>
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">5</property>
- <property name="width">1</property>
- <property name="height">1</property>
</packing>
</child>
<child>
@@ -155,15 +138,13 @@
<property name="has_tooltip">True</property>
<property name="tooltip_markup" translatable="yes">Select the size</property>
<property name="tooltip_text" translatable="yes">Select the font color</property>
- <property name="xalign">0</property>
<property name="label" translatable="yes">Color:</property>
<property name="justify">center</property>
+ <property name="xalign">0</property>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">3</property>
- <property name="width">1</property>
- <property name="height">1</property>
</packing>
</child>
<child>
@@ -177,8 +158,6 @@
<packing>
<property name="left_attach">1</property>
<property name="top_attach">3</property>
- <property name="width">1</property>
- <property name="height">1</property>
</packing>
</child>
<child>
@@ -188,15 +167,13 @@
<property name="has_tooltip">True</property>
<property name="tooltip_markup" translatable="yes">Select the size</property>
<property name="tooltip_text" translatable="yes">Select whether the font should be modified for
use as subscript or superscript</property>
- <property name="xalign">0</property>
<property name="label" translatable="yes">Script:</property>
<property name="justify">center</property>
+ <property name="xalign">0</property>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">6</property>
- <property name="width">1</property>
- <property name="height">1</property>
</packing>
</child>
<child>
@@ -210,8 +187,6 @@
<packing>
<property name="left_attach">1</property>
<property name="top_attach">6</property>
- <property name="width">1</property>
- <property name="height">1</property>
</packing>
</child>
<child>
@@ -221,15 +196,13 @@
<property name="has_tooltip">True</property>
<property name="tooltip_markup" translatable="yes">Select the type of underlining</property>
<property name="tooltip_text" translatable="yes">Select the type of underlining</property>
- <property name="xalign">0</property>
<property name="label" translatable="yes">Underline:</property>
<property name="justify">center</property>
+ <property name="xalign">0</property>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">4</property>
- <property name="width">1</property>
- <property name="height">1</property>
</packing>
</child>
<child>
@@ -243,8 +216,6 @@
<packing>
<property name="left_attach">1</property>
<property name="top_attach">4</property>
- <property name="width">1</property>
- <property name="height">1</property>
</packing>
</child>
</object>
diff --git a/goffice/gtk/go-optionmenu.c b/goffice/gtk/go-optionmenu.c
index dd0fefb..ead4cd6 100644
--- a/goffice/gtk/go-optionmenu.c
+++ b/goffice/gtk/go-optionmenu.c
@@ -395,6 +395,17 @@ go_option_menu_get_history (GOOptionMenu *option_menu)
return GTK_WIDGET (option_menu->selected);
}
+/**
+ * go_option_menu_get_label:
+ * @option_menu: #GOOptionMenu
+ *
+ * Returns: (transfer none): The #GtkLabel used for the button text.
+ */
+GtkWidget *
+go_option_menu_get_label (GOOptionMenu *option_menu)
+{
+ return GTK_WIDGET (option_menu->button_label);
+}
static void
go_option_menu_set_property (GObject *object,
@@ -504,6 +515,7 @@ go_option_menu_init (GOOptionMenu *option_menu)
option_menu->button_label = GTK_LABEL (gtk_label_new (""));
gtk_box_pack_start (box, GTK_WIDGET (option_menu->button_label),
FALSE, TRUE, 0);
+ g_object_set (option_menu->button_label, "xalign", 0.0, NULL);
arrow = gtk_arrow_new (GTK_ARROW_DOWN, GTK_SHADOW_NONE);
g_object_set (arrow, "xalign", 0.75, NULL);
diff --git a/goffice/gtk/go-optionmenu.h b/goffice/gtk/go-optionmenu.h
index 8046a7c..82f9345 100644
--- a/goffice/gtk/go-optionmenu.h
+++ b/goffice/gtk/go-optionmenu.h
@@ -87,6 +87,7 @@ GtkWidget *go_option_menu_get_history (GOOptionMenu *option_menu);
void go_option_menu_select_item (GOOptionMenu *option_menu,
GtkMenuItem *item);
+GtkWidget *go_option_menu_get_label (GOOptionMenu *option_menu);
G_END_DECLS
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]