forked from AuroraMiddleware/gtk
entry: Move spinbutton size hack
If we want to do special sizing for the text, we need to do it for the text. Otherwise paddings, borders and entyr icons will screw up everything.
This commit is contained in:
parent
02fab14b3b
commit
3982f05be4
@ -148,7 +148,6 @@
|
||||
* .insertion-cursor.
|
||||
*/
|
||||
|
||||
|
||||
#define MIN_ENTRY_WIDTH 150
|
||||
|
||||
#define MAX_ICONS 2
|
||||
@ -3509,12 +3508,19 @@ gtk_entry_measure (GtkCssGadget *gadget,
|
||||
char_pixels = (MAX (char_width, digit_width) + PANGO_SCALE - 1) / PANGO_SCALE;
|
||||
|
||||
if (priv->width_chars < 0)
|
||||
min = MIN_ENTRY_WIDTH;
|
||||
{
|
||||
if (GTK_IS_SPIN_BUTTON (entry))
|
||||
min = gtk_spin_button_get_text_width (GTK_SPIN_BUTTON (entry));
|
||||
else
|
||||
min = MIN_ENTRY_WIDTH;
|
||||
}
|
||||
else
|
||||
min = char_pixels * priv->width_chars;
|
||||
{
|
||||
min = char_pixels * priv->width_chars;
|
||||
}
|
||||
|
||||
if (priv->max_width_chars < 0)
|
||||
nat = MIN_ENTRY_WIDTH;
|
||||
nat = min;
|
||||
else
|
||||
nat = char_pixels * priv->max_width_chars;
|
||||
|
||||
|
@ -24,6 +24,7 @@
|
||||
#include <gtk/gtkentrycompletion.h>
|
||||
#include <gtk/gtkentry.h>
|
||||
#include <gtk/gtkcssgadgetprivate.h>
|
||||
#include <gtk/gtkspinbutton.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
@ -91,6 +92,9 @@ GtkCssGadget* gtk_entry_get_gadget (GtkEntry *entry);
|
||||
void _gtk_entry_grab_focus (GtkEntry *entry,
|
||||
gboolean select_all);
|
||||
|
||||
/* in gtkspinbutton.c (because I'm too lazy to create gtkspinbuttonprivate.h) */
|
||||
gint gtk_spin_button_get_text_width (GtkSpinButton *spin_button);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* __GTK_ENTRY_PRIVATE_H__ */
|
||||
|
@ -1185,6 +1185,36 @@ gtk_spin_button_format_for_value (GtkSpinButton *spin_button,
|
||||
return buf;
|
||||
}
|
||||
|
||||
gint
|
||||
gtk_spin_button_get_text_width (GtkSpinButton *spin_button)
|
||||
{
|
||||
GtkSpinButtonPrivate *priv = spin_button->priv;
|
||||
gint width, w;
|
||||
PangoLayout *layout;
|
||||
gchar *str;
|
||||
|
||||
layout = pango_layout_copy (gtk_entry_get_layout (GTK_ENTRY (spin_button)));
|
||||
|
||||
/* Get max of MIN_SPIN_BUTTON_WIDTH, size of upper, size of lower */
|
||||
width = MIN_SPIN_BUTTON_WIDTH;
|
||||
|
||||
str = gtk_spin_button_format_for_value (spin_button,
|
||||
gtk_adjustment_get_upper (priv->adjustment));
|
||||
w = measure_string_width (layout, str);
|
||||
width = MAX (width, w);
|
||||
g_free (str);
|
||||
|
||||
str = gtk_spin_button_format_for_value (spin_button,
|
||||
gtk_adjustment_get_lower (priv->adjustment));
|
||||
w = measure_string_width (layout, str);
|
||||
width = MAX (width, w);
|
||||
g_free (str);
|
||||
|
||||
g_object_unref (layout);
|
||||
|
||||
return width;
|
||||
}
|
||||
|
||||
static void
|
||||
gtk_spin_button_get_preferred_width (GtkWidget *widget,
|
||||
gint *minimum,
|
||||
@ -1192,39 +1222,9 @@ gtk_spin_button_get_preferred_width (GtkWidget *widget,
|
||||
{
|
||||
GtkSpinButton *spin_button = GTK_SPIN_BUTTON (widget);
|
||||
GtkSpinButtonPrivate *priv = spin_button->priv;
|
||||
GtkEntry *entry = GTK_ENTRY (widget);
|
||||
|
||||
GTK_WIDGET_CLASS (gtk_spin_button_parent_class)->get_preferred_width (widget, minimum, natural);
|
||||
|
||||
if (gtk_entry_get_width_chars (entry) < 0)
|
||||
{
|
||||
gint width, w;
|
||||
PangoLayout *layout;
|
||||
gchar *str;
|
||||
|
||||
layout = pango_layout_copy (gtk_entry_get_layout (entry));
|
||||
|
||||
/* Get max of MIN_SPIN_BUTTON_WIDTH, size of upper, size of lower */
|
||||
width = MIN_SPIN_BUTTON_WIDTH;
|
||||
|
||||
str = gtk_spin_button_format_for_value (spin_button,
|
||||
gtk_adjustment_get_upper (priv->adjustment));
|
||||
w = measure_string_width (layout, str);
|
||||
width = MAX (width, w);
|
||||
g_free (str);
|
||||
|
||||
str = gtk_spin_button_format_for_value (spin_button,
|
||||
gtk_adjustment_get_lower (priv->adjustment));
|
||||
w = measure_string_width (layout, str);
|
||||
width = MAX (width, w);
|
||||
g_free (str);
|
||||
|
||||
*minimum = width;
|
||||
*natural = width;
|
||||
|
||||
g_object_unref (layout);
|
||||
}
|
||||
|
||||
if (priv->orientation == GTK_ORIENTATION_HORIZONTAL)
|
||||
{
|
||||
gint down_panel_width;
|
||||
|
Loading…
Reference in New Issue
Block a user