[gtk+/native-layout] Fixed wrapping labels to show up correctly aligned inside their allocations.
- From: Tristan Van Berkom <tvb src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+/native-layout] Fixed wrapping labels to show up correctly aligned inside their allocations.
- Date: Sun, 11 Apr 2010 02:52:21 +0000 (UTC)
commit c0e950f17bc6b2eebe21db5b95cee56520c84369
Author: Tristan Van Berkom <tristan van berkom gmail com>
Date: Sat Apr 10 22:30:42 2010 -0400
Fixed wrapping labels to show up correctly aligned inside their allocations.
gtk/gtklabel.c | 39 ++++++++++++++-------------------------
1 files changed, 14 insertions(+), 25 deletions(-)
---
diff --git a/gtk/gtklabel.c b/gtk/gtklabel.c
index 90904b4..dd30b21 100644
--- a/gtk/gtklabel.c
+++ b/gtk/gtklabel.c
@@ -3246,7 +3246,7 @@ gtk_label_get_desired_size (GtkExtendedLayout *layout,
}
if (label->single_line_mode)
- required_rect.height = get_single_line_height (GTK_WIDGET (label), label->layout);
+ required_rect.height = get_single_line_height (GTK_WIDGET (label), label->layout);
if (label->have_transform)
{
@@ -3258,12 +3258,18 @@ gtk_label_get_desired_size (GtkExtendedLayout *layout,
required_rect.width = PANGO_PIXELS_CEIL (required_rect.width);
required_rect.height = PANGO_PIXELS_CEIL (required_rect.height);
+
+ /* if a width-request is set, use that as the requested label width */
if ((label->wrap || label->ellipsize ||
priv->width_chars > 0 || priv->max_width_chars > 0) &&
aux_info && aux_info->width > 0)
required_rect.width = aux_info->width;
- minimum_size->width = required_rect.width + label->misc.xpad * 2;
+ /* XXX TODO: Ideally for wrapping labels, the width should be one char or the length
+ * of the longest word in the text depending on wrap mode.
+ */
+
+ minimum_size->width = required_rect.width + label->misc.xpad * 2;
minimum_size->height = required_rect.height + label->misc.ypad * 2;
/* Natural size */
@@ -3296,9 +3302,9 @@ gtk_label_get_desired_size (GtkExtendedLayout *layout,
static void
get_size_for_allocation (GtkLabel *label,
GtkOrientation orientation,
- gint allocation,
- gint *minimum_size,
- gint *natural_size)
+ gint allocation,
+ gint *minimum_size,
+ gint *natural_size)
{
PangoLayout *layout;
GtkWidgetAuxInfo *aux_info =
@@ -3326,7 +3332,7 @@ get_size_for_allocation (GtkLabel *label,
if (natural_size)
{
-// pango_layout_set_ellipsize (layout, PANGO_ELLIPSIZE_NONE);
+ //pango_layout_set_ellipsize (layout, PANGO_ELLIPSIZE_NONE);
pango_layout_get_pixel_size (layout, NULL, natural_size);
}
@@ -3395,7 +3401,7 @@ gtk_label_size_allocate (GtkWidget *widget,
GTK_WIDGET_CLASS (gtk_label_parent_class)->size_allocate (widget, allocation);
- /* The layout may have been recently cleared in get_size_for_allocation(), but the
+ /* The layout may have been recently cleared in get_size_for_orientation(), but the
* width at that point may not be the same as the allocated width
*/
if (label->wrap)
@@ -3595,7 +3601,7 @@ get_layout_location (GtkLabel *label,
pango_extents_to_pixels (&logical, NULL);
- if (label->ellipsize || priv->width_chars > 0 || priv->full_size)
+ if (label->wrap || label->ellipsize || priv->width_chars > 0 || priv->full_size)
{
int width;
@@ -3609,23 +3615,6 @@ get_layout_location (GtkLabel *label,
req_width += 2 * misc->xpad;
req_height += 2 * misc->ypad;
}
- else if (label->wrap)
- {
- GtkWidgetAuxInfo *aux_info = _gtk_widget_get_aux_info (widget, FALSE);
-
- if (aux_info->width > 0)
- req_width = aux_info->width;
- else
- req_width = widget->allocation.width;
-
- if (aux_info->height > 0)
- req_height = aux_info->height;
- else
- req_height = widget->allocation.height;
-
- req_width -= 2 * misc->xpad;
- req_height -= 2 * misc->ypad;
- }
else
{
req_width = widget->requisition.width;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]