mirror of
https://gitlab.gnome.org/GNOME/gtk.git
synced 2025-01-13 05:50:10 +00:00
Merge branch 'builder-tool-box-position' into 'main'
builder-tool: Handle pack-type, position, and center child in GtkBox See merge request GNOME/gtk!7715
This commit is contained in:
commit
b42caef0ed
@ -49,7 +49,6 @@
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkBox">
|
||||
<property name="can_focus">0</property>
|
||||
<property name="valign">center</property>
|
||||
<property name="hexpand">1</property>
|
||||
<property name="vexpand">0</property>
|
||||
@ -91,9 +90,8 @@
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkBox">
|
||||
<property name="halign">center</property>
|
||||
<property name="orientation">vertical</property>
|
||||
<property name="can_focus">0</property>
|
||||
<property name="halign">center</property>
|
||||
<property name="vexpand">1</property>
|
||||
<child>
|
||||
<object class="GtkButton">
|
||||
@ -674,6 +672,77 @@
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkCenterBox">
|
||||
<property name="orientation">vertical</property>
|
||||
<property name="start-widget">
|
||||
<object class="GtkBox">
|
||||
<property name="orientation">vertical</property>
|
||||
<child>
|
||||
<object class="GtkButton">
|
||||
<property name="valign">center</property>
|
||||
<property name="label" translatable="1">start 0</property>
|
||||
<property name="focusable">1</property>
|
||||
<property name="receives_default">1</property>
|
||||
</object>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkButton">
|
||||
<property name="valign">center</property>
|
||||
<property name="label" translatable="1">start 1</property>
|
||||
<property name="focusable">1</property>
|
||||
<property name="receives_default">1</property>
|
||||
</object>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkButton">
|
||||
<property name="valign">center</property>
|
||||
<property name="label" translatable="1">start 2</property>
|
||||
<property name="focusable">1</property>
|
||||
<property name="receives_default">1</property>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
</property>
|
||||
<property name="center-widget">
|
||||
<object class="GtkButton">
|
||||
<property name="valign">center</property>
|
||||
<property name="label" translatable="1">center</property>
|
||||
<property name="focusable">1</property>
|
||||
<property name="receives_default">1</property>
|
||||
</object>
|
||||
</property>
|
||||
<property name="end-widget">
|
||||
<object class="GtkBox">
|
||||
<property name="orientation">vertical</property>
|
||||
<child>
|
||||
<object class="GtkButton">
|
||||
<property name="valign">center</property>
|
||||
<property name="label" translatable="1">end 2</property>
|
||||
<property name="focusable">1</property>
|
||||
<property name="receives_default">1</property>
|
||||
</object>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkButton">
|
||||
<property name="valign">center</property>
|
||||
<property name="label" translatable="1">end 1</property>
|
||||
<property name="focusable">1</property>
|
||||
<property name="receives_default">1</property>
|
||||
</object>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkButton">
|
||||
<property name="valign">center</property>
|
||||
<property name="label" translatable="1">end 0</property>
|
||||
<property name="focusable">1</property>
|
||||
<property name="receives_default">1</property>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
</property>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
</property>
|
||||
</object>
|
||||
|
@ -1123,6 +1123,114 @@
|
||||
<property name="position">4</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkBox">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="orientation">vertical</property>
|
||||
<child>
|
||||
<object class="GtkButton">
|
||||
<property name="label" translatable="yes">start 0</property>
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="receives_default">True</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">False</property>
|
||||
<property name="position">0</property>
|
||||
<property name="pack-type">start</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkButton">
|
||||
<property name="label" translatable="yes">start 2</property>
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="receives_default">True</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">False</property>
|
||||
<property name="pack-type">start</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkButton">
|
||||
<property name="label" translatable="yes">start 1</property>
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="receives_default">True</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">False</property>
|
||||
<property name="position">1</property>
|
||||
<property name="pack-type">start</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child type="center">
|
||||
<object class="GtkButton">
|
||||
<property name="label" translatable="yes">center</property>
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="receives_default">True</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">False</property>
|
||||
<property name="position">0</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkButton">
|
||||
<property name="label" translatable="yes">end 0</property>
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="receives_default">True</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">False</property>
|
||||
<property name="position">0</property>
|
||||
<property name="pack-type">end</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkButton">
|
||||
<property name="label" translatable="yes">end 2</property>
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="receives_default">True</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">False</property>
|
||||
<property name="position">2</property>
|
||||
<property name="pack-type">end</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkButton">
|
||||
<property name="label" translatable="yes">end 1</property>
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="receives_default">True</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">False</property>
|
||||
<property name="position">1</property>
|
||||
<property name="pack-type">end</property>
|
||||
</packing>
|
||||
</child>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">True</property>
|
||||
<property name="position">6</property>
|
||||
</packing>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
|
@ -46,6 +46,7 @@
|
||||
<property name="label" translatable="1">Hello World!</property>
|
||||
<property name="active">1</property>
|
||||
<property name="group">button3</property>
|
||||
<property name="focusable">1</property>
|
||||
<property name="receives_default">1</property>
|
||||
<layout>
|
||||
<property name="column">3</property>
|
||||
|
@ -131,6 +131,10 @@
|
||||
<object class="GtkBox" id="box2">
|
||||
<property name="valign">center</property>
|
||||
<property name="orientation">vertical</property>
|
||||
<layout>
|
||||
<property name="column">1</property>
|
||||
<property name="row">0</property>
|
||||
</layout>
|
||||
<child>
|
||||
<object class="GtkLabel" id="result_label">
|
||||
<property name="valign">start</property>
|
||||
@ -164,10 +168,6 @@
|
||||
<property name="wrap">1</property>
|
||||
</object>
|
||||
</child>
|
||||
<layout>
|
||||
<property name="column">1</property>
|
||||
<property name="row">0</property>
|
||||
</layout>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
|
@ -1381,6 +1381,9 @@ rewrite_start_center_end_children (Element *element,
|
||||
{
|
||||
Element *child = l->data;
|
||||
|
||||
if (!g_str_equal (child->element_name, "child"))
|
||||
continue;
|
||||
|
||||
if (has_attribute (child, "type", "start"))
|
||||
start_child = child;
|
||||
else if (has_attribute (child, "type", "center"))
|
||||
@ -1588,10 +1591,33 @@ write_box_prop (Element *element,
|
||||
return element;
|
||||
}
|
||||
|
||||
static Element *
|
||||
rewrite_start_end_box_children (Element *element,
|
||||
const char *type,
|
||||
GtkOrientation orientation,
|
||||
GList *children)
|
||||
{
|
||||
Element *child;
|
||||
Element *object;
|
||||
|
||||
child = add_element (element, "child");
|
||||
set_attribute_value (child, "type", type);
|
||||
|
||||
object = add_element (child, "object");
|
||||
set_attribute_value (object, "class", "GtkBox");
|
||||
if (orientation == GTK_ORIENTATION_VERTICAL)
|
||||
write_box_prop (NULL, object, "orientation", "vertical");
|
||||
object->children = g_list_concat (object->children, children);
|
||||
|
||||
return child;
|
||||
}
|
||||
|
||||
static void
|
||||
rewrite_box (Element *element,
|
||||
MyParserData *data)
|
||||
{
|
||||
GList *start_children = NULL, *end_children = NULL, *other_children = NULL;
|
||||
Element *center_child = NULL;
|
||||
GList *l, *ll;
|
||||
GtkOrientation orientation = GTK_ORIENTATION_HORIZONTAL;
|
||||
|
||||
@ -1629,6 +1655,9 @@ rewrite_box (Element *element,
|
||||
Element *object = NULL;
|
||||
Element *packing = NULL;
|
||||
|
||||
GtkPackType pack_type = GTK_PACK_START;
|
||||
gint position = G_MAXINT;
|
||||
|
||||
for (ll = child->children; ll; ll = ll->next)
|
||||
{
|
||||
Element *elt2 = ll->data;
|
||||
@ -1693,6 +1722,30 @@ rewrite_box (Element *element,
|
||||
NULL))
|
||||
fill = g_value_get_boolean (&value);
|
||||
}
|
||||
|
||||
if (has_attribute (elt, "name", "position"))
|
||||
{
|
||||
GValue value = G_VALUE_INIT;
|
||||
|
||||
if (gtk_builder_value_from_string_type (data->builder,
|
||||
G_TYPE_INT,
|
||||
elt->data,
|
||||
&value,
|
||||
NULL))
|
||||
position = g_value_get_int (&value);
|
||||
}
|
||||
|
||||
if (has_attribute (elt, "name", "pack-type"))
|
||||
{
|
||||
GValue value = G_VALUE_INIT;
|
||||
|
||||
if (gtk_builder_value_from_string_type (data->builder,
|
||||
GTK_TYPE_PACK_TYPE,
|
||||
elt->data,
|
||||
&value,
|
||||
NULL))
|
||||
pack_type = g_value_get_enum (&value);
|
||||
}
|
||||
}
|
||||
|
||||
if (orientation == GTK_ORIENTATION_HORIZONTAL)
|
||||
@ -1713,8 +1766,49 @@ rewrite_box (Element *element,
|
||||
child->children = g_list_remove (child->children, packing);
|
||||
free_element (packing);
|
||||
}
|
||||
|
||||
if (has_attribute (child, "type", "center"))
|
||||
{
|
||||
if (center_child != NULL)
|
||||
g_warning (_ ("%s only accepts one center child"), get_class_name (element));
|
||||
center_child = child;
|
||||
}
|
||||
else if (pack_type == GTK_PACK_START)
|
||||
start_children = g_list_insert (start_children, child, position);
|
||||
else
|
||||
end_children = g_list_insert (end_children, child, position);
|
||||
}
|
||||
else
|
||||
other_children = g_list_append (other_children, child);
|
||||
}
|
||||
|
||||
end_children = g_list_reverse (end_children);
|
||||
|
||||
if (center_child || end_children)
|
||||
{
|
||||
set_attribute_value (element, "class", "GtkCenterBox");
|
||||
|
||||
l = NULL;
|
||||
if (start_children)
|
||||
{
|
||||
Element *child = rewrite_start_end_box_children (element, "start", orientation, start_children);
|
||||
l = g_list_append (l, child);
|
||||
}
|
||||
|
||||
if (center_child)
|
||||
l = g_list_append (l, center_child);
|
||||
|
||||
if (end_children)
|
||||
{
|
||||
Element *child = rewrite_start_end_box_children (element, "end", orientation, end_children);
|
||||
l = g_list_append (l, child);
|
||||
}
|
||||
}
|
||||
else
|
||||
l = start_children;
|
||||
|
||||
g_list_free (element->children);
|
||||
element->children = g_list_concat (other_children, l);
|
||||
}
|
||||
|
||||
static void
|
||||
@ -2138,19 +2232,6 @@ rewrite_element_3to4 (Element *element,
|
||||
{
|
||||
GList *l;
|
||||
|
||||
l = element->children;
|
||||
while (l)
|
||||
{
|
||||
GList *next = l->next;
|
||||
Element *child = l->data;
|
||||
if (rewrite_element_3to4 (child, data))
|
||||
{
|
||||
element->children = g_list_remove (element->children, child);
|
||||
free_element (child);
|
||||
}
|
||||
l = next;
|
||||
}
|
||||
|
||||
if (element_is_object_or_template (element) &&
|
||||
g_str_equal (get_class_name (element), "GtkStack"))
|
||||
rewrite_stack (element, data);
|
||||
@ -2216,6 +2297,19 @@ rewrite_element_3to4 (Element *element,
|
||||
if (g_str_equal (element->element_name, "requires"))
|
||||
rewrite_requires (element, data);
|
||||
|
||||
l = element->children;
|
||||
while (l)
|
||||
{
|
||||
GList *next = l->next;
|
||||
Element *child = l->data;
|
||||
if (rewrite_element_3to4 (child, data))
|
||||
{
|
||||
element->children = g_list_remove (element->children, child);
|
||||
free_element (child);
|
||||
}
|
||||
l = next;
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user