forked from AuroraMiddleware/gtk
Add GtkLabel:tabs
This adds more powerful formatting capabilities to GtkLabel without costing us much, since Pango already supports tabs.
This commit is contained in:
parent
924da0e84b
commit
641a589734
@ -256,6 +256,7 @@ struct _GtkLabel
|
|||||||
PangoAttrList *attrs;
|
PangoAttrList *attrs;
|
||||||
PangoAttrList *markup_attrs;
|
PangoAttrList *markup_attrs;
|
||||||
PangoLayout *layout;
|
PangoLayout *layout;
|
||||||
|
PangoTabArray *tabs;
|
||||||
|
|
||||||
GtkWidget *popup_menu;
|
GtkWidget *popup_menu;
|
||||||
GMenuModel *extra_menu;
|
GMenuModel *extra_menu;
|
||||||
@ -394,6 +395,7 @@ enum {
|
|||||||
PROP_XALIGN,
|
PROP_XALIGN,
|
||||||
PROP_YALIGN,
|
PROP_YALIGN,
|
||||||
PROP_EXTRA_MENU,
|
PROP_EXTRA_MENU,
|
||||||
|
PROP_TABS,
|
||||||
NUM_PROPERTIES
|
NUM_PROPERTIES
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -520,6 +522,9 @@ gtk_label_set_property (GObject *object,
|
|||||||
case PROP_EXTRA_MENU:
|
case PROP_EXTRA_MENU:
|
||||||
gtk_label_set_extra_menu (self, g_value_get_object (value));
|
gtk_label_set_extra_menu (self, g_value_get_object (value));
|
||||||
break;
|
break;
|
||||||
|
case PROP_TABS:
|
||||||
|
gtk_label_set_tabs (self, g_value_get_boxed (value));
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||||
break;
|
break;
|
||||||
@ -593,6 +598,9 @@ gtk_label_get_property (GObject *object,
|
|||||||
case PROP_EXTRA_MENU:
|
case PROP_EXTRA_MENU:
|
||||||
g_value_set_object (value, gtk_label_get_extra_menu (self));
|
g_value_set_object (value, gtk_label_get_extra_menu (self));
|
||||||
break;
|
break;
|
||||||
|
case PROP_TABS:
|
||||||
|
g_value_set_boxed (value, self->tabs);
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||||
break;
|
break;
|
||||||
@ -623,6 +631,7 @@ gtk_label_init (GtkLabel *self)
|
|||||||
self->layout = NULL;
|
self->layout = NULL;
|
||||||
self->text = g_strdup ("");
|
self->text = g_strdup ("");
|
||||||
self->attrs = NULL;
|
self->attrs = NULL;
|
||||||
|
self->tabs = NULL;
|
||||||
|
|
||||||
self->mnemonic_widget = NULL;
|
self->mnemonic_widget = NULL;
|
||||||
|
|
||||||
@ -1549,6 +1558,8 @@ gtk_label_finalize (GObject *object)
|
|||||||
g_clear_pointer (&self->popup_menu, gtk_widget_unparent);
|
g_clear_pointer (&self->popup_menu, gtk_widget_unparent);
|
||||||
g_clear_object (&self->extra_menu);
|
g_clear_object (&self->extra_menu);
|
||||||
|
|
||||||
|
g_clear_pointer (&self->tabs, pango_tab_array_free);
|
||||||
|
|
||||||
G_OBJECT_CLASS (gtk_label_parent_class)->finalize (object);
|
G_OBJECT_CLASS (gtk_label_parent_class)->finalize (object);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2548,6 +2559,18 @@ gtk_label_class_init (GtkLabelClass *class)
|
|||||||
G_TYPE_MENU_MODEL,
|
G_TYPE_MENU_MODEL,
|
||||||
GTK_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY);
|
GTK_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* GtkLabel:tabs: (attributes org.gtk.Property.get=gtk_label_get_tabs org.gtk.Property.set=gtk_label_set_tabs)
|
||||||
|
*
|
||||||
|
* Custom tabs for this label.
|
||||||
|
*
|
||||||
|
* Since: 4.8
|
||||||
|
*/
|
||||||
|
label_props[PROP_TABS] =
|
||||||
|
g_param_spec_boxed ("tabs", NULL, NULL,
|
||||||
|
PANGO_TYPE_TAB_ARRAY,
|
||||||
|
GTK_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY);
|
||||||
|
|
||||||
g_object_class_install_properties (gobject_class, NUM_PROPERTIES, label_props);
|
g_object_class_install_properties (gobject_class, NUM_PROPERTIES, label_props);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -4155,6 +4178,8 @@ gtk_label_ensure_layout (GtkLabel *self)
|
|||||||
|
|
||||||
if (self->ellipsize || self->wrap)
|
if (self->ellipsize || self->wrap)
|
||||||
pango_layout_set_width (self->layout, gtk_widget_get_width (GTK_WIDGET (self)) * PANGO_SCALE);
|
pango_layout_set_width (self->layout, gtk_widget_get_width (GTK_WIDGET (self)) * PANGO_SCALE);
|
||||||
|
|
||||||
|
pango_layout_set_tabs (self->layout, self->tabs);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -5922,3 +5947,53 @@ gtk_label_get_extra_menu (GtkLabel *self)
|
|||||||
|
|
||||||
return self->extra_menu;
|
return self->extra_menu;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* gtk_label_set_tabs: (attributes org.gtk.Method.set_property=tabs)
|
||||||
|
* @self: a `GtkLabel`
|
||||||
|
* @tabs: (nullable): tabs as a `PangoTabArray`
|
||||||
|
*
|
||||||
|
* Sets the default tab stops for paragraphs in @self.
|
||||||
|
*
|
||||||
|
* Since: 4.8
|
||||||
|
*/
|
||||||
|
void
|
||||||
|
gtk_label_set_tabs (GtkLabel *self,
|
||||||
|
PangoTabArray *tabs)
|
||||||
|
{
|
||||||
|
g_return_if_fail (GTK_IS_LABEL (self));
|
||||||
|
|
||||||
|
if (self->tabs == tabs)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (self->tabs)
|
||||||
|
pango_tab_array_free (self->tabs);
|
||||||
|
self->tabs = pango_tab_array_copy (tabs);
|
||||||
|
|
||||||
|
gtk_label_clear_layout (self);
|
||||||
|
g_object_notify_by_pspec (G_OBJECT (self), label_props[PROP_TABS]);
|
||||||
|
gtk_widget_queue_resize (GTK_WIDGET (self));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* gtk_label_get_tabs: (attributes org.gtk.Method.get_property=tabs)
|
||||||
|
* @self: a `GtkLabel`
|
||||||
|
*
|
||||||
|
* Gets the tabs for @self.
|
||||||
|
*
|
||||||
|
* The returned array will be %NULL if “standard” (8-space) tabs are used.
|
||||||
|
* Free the return value with [method@Pango.TabArray.free].
|
||||||
|
*
|
||||||
|
* Returns: (nullable) (transfer full): copy of default tab array,
|
||||||
|
* or %NULL if standard tabs are used; must be freed with
|
||||||
|
* [method@Pango.TabArray.free].
|
||||||
|
*
|
||||||
|
* Since: 4.8
|
||||||
|
*/
|
||||||
|
PangoTabArray *
|
||||||
|
gtk_label_get_tabs (GtkLabel *self)
|
||||||
|
{
|
||||||
|
g_return_val_if_fail (GTK_IS_LABEL (self), NULL);
|
||||||
|
|
||||||
|
return self->tabs ? pango_tab_array_copy (self->tabs) : NULL;
|
||||||
|
}
|
||||||
|
@ -177,6 +177,14 @@ void gtk_label_set_extra_menu (GtkLabel *self,
|
|||||||
GDK_AVAILABLE_IN_ALL
|
GDK_AVAILABLE_IN_ALL
|
||||||
GMenuModel * gtk_label_get_extra_menu (GtkLabel *self);
|
GMenuModel * gtk_label_get_extra_menu (GtkLabel *self);
|
||||||
|
|
||||||
|
GDK_AVAILABLE_IN_4_8
|
||||||
|
void gtk_label_set_tabs (GtkLabel *self,
|
||||||
|
PangoTabArray *tabs);
|
||||||
|
|
||||||
|
GDK_AVAILABLE_IN_4_8
|
||||||
|
PangoTabArray * gtk_label_get_tabs (GtkLabel *self);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
G_DEFINE_AUTOPTR_CLEANUP_FUNC(GtkLabel, g_object_unref)
|
G_DEFINE_AUTOPTR_CLEANUP_FUNC(GtkLabel, g_object_unref)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user