[gtk+/entry-css-cleanups: 9/11] entry: use padding on the image area to position the image
- From: Cosimo Cecchi <cosimoc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+/entry-css-cleanups: 9/11] entry: use padding on the image area to position the image
- Date: Mon, 30 Jan 2012 22:29:57 +0000 (UTC)
commit b0a3d647e3cac27a0b5ac024f641a5e2b430c9e7
Author: Cosimo Cecchi <cosimoc gnome org>
Date: Mon Jan 30 16:47:55 2012 -0500
entry: use padding on the image area to position the image
Don't assume the padding of the icons is the same padding of the rest of
the entry.
This also allows to set different paddings for left and right icons.
gtk/gtkentry.c | 47 +++++++++++++++++++++++++++--------------------
1 files changed, 27 insertions(+), 20 deletions(-)
---
diff --git a/gtk/gtkentry.c b/gtk/gtkentry.c
index 7608792..4cc81bd 100644
--- a/gtk/gtkentry.c
+++ b/gtk/gtkentry.c
@@ -169,7 +169,6 @@ struct _GtkEntryPrivate
gint drag_start_x;
gint drag_start_y;
gint focus_width;
- gint icon_margin;
gint insert_pos;
gint selection_bound;
gint scroll_offset;
@@ -2506,6 +2505,21 @@ gtk_entry_prepare_context_for_icon (GtkEntry *entry,
gtk_style_context_set_state (context, state);
gtk_style_context_add_class (context, GTK_STYLE_CLASS_IMAGE);
+
+ if (gtk_widget_get_direction (GTK_WIDGET (entry)) == GTK_TEXT_DIR_RTL)
+ {
+ if (icon_pos == GTK_ENTRY_ICON_PRIMARY)
+ gtk_style_context_add_class (context, GTK_STYLE_CLASS_RIGHT);
+ else
+ gtk_style_context_add_class (context, GTK_STYLE_CLASS_LEFT);
+ }
+ else
+ {
+ if (icon_pos == GTK_ENTRY_ICON_PRIMARY)
+ gtk_style_context_add_class (context, GTK_STYLE_CLASS_LEFT);
+ else
+ gtk_style_context_add_class (context, GTK_STYLE_CLASS_RIGHT);
+ }
}
static gint
@@ -2515,6 +2529,7 @@ get_icon_width (GtkEntry *entry,
GtkEntryPrivate *priv = entry->priv;
EntryIconInfo *icon_info = priv->icons[icon_pos];
GtkStyleContext *context;
+ GtkBorder padding;
gint width;
if (!icon_info)
@@ -2522,10 +2537,15 @@ get_icon_width (GtkEntry *entry,
context = gtk_widget_get_style_context (GTK_WIDGET (entry));
gtk_entry_prepare_context_for_icon (entry, context, icon_pos);
+ gtk_style_context_get_padding (context, 0, &padding);
+
_gtk_icon_helper_get_size (icon_info->icon_helper, context,
&width, NULL);
gtk_style_context_restore (context);
+ if (width > 0)
+ width += padding.left + padding.right;
+
return width;
}
@@ -2546,14 +2566,10 @@ get_icon_allocations (GtkEntry *entry,
primary->y = y;
primary->height = height;
primary->width = get_icon_width (entry, GTK_ENTRY_ICON_PRIMARY);
- if (primary->width > 0)
- primary->width += 2 * priv->icon_margin;
secondary->y = y;
secondary->height = height;
secondary->width = get_icon_width (entry, GTK_ENTRY_ICON_SECONDARY);
- if (secondary->width > 0)
- secondary->width += 2 * priv->icon_margin;
if (gtk_widget_get_direction (GTK_WIDGET (entry)) == GTK_TEXT_DIR_RTL)
{
@@ -3131,7 +3147,7 @@ gtk_entry_get_preferred_width (GtkWidget *widget,
{
icon_width = get_icon_width (entry, i);
if (icon_width > 0)
- icon_widths += icon_width + 2 * priv->icon_margin;
+ icon_widths += icon_width;
}
if (icon_widths > width)
@@ -3384,6 +3400,7 @@ draw_icon (GtkWidget *widget,
EntryIconInfo *icon_info = priv->icons[icon_pos];
gint x, y, width, height, pix_width, pix_height;
GtkStyleContext *context;
+ GtkBorder padding;
if (!icon_info)
return;
@@ -3401,9 +3418,11 @@ draw_icon (GtkWidget *widget,
context = gtk_widget_get_style_context (widget);
gtk_entry_prepare_context_for_icon (entry, context, icon_pos);
- _gtk_icon_helper_get_size (icon_info->icon_helper, context, &pix_width, &pix_height);
+ _gtk_icon_helper_get_size (icon_info->icon_helper, context,
+ &pix_width, &pix_height);
+ gtk_style_context_get_padding (context, 0, &padding);
- x = MAX (0, (width - pix_width) / 2);
+ x = MAX (0, padding.left);
y = MAX (0, (height - pix_height) / 2);
_gtk_icon_helper_draw (icon_info->icon_helper,
@@ -4521,17 +4540,6 @@ icon_theme_changed (GtkEntry *entry)
}
static void
-icon_margin_changed (GtkEntry *entry)
-{
- GtkEntryPrivate *priv = entry->priv;
- GtkBorder border;
-
- _gtk_entry_get_borders (GTK_ENTRY (entry), &border);
-
- priv->icon_margin = border.left;
-}
-
-static void
gtk_entry_update_cached_style_values (GtkEntry *entry)
{
GtkEntryPrivate *priv = entry->priv;
@@ -4569,7 +4577,6 @@ gtk_entry_style_updated (GtkWidget *widget)
gtk_entry_recompute (entry);
icon_theme_changed (entry);
- icon_margin_changed (entry);
}
/* GtkCellEditable method implementations
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]