forked from AuroraMiddleware/gtk
GtkWidget: Add margin-start and margin-end properties
Add margin-{start,end} and gtk_widget_{get,set}_margin_{start,end} and drop margin-{left,right} and gtk_widget_{get,set}_margin_{left,right}. margin-{start,end} handle right also in RTL. https://bugzilla.gnome.org/show_bug.cgi?id=710238
This commit is contained in:
parent
c4141a2115
commit
9921bec63a
@ -5502,6 +5502,10 @@ gtk_widget_get_margin_left
|
||||
gtk_widget_set_margin_left
|
||||
gtk_widget_get_margin_right
|
||||
gtk_widget_set_margin_right
|
||||
gtk_widget_get_margin_start
|
||||
gtk_widget_set_margin_start
|
||||
gtk_widget_get_margin_end
|
||||
gtk_widget_set_margin_end
|
||||
gtk_widget_get_margin_top
|
||||
gtk_widget_set_margin_top
|
||||
gtk_widget_get_margin_bottom
|
||||
|
194
gtk/gtkwidget.c
194
gtk/gtkwidget.c
@ -631,6 +631,8 @@ enum {
|
||||
PROP_VALIGN,
|
||||
PROP_MARGIN_LEFT,
|
||||
PROP_MARGIN_RIGHT,
|
||||
PROP_MARGIN_START,
|
||||
PROP_MARGIN_END,
|
||||
PROP_MARGIN_TOP,
|
||||
PROP_MARGIN_BOTTOM,
|
||||
PROP_MARGIN,
|
||||
@ -1412,6 +1414,8 @@ G_GNUC_END_IGNORE_DEPRECATIONS
|
||||
* request, the margin will be added in addition to the size from
|
||||
* gtk_widget_set_size_request() for example.
|
||||
*
|
||||
* Deprecated: 3.12. Use #GtkWidget:margin-start instead.
|
||||
*
|
||||
* Since: 3.0
|
||||
*/
|
||||
g_object_class_install_property (gobject_class,
|
||||
@ -1433,6 +1437,8 @@ G_GNUC_END_IGNORE_DEPRECATIONS
|
||||
* request, the margin will be added in addition to the size from
|
||||
* gtk_widget_set_size_request() for example.
|
||||
*
|
||||
* Deprecated: 3.12. Use #GtkWidget:margin-end instead.
|
||||
*
|
||||
* Since: 3.0
|
||||
*/
|
||||
g_object_class_install_property (gobject_class,
|
||||
@ -1445,6 +1451,48 @@ G_GNUC_END_IGNORE_DEPRECATIONS
|
||||
0,
|
||||
GTK_PARAM_READWRITE));
|
||||
|
||||
/**
|
||||
* GtkWidget:margin-start:
|
||||
*
|
||||
* Margin on start of widget.
|
||||
*
|
||||
* This property adds margin outside of the widget's normal size
|
||||
* request, the margin will be added in addition to the size from
|
||||
* gtk_widget_set_size_request() for example.
|
||||
*
|
||||
* Since: 3.12
|
||||
*/
|
||||
g_object_class_install_property (gobject_class,
|
||||
PROP_MARGIN_LEFT,
|
||||
g_param_spec_int ("margin-start",
|
||||
P_("Margin on Start"),
|
||||
P_("Pixels of extra space on the start"),
|
||||
0,
|
||||
G_MAXINT16,
|
||||
0,
|
||||
GTK_PARAM_READWRITE));
|
||||
|
||||
/**
|
||||
* GtkWidget:margin-end:
|
||||
*
|
||||
* Margin on end of widget.
|
||||
*
|
||||
* This property adds margin outside of the widget's normal size
|
||||
* request, the margin will be added in addition to the size from
|
||||
* gtk_widget_set_size_request() for example.
|
||||
*
|
||||
* Since: 3.12
|
||||
*/
|
||||
g_object_class_install_property (gobject_class,
|
||||
PROP_MARGIN_RIGHT,
|
||||
g_param_spec_int ("margin-end",
|
||||
P_("Margin on End"),
|
||||
P_("Pixels of extra space on the end"),
|
||||
0,
|
||||
G_MAXINT16,
|
||||
0,
|
||||
GTK_PARAM_READWRITE));
|
||||
|
||||
/**
|
||||
* GtkWidget:margin-top:
|
||||
*
|
||||
@ -3721,6 +3769,12 @@ gtk_widget_set_property (GObject *object,
|
||||
case PROP_MARGIN_RIGHT:
|
||||
gtk_widget_set_margin_right (widget, g_value_get_int (value));
|
||||
break;
|
||||
case PROP_MARGIN_START:
|
||||
gtk_widget_set_margin_start (widget, g_value_get_int (value));
|
||||
break;
|
||||
case PROP_MARGIN_END:
|
||||
gtk_widget_set_margin_end (widget, g_value_get_int (value));
|
||||
break;
|
||||
case PROP_MARGIN_TOP:
|
||||
gtk_widget_set_margin_top (widget, g_value_get_int (value));
|
||||
break;
|
||||
@ -3729,8 +3783,8 @@ gtk_widget_set_property (GObject *object,
|
||||
break;
|
||||
case PROP_MARGIN:
|
||||
g_object_freeze_notify (G_OBJECT (widget));
|
||||
gtk_widget_set_margin_left (widget, g_value_get_int (value));
|
||||
gtk_widget_set_margin_right (widget, g_value_get_int (value));
|
||||
gtk_widget_set_margin_start (widget, g_value_get_int (value));
|
||||
gtk_widget_set_margin_end (widget, g_value_get_int (value));
|
||||
gtk_widget_set_margin_top (widget, g_value_get_int (value));
|
||||
gtk_widget_set_margin_bottom (widget, g_value_get_int (value));
|
||||
g_object_thaw_notify (G_OBJECT (widget));
|
||||
@ -14026,18 +14080,22 @@ gtk_widget_set_margin_left (GtkWidget *widget,
|
||||
gint margin)
|
||||
{
|
||||
GtkWidgetAuxInfo *aux_info;
|
||||
gboolean rtl;
|
||||
|
||||
g_return_if_fail (GTK_IS_WIDGET (widget));
|
||||
g_return_if_fail (margin <= G_MAXINT16);
|
||||
|
||||
aux_info = gtk_widget_get_aux_info (widget, TRUE);
|
||||
|
||||
rtl = gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL;
|
||||
|
||||
if (aux_info->margin.left == margin)
|
||||
return;
|
||||
|
||||
aux_info->margin.left = margin;
|
||||
gtk_widget_queue_resize (widget);
|
||||
g_object_notify (G_OBJECT (widget), "margin-left");
|
||||
g_object_notify (G_OBJECT (widget), rtl ? "margin-end" : "margin-start");
|
||||
}
|
||||
|
||||
/**
|
||||
@ -14073,18 +14131,150 @@ gtk_widget_set_margin_right (GtkWidget *widget,
|
||||
gint margin)
|
||||
{
|
||||
GtkWidgetAuxInfo *aux_info;
|
||||
gboolean rtl;
|
||||
|
||||
g_return_if_fail (GTK_IS_WIDGET (widget));
|
||||
g_return_if_fail (margin <= G_MAXINT16);
|
||||
|
||||
aux_info = gtk_widget_get_aux_info (widget, TRUE);
|
||||
|
||||
rtl = gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL;
|
||||
|
||||
if (aux_info->margin.right == margin)
|
||||
return;
|
||||
|
||||
aux_info->margin.right = margin;
|
||||
gtk_widget_queue_resize (widget);
|
||||
g_object_notify (G_OBJECT (widget), "margin-right");
|
||||
g_object_notify (G_OBJECT (widget), rtl ? "margin-start" : "margin-end");
|
||||
}
|
||||
|
||||
/**
|
||||
* gtk_widget_get_margin_start:
|
||||
* @widget: a #GtkWidget
|
||||
*
|
||||
* Gets the value of the #GtkWidget:margin-start property.
|
||||
*
|
||||
* Returns: The start margin of @widget
|
||||
*
|
||||
* Since: 3.12
|
||||
*/
|
||||
gint
|
||||
gtk_widget_get_margin_start (GtkWidget *widget)
|
||||
{
|
||||
const GtkWidgetAuxInfo *aux_info;
|
||||
|
||||
g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
|
||||
|
||||
aux_info = _gtk_widget_get_aux_info_or_defaults (widget);
|
||||
|
||||
if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
|
||||
return aux_info->margin.right;
|
||||
else
|
||||
return aux_info->margin.left;
|
||||
}
|
||||
|
||||
/**
|
||||
* gtk_widget_set_margin_start:
|
||||
* @widget: a #GtkWidget
|
||||
* @margin: the start margin
|
||||
*
|
||||
* Sets the start margin of @widget.
|
||||
* See the #GtkWidget:margin-start property.
|
||||
*
|
||||
* Since: 3.12
|
||||
*/
|
||||
void
|
||||
gtk_widget_set_margin_start (GtkWidget *widget,
|
||||
gint margin)
|
||||
{
|
||||
GtkWidgetAuxInfo *aux_info;
|
||||
gint16 *start;
|
||||
gboolean rtl;
|
||||
|
||||
g_return_if_fail (GTK_IS_WIDGET (widget));
|
||||
g_return_if_fail (margin <= G_MAXINT16);
|
||||
|
||||
aux_info = gtk_widget_get_aux_info (widget, TRUE);
|
||||
|
||||
rtl = gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL;
|
||||
|
||||
if (rtl)
|
||||
start = &aux_info->margin.right;
|
||||
else
|
||||
start = &aux_info->margin.left;
|
||||
|
||||
if (*start == margin)
|
||||
return;
|
||||
|
||||
*start = margin;
|
||||
gtk_widget_queue_resize (widget);
|
||||
g_object_notify (G_OBJECT (widget), "margin-start");
|
||||
g_object_notify (G_OBJECT (widget), rtl ? "margin-right" : "margin-left");
|
||||
}
|
||||
|
||||
/**
|
||||
* gtk_widget_get_margin_end:
|
||||
* @widget: a #GtkWidget
|
||||
*
|
||||
* Gets the value of the #GtkWidget:margin-end property.
|
||||
*
|
||||
* Returns: The end margin of @widget
|
||||
*
|
||||
* Since: 3.12
|
||||
*/
|
||||
gint
|
||||
gtk_widget_get_margin_end (GtkWidget *widget)
|
||||
{
|
||||
const GtkWidgetAuxInfo *aux_info;
|
||||
|
||||
g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
|
||||
|
||||
aux_info = _gtk_widget_get_aux_info_or_defaults (widget);
|
||||
|
||||
if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
|
||||
return aux_info->margin.left;
|
||||
else
|
||||
return aux_info->margin.right;
|
||||
}
|
||||
|
||||
/**
|
||||
* gtk_widget_set_margin_end:
|
||||
* @widget: a #GtkWidget
|
||||
* @margin: the end margin
|
||||
*
|
||||
* Sets the end margin of @widget.
|
||||
* See the #GtkWidget:margin-end property.
|
||||
*
|
||||
* Since: 3.12
|
||||
*/
|
||||
void
|
||||
gtk_widget_set_margin_end (GtkWidget *widget,
|
||||
gint margin)
|
||||
{
|
||||
GtkWidgetAuxInfo *aux_info;
|
||||
gint16 *end;
|
||||
gboolean rtl;
|
||||
|
||||
g_return_if_fail (GTK_IS_WIDGET (widget));
|
||||
g_return_if_fail (margin <= G_MAXINT16);
|
||||
|
||||
aux_info = gtk_widget_get_aux_info (widget, TRUE);
|
||||
|
||||
rtl = gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL;
|
||||
|
||||
if (rtl)
|
||||
end = &aux_info->margin.left;
|
||||
else
|
||||
end = &aux_info->margin.right;
|
||||
|
||||
if (*end == margin)
|
||||
return;
|
||||
|
||||
*end = margin;
|
||||
gtk_widget_queue_resize (widget);
|
||||
g_object_notify (G_OBJECT (widget), "margin-end");
|
||||
g_object_notify (G_OBJECT (widget), rtl ? "margin-left" : "margin-right");
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -920,16 +920,26 @@ GtkAlign gtk_widget_get_valign_with_baseline (GtkWidget *widget);
|
||||
GDK_AVAILABLE_IN_ALL
|
||||
void gtk_widget_set_valign (GtkWidget *widget,
|
||||
GtkAlign align);
|
||||
GDK_AVAILABLE_IN_ALL
|
||||
GDK_DEPRECATED_IN_3_12_FOR(gtk_widget_get_margin_start)
|
||||
gint gtk_widget_get_margin_left (GtkWidget *widget);
|
||||
GDK_AVAILABLE_IN_ALL
|
||||
GDK_DEPRECATED_IN_3_12_FOR(gtk_widget_set_margin_start)
|
||||
void gtk_widget_set_margin_left (GtkWidget *widget,
|
||||
gint margin);
|
||||
GDK_AVAILABLE_IN_ALL
|
||||
GDK_DEPRECATED_IN_3_12_FOR(gtk_widget_get_margin_end)
|
||||
gint gtk_widget_get_margin_right (GtkWidget *widget);
|
||||
GDK_AVAILABLE_IN_ALL
|
||||
GDK_DEPRECATED_IN_3_12_FOR(gtk_widget_set_margin_end)
|
||||
void gtk_widget_set_margin_right (GtkWidget *widget,
|
||||
gint margin);
|
||||
GDK_AVAILABLE_IN_3_12
|
||||
gint gtk_widget_get_margin_start (GtkWidget *widget);
|
||||
GDK_AVAILABLE_IN_3_12
|
||||
void gtk_widget_set_margin_start (GtkWidget *widget,
|
||||
gint margin);
|
||||
GDK_AVAILABLE_IN_3_12
|
||||
gint gtk_widget_get_margin_end (GtkWidget *widget);
|
||||
GDK_AVAILABLE_IN_3_12
|
||||
void gtk_widget_set_margin_end (GtkWidget *widget,
|
||||
gint margin);
|
||||
GDK_AVAILABLE_IN_ALL
|
||||
gint gtk_widget_get_margin_top (GtkWidget *widget);
|
||||
GDK_AVAILABLE_IN_ALL
|
||||
|
Loading…
Reference in New Issue
Block a user