Compare commits
12 Commits
async-dial
...
center-box
Author | SHA1 | Date | |
---|---|---|---|
|
dc6c27fb88 | ||
|
ebabb4bf30 | ||
|
1c17f382a5 | ||
|
35d8c85667 | ||
|
9b1f4b4a90 | ||
|
149c2cc3d8 | ||
|
b095bf05c2 | ||
|
cd43686289 | ||
|
3dc7e71c32 | ||
|
433082f050 | ||
|
81049ea5c5 | ||
|
4c90d61c05 |
@@ -68,6 +68,7 @@
|
|||||||
<chapter id="LayoutContainers">
|
<chapter id="LayoutContainers">
|
||||||
<title>Layout Containers</title>
|
<title>Layout Containers</title>
|
||||||
<xi:include href="xml/gtkbox.xml" />
|
<xi:include href="xml/gtkbox.xml" />
|
||||||
|
<xi:include href="xml/gtkcenterbox.xml" />
|
||||||
<xi:include href="xml/gtkgrid.xml" />
|
<xi:include href="xml/gtkgrid.xml" />
|
||||||
<xi:include href="xml/gtkrevealer.xml" />
|
<xi:include href="xml/gtkrevealer.xml" />
|
||||||
<xi:include href="xml/gtklistbox.xml" />
|
<xi:include href="xml/gtklistbox.xml" />
|
||||||
|
@@ -341,6 +341,26 @@ GtkBoxPrivate
|
|||||||
gtk_box_get_type
|
gtk_box_get_type
|
||||||
</SECTION>
|
</SECTION>
|
||||||
|
|
||||||
|
<SECTION>
|
||||||
|
<FILE>gtkcenterbox</FILE>
|
||||||
|
<TITLE>GtkCenterBox</TITLE>
|
||||||
|
GtkCenterBox
|
||||||
|
gtk_center_box_new
|
||||||
|
gtk_center_box_set_start_widget
|
||||||
|
gtk_center_box_set_center_widget
|
||||||
|
gtk_center_box_set_end_widget
|
||||||
|
gtk_center_box_get_start_widget
|
||||||
|
gtk_center_box_get_center_widget
|
||||||
|
gtk_center_box_get_end_widget
|
||||||
|
<PRIVATE>
|
||||||
|
GTK_TYPE_CENTER_BOX
|
||||||
|
GTK_CENTER_BOX
|
||||||
|
GTK_CENTER_BOX_CLASS
|
||||||
|
GTK_IS_CENTER_BOX
|
||||||
|
GTK_IS_CENTER_BOX_CLASS
|
||||||
|
GTK_CENTER_BOX_GET_CLASS
|
||||||
|
</SECTION>
|
||||||
|
|
||||||
<SECTION>
|
<SECTION>
|
||||||
<FILE>gtklistbox</FILE>
|
<FILE>gtklistbox</FILE>
|
||||||
<TITLE>GtkListBox</TITLE>
|
<TITLE>GtkListBox</TITLE>
|
||||||
|
@@ -68,6 +68,7 @@
|
|||||||
#include <gtk/gtkcellrenderertext.h>
|
#include <gtk/gtkcellrenderertext.h>
|
||||||
#include <gtk/gtkcellrenderertoggle.h>
|
#include <gtk/gtkcellrenderertoggle.h>
|
||||||
#include <gtk/gtkcellview.h>
|
#include <gtk/gtkcellview.h>
|
||||||
|
#include <gtk/gtkcenterbox.h>
|
||||||
#include <gtk/gtkcheckbutton.h>
|
#include <gtk/gtkcheckbutton.h>
|
||||||
#include <gtk/gtkcheckmenuitem.h>
|
#include <gtk/gtkcheckmenuitem.h>
|
||||||
#include <gtk/gtkclipboard.h>
|
#include <gtk/gtkclipboard.h>
|
||||||
|
@@ -30,7 +30,7 @@
|
|||||||
#include "gtkwidgetprivate.h"
|
#include "gtkwidgetprivate.h"
|
||||||
#include "gtkcontainerprivate.h"
|
#include "gtkcontainerprivate.h"
|
||||||
#include "gtkprivate.h"
|
#include "gtkprivate.h"
|
||||||
#include "gtkcenterboxprivate.h"
|
#include "gtkcenterbox.h"
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
|
@@ -1,8 +1,309 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2017 Timm Bäder <mail@baedert.org>
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 2 of the License, or (at your
|
||||||
|
* option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful, but
|
||||||
|
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||||
|
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
|
||||||
|
* License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with this program; if not, write to the Free Software Foundation,
|
||||||
|
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
*
|
||||||
|
* Author: Timm Bäder <mail@baedert.org>
|
||||||
|
*/
|
||||||
|
|
||||||
#include "gtkcenterboxprivate.h"
|
/**
|
||||||
|
* SECTION:gtkcenterbox
|
||||||
|
* @Short_description: A centering container
|
||||||
|
* @Title: GtkCenterBox
|
||||||
|
* @See_also: #GtkBox
|
||||||
|
*
|
||||||
|
* The GtkCenterBox widget will arrange three children in a horizontal
|
||||||
|
* or vertical arrangement, keeping the middle child centered as well
|
||||||
|
* as possible.
|
||||||
|
*/
|
||||||
|
|
||||||
G_DEFINE_TYPE (GtkCenterBox, gtk_center_box, GTK_TYPE_WIDGET);
|
#include "config.h"
|
||||||
|
#include "gtkcenterbox.h"
|
||||||
|
#include "gtkcssnodeprivate.h"
|
||||||
|
#include "gtkwidgetprivate.h"
|
||||||
|
#include "gtkorientable.h"
|
||||||
|
#include "gtkorientableprivate.h"
|
||||||
|
#include "gtkbuildable.h"
|
||||||
|
#include "gtksizerequest.h"
|
||||||
|
|
||||||
|
struct _GtkCenterBox
|
||||||
|
{
|
||||||
|
GtkWidget parent_instance;
|
||||||
|
|
||||||
|
GtkWidget *start_widget;
|
||||||
|
GtkWidget *center_widget;
|
||||||
|
GtkWidget *end_widget;
|
||||||
|
|
||||||
|
GtkOrientation orientation;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct _GtkCenterBoxClass
|
||||||
|
{
|
||||||
|
GtkWidgetClass parent_class;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
enum {
|
||||||
|
PROP_0,
|
||||||
|
PROP_ORIENTATION
|
||||||
|
};
|
||||||
|
|
||||||
|
static void gtk_center_box_buildable_init (GtkBuildableIface *iface);
|
||||||
|
|
||||||
|
G_DEFINE_TYPE_WITH_CODE (GtkCenterBox, gtk_center_box, GTK_TYPE_WIDGET,
|
||||||
|
G_IMPLEMENT_INTERFACE (GTK_TYPE_ORIENTABLE, NULL)
|
||||||
|
G_IMPLEMENT_INTERFACE (GTK_TYPE_BUILDABLE, gtk_center_box_buildable_init))
|
||||||
|
|
||||||
|
static void
|
||||||
|
gtk_center_box_buildable_add_child (GtkBuildable *buildable,
|
||||||
|
GtkBuilder *builder,
|
||||||
|
GObject *child,
|
||||||
|
const gchar *type)
|
||||||
|
{
|
||||||
|
if (g_strcmp0 (type, "start") == 0)
|
||||||
|
gtk_center_box_set_start_widget (GTK_CENTER_BOX (buildable), GTK_WIDGET (child));
|
||||||
|
else if (g_strcmp0 (type, "center") == 0)
|
||||||
|
gtk_center_box_set_center_widget (GTK_CENTER_BOX (buildable), GTK_WIDGET (child));
|
||||||
|
else if (g_strcmp0 (type, "end") == 0)
|
||||||
|
gtk_center_box_set_end_widget (GTK_CENTER_BOX (buildable), GTK_WIDGET (child));
|
||||||
|
else
|
||||||
|
GTK_BUILDER_WARN_INVALID_CHILD_TYPE (GTK_CENTER_BOX (buildable), type);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
gtk_center_box_buildable_init (GtkBuildableIface *iface)
|
||||||
|
{
|
||||||
|
iface->add_child = gtk_center_box_buildable_add_child;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
gtk_center_box_distribute (GtkCenterBox *self,
|
||||||
|
gint for_size,
|
||||||
|
gint size,
|
||||||
|
GtkRequestedSize *sizes)
|
||||||
|
{
|
||||||
|
int center_size = 0;
|
||||||
|
int start_size = 0;
|
||||||
|
int end_size = 0;
|
||||||
|
gboolean center_expand = FALSE;
|
||||||
|
gboolean start_expand = FALSE;
|
||||||
|
gboolean end_expand = FALSE;
|
||||||
|
int avail;
|
||||||
|
|
||||||
|
sizes[0].minimum_size = sizes[0].natural_size = 0;
|
||||||
|
sizes[1].minimum_size = sizes[1].natural_size = 0;
|
||||||
|
sizes[2].minimum_size = sizes[2].natural_size = 0;
|
||||||
|
|
||||||
|
if (self->start_widget)
|
||||||
|
gtk_widget_measure (self->start_widget,
|
||||||
|
self->orientation,
|
||||||
|
for_size,
|
||||||
|
&sizes[0].minimum_size, &sizes[0].natural_size,
|
||||||
|
NULL, NULL);
|
||||||
|
|
||||||
|
if (self->center_widget)
|
||||||
|
gtk_widget_measure (self->center_widget,
|
||||||
|
self->orientation,
|
||||||
|
for_size,
|
||||||
|
&sizes[1].minimum_size, &sizes[1].natural_size,
|
||||||
|
NULL, NULL);
|
||||||
|
|
||||||
|
|
||||||
|
if (self->end_widget)
|
||||||
|
gtk_widget_measure (self->end_widget,
|
||||||
|
self->orientation,
|
||||||
|
for_size,
|
||||||
|
&sizes[2].minimum_size, &sizes[2].natural_size,
|
||||||
|
NULL, NULL);
|
||||||
|
|
||||||
|
if (self->center_widget)
|
||||||
|
{
|
||||||
|
center_size = CLAMP (size - (sizes[0].minimum_size + sizes[2].minimum_size), sizes[1].minimum_size, sizes[1].natural_size);
|
||||||
|
center_expand = gtk_widget_get_hexpand (self->center_widget);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (self->start_widget)
|
||||||
|
{
|
||||||
|
avail = MIN ((size - center_size) / 2, size - (center_size + sizes[2].minimum_size));
|
||||||
|
start_size = CLAMP (avail, sizes[0].minimum_size, sizes[0].natural_size);
|
||||||
|
start_expand = gtk_widget_get_hexpand (self->start_widget);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (self->end_widget)
|
||||||
|
{
|
||||||
|
avail = MIN ((size - center_size) / 2, size - (center_size + sizes[0].minimum_size));
|
||||||
|
end_size = CLAMP (avail, sizes[2].minimum_size, sizes[2].natural_size);
|
||||||
|
end_expand = gtk_widget_get_hexpand (self->end_widget);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (self->center_widget)
|
||||||
|
{
|
||||||
|
int center_pos;
|
||||||
|
|
||||||
|
center_pos = (size / 2) - (center_size / 2);
|
||||||
|
|
||||||
|
/* Push in from start/end */
|
||||||
|
if (start_size > center_pos)
|
||||||
|
center_pos = start_size;
|
||||||
|
else if (size - end_size < center_pos + center_size)
|
||||||
|
center_pos = size - center_size - end_size;
|
||||||
|
else if (center_expand)
|
||||||
|
{
|
||||||
|
center_size = size - 2 * MAX (start_size, end_size);
|
||||||
|
center_pos = (size / 2) - (center_size / 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (start_expand)
|
||||||
|
start_size = center_pos;
|
||||||
|
|
||||||
|
if (end_expand)
|
||||||
|
end_size = size - center_pos + center_size;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
avail = size - (start_size + end_size);
|
||||||
|
if (start_expand && end_expand)
|
||||||
|
{
|
||||||
|
start_size += avail / 2;
|
||||||
|
end_size += avail / 2;
|
||||||
|
}
|
||||||
|
else if (start_expand)
|
||||||
|
{
|
||||||
|
start_size += avail;
|
||||||
|
}
|
||||||
|
else if (end_expand)
|
||||||
|
{
|
||||||
|
end_size += avail;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
sizes[0].minimum_size = start_size;
|
||||||
|
sizes[1].minimum_size = center_size;
|
||||||
|
sizes[2].minimum_size = end_size;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
gtk_center_box_measure_orientation (GtkWidget *widget,
|
||||||
|
GtkOrientation orientation,
|
||||||
|
int for_size,
|
||||||
|
int *minimum,
|
||||||
|
int *natural,
|
||||||
|
int *minimum_baseline,
|
||||||
|
int *natural_baseline)
|
||||||
|
{
|
||||||
|
GtkCenterBox *self = GTK_CENTER_BOX (widget);
|
||||||
|
int min_baseline, nat_baseline;
|
||||||
|
int start_min = 0;
|
||||||
|
int start_nat = 0;
|
||||||
|
int center_min = 0;
|
||||||
|
int center_nat = 0;
|
||||||
|
int end_min = 0;
|
||||||
|
int end_nat = 0;
|
||||||
|
|
||||||
|
if (self->start_widget)
|
||||||
|
gtk_widget_measure (self->start_widget,
|
||||||
|
orientation,
|
||||||
|
for_size,
|
||||||
|
&start_min, &start_nat,
|
||||||
|
&min_baseline, &nat_baseline);
|
||||||
|
|
||||||
|
if (self->center_widget)
|
||||||
|
gtk_widget_measure (self->center_widget,
|
||||||
|
orientation,
|
||||||
|
for_size,
|
||||||
|
¢er_min, ¢er_nat,
|
||||||
|
&min_baseline, &nat_baseline);
|
||||||
|
|
||||||
|
if (self->end_widget)
|
||||||
|
gtk_widget_measure (self->end_widget,
|
||||||
|
orientation,
|
||||||
|
for_size,
|
||||||
|
&end_min, &end_nat,
|
||||||
|
&min_baseline, &nat_baseline);
|
||||||
|
|
||||||
|
*minimum = start_min + center_min + end_min;
|
||||||
|
*natural = center_nat + 2 * MAX (start_nat, end_nat);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
gtk_center_box_measure_opposite (GtkWidget *widget,
|
||||||
|
GtkOrientation orientation,
|
||||||
|
int for_size,
|
||||||
|
int *minimum,
|
||||||
|
int *natural,
|
||||||
|
int *minimum_baseline,
|
||||||
|
int *natural_baseline)
|
||||||
|
{
|
||||||
|
GtkCenterBox *self = GTK_CENTER_BOX (widget);
|
||||||
|
int child_min, child_nat;
|
||||||
|
int child_min_baseline, child_nat_baseline;
|
||||||
|
int total_min, above_min, below_min;
|
||||||
|
int total_nat, above_nat, below_nat;
|
||||||
|
GtkWidget *child[3];
|
||||||
|
GtkRequestedSize sizes[3];
|
||||||
|
int i;
|
||||||
|
|
||||||
|
child[0] = self->start_widget;
|
||||||
|
child[1] = self->center_widget;
|
||||||
|
child[2] = self->end_widget;
|
||||||
|
|
||||||
|
if (for_size >= 0)
|
||||||
|
gtk_center_box_distribute (self, -1, for_size, sizes);
|
||||||
|
|
||||||
|
above_min = below_min = above_nat = below_nat = -1;
|
||||||
|
total_min = total_nat = 0;
|
||||||
|
|
||||||
|
for (i = 0; i < 3; i++)
|
||||||
|
{
|
||||||
|
if (child[i] == NULL)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
gtk_widget_measure (child[i],
|
||||||
|
orientation,
|
||||||
|
for_size >= 0 ? sizes[i].minimum_size : -1,
|
||||||
|
&child_min, &child_nat,
|
||||||
|
&child_min_baseline, &child_nat_baseline);
|
||||||
|
|
||||||
|
if (child_min_baseline >= 0)
|
||||||
|
{
|
||||||
|
below_min = MAX (below_min, child_min - child_min_baseline);
|
||||||
|
above_min = MAX (above_min, child_min_baseline);
|
||||||
|
below_nat = MAX (below_nat, child_nat - child_nat_baseline);
|
||||||
|
above_nat = MAX (above_nat, child_nat_baseline);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
total_min = MAX (total_min, child_min);
|
||||||
|
total_nat = MAX (total_nat, child_nat);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (above_min >= 0)
|
||||||
|
{
|
||||||
|
total_min = MAX (total_min, above_min + below_min);
|
||||||
|
total_nat = MAX (total_nat, above_nat + below_nat);
|
||||||
|
/* assume GTK_BASELINE_POSITION_CENTER for now */
|
||||||
|
if (minimum_baseline)
|
||||||
|
*minimum_baseline = above_min + (total_min - (above_min + below_min)) / 2;
|
||||||
|
if (natural_baseline)
|
||||||
|
*natural_baseline = above_nat + (total_nat - (above_nat + below_nat)) / 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
*minimum = total_min;
|
||||||
|
*natural = total_nat;
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
gtk_center_box_measure (GtkWidget *widget,
|
gtk_center_box_measure (GtkWidget *widget,
|
||||||
@@ -14,53 +315,11 @@ gtk_center_box_measure (GtkWidget *widget,
|
|||||||
int *natural_baseline)
|
int *natural_baseline)
|
||||||
{
|
{
|
||||||
GtkCenterBox *self = GTK_CENTER_BOX (widget);
|
GtkCenterBox *self = GTK_CENTER_BOX (widget);
|
||||||
int min, nat, min_baseline, nat_baseline;
|
|
||||||
|
|
||||||
gtk_widget_measure (self->start_widget,
|
|
||||||
orientation,
|
|
||||||
for_size,
|
|
||||||
minimum, natural,
|
|
||||||
minimum_baseline, natural_baseline);
|
|
||||||
|
|
||||||
if (self->center_widget)
|
|
||||||
{
|
|
||||||
gtk_widget_measure (self->center_widget,
|
|
||||||
orientation,
|
|
||||||
for_size,
|
|
||||||
&min, &nat,
|
|
||||||
&min_baseline, &nat_baseline);
|
|
||||||
|
|
||||||
/* XXX How are baselines even handled? */
|
|
||||||
|
|
||||||
if (orientation == GTK_ORIENTATION_HORIZONTAL)
|
|
||||||
{
|
|
||||||
*minimum = *minimum + min;
|
|
||||||
*natural = *natural + nat;
|
|
||||||
}
|
|
||||||
else /* GTK_ORIENTATION_VERTICAL */
|
|
||||||
{
|
|
||||||
*minimum = MAX (*minimum, min);
|
|
||||||
*natural = MAX (*minimum, nat);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
gtk_widget_measure (self->end_widget,
|
|
||||||
orientation,
|
|
||||||
for_size,
|
|
||||||
&min, &nat,
|
|
||||||
&min_baseline, &nat_baseline);
|
|
||||||
|
|
||||||
if (orientation == GTK_ORIENTATION_HORIZONTAL)
|
|
||||||
{
|
|
||||||
*minimum = *minimum + min;
|
|
||||||
*natural = *natural + nat;
|
|
||||||
}
|
|
||||||
else /* GTK_ORIENTATION_VERTICAL */
|
|
||||||
{
|
|
||||||
*minimum = MAX (*minimum, min);
|
|
||||||
*natural = MAX (*minimum, nat);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
if (self->orientation == orientation)
|
||||||
|
gtk_center_box_measure_orientation (widget, orientation, for_size, minimum, natural, minimum_baseline, natural_baseline);
|
||||||
|
else
|
||||||
|
gtk_center_box_measure_opposite (widget, orientation, for_size, minimum, natural, minimum_baseline, natural_baseline);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@@ -71,60 +330,89 @@ gtk_center_box_size_allocate (GtkWidget *widget,
|
|||||||
GtkAllocation child_allocation;
|
GtkAllocation child_allocation;
|
||||||
GtkAllocation clip = *allocation;
|
GtkAllocation clip = *allocation;
|
||||||
GtkAllocation child_clip;
|
GtkAllocation child_clip;
|
||||||
int start_size, end_size;
|
GtkWidget *child[3];
|
||||||
int min, nat;
|
int child_size[3];
|
||||||
|
int child_pos[3];
|
||||||
|
GtkRequestedSize sizes[3];
|
||||||
|
int size;
|
||||||
|
int for_size;
|
||||||
|
int baseline;
|
||||||
|
int i;
|
||||||
|
|
||||||
GTK_WIDGET_CLASS (gtk_center_box_parent_class)->size_allocate (widget, allocation);
|
GTK_WIDGET_CLASS (gtk_center_box_parent_class)->size_allocate (widget, allocation);
|
||||||
|
|
||||||
|
if (self->orientation == GTK_ORIENTATION_HORIZONTAL)
|
||||||
// TODO: Allocate natural sizes if possible?
|
|
||||||
|
|
||||||
/* Start Box */
|
|
||||||
gtk_widget_measure (self->start_widget, GTK_ORIENTATION_HORIZONTAL,
|
|
||||||
allocation->height,
|
|
||||||
&min, &nat, NULL, NULL);
|
|
||||||
child_allocation.x = allocation->x;
|
|
||||||
child_allocation.y = allocation->y;
|
|
||||||
child_allocation.width = min;
|
|
||||||
child_allocation.height = allocation->height;
|
|
||||||
|
|
||||||
gtk_widget_size_allocate (self->start_widget, &child_allocation);
|
|
||||||
gtk_widget_get_clip (self->start_widget, &child_clip);
|
|
||||||
gdk_rectangle_union (&clip, &clip, &child_clip);
|
|
||||||
start_size = child_allocation.width;
|
|
||||||
|
|
||||||
|
|
||||||
/* End Box */
|
|
||||||
gtk_widget_measure (self->end_widget, GTK_ORIENTATION_HORIZONTAL,
|
|
||||||
allocation->height,
|
|
||||||
&min, &nat, NULL, NULL);
|
|
||||||
child_allocation.x = allocation->x + allocation->width - min;
|
|
||||||
child_allocation.width = min;
|
|
||||||
|
|
||||||
gtk_widget_size_allocate (self->end_widget, &child_allocation);
|
|
||||||
gtk_widget_get_clip (self->end_widget, &child_clip);
|
|
||||||
gdk_rectangle_union (&clip, &clip, &child_clip);
|
|
||||||
end_size = child_allocation.width;
|
|
||||||
|
|
||||||
/* Center Widget */
|
|
||||||
if (self->center_widget)
|
|
||||||
{
|
{
|
||||||
gtk_widget_measure (self->center_widget, GTK_ORIENTATION_HORIZONTAL,
|
size = allocation->width;
|
||||||
allocation->height,
|
for_size = allocation->height;
|
||||||
&min, &nat, NULL, NULL);
|
baseline = gtk_widget_get_allocated_baseline (widget);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
size = allocation->height;
|
||||||
|
for_size = allocation->width;
|
||||||
|
baseline = -1;
|
||||||
|
}
|
||||||
|
|
||||||
child_allocation.x = (allocation->width / 2) - (min / 2);
|
gtk_center_box_distribute (self, for_size, size, sizes);
|
||||||
|
|
||||||
|
if (self->orientation == GTK_ORIENTATION_HORIZONTAL &&
|
||||||
|
gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
|
||||||
|
{
|
||||||
|
child[0] = self->end_widget;
|
||||||
|
child[1] = self->center_widget;
|
||||||
|
child[2] = self->start_widget;
|
||||||
|
child_size[0] = sizes[2].minimum_size;
|
||||||
|
child_size[1] = sizes[1].minimum_size;
|
||||||
|
child_size[2] = sizes[0].minimum_size;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
child[0] = self->start_widget;
|
||||||
|
child[1] = self->center_widget;
|
||||||
|
child[2] = self->end_widget;
|
||||||
|
child_size[0] = sizes[0].minimum_size;
|
||||||
|
child_size[1] = sizes[1].minimum_size;
|
||||||
|
child_size[2] = sizes[2].minimum_size;
|
||||||
|
}
|
||||||
|
|
||||||
|
child_pos[0] = 0;
|
||||||
|
child_pos[1] = (size / 2) - (child_size[1] / 2);
|
||||||
|
child_pos[2] = size - child_size[2];
|
||||||
|
|
||||||
|
if (child[1])
|
||||||
|
{
|
||||||
/* Push in from start/end */
|
/* Push in from start/end */
|
||||||
if (start_size > child_allocation.x)
|
if (child_size[0] > child_pos[1])
|
||||||
child_allocation.x = start_size;
|
child_pos[1] = child_size[0];
|
||||||
else if (allocation->width - end_size < child_allocation.x + min)
|
else if (size - child_size[2] < child_pos[1] + child_size[1])
|
||||||
child_allocation.x = allocation->width - min - end_size;
|
child_pos[1] = size - child_size[1] - child_size[2];
|
||||||
|
}
|
||||||
|
|
||||||
child_allocation.x += allocation->x;
|
child_allocation = *allocation;
|
||||||
child_allocation.width = min;
|
|
||||||
gtk_widget_size_allocate (self->center_widget, &child_allocation);
|
for (i = 0; i < 3; i++)
|
||||||
gtk_widget_get_clip (self->center_widget, &child_clip);
|
{
|
||||||
|
if (child[i] == NULL)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if (self->orientation == GTK_ORIENTATION_HORIZONTAL)
|
||||||
|
{
|
||||||
|
child_allocation.x = allocation->x + child_pos[i];
|
||||||
|
child_allocation.y = allocation->y;
|
||||||
|
child_allocation.width = child_size[i];
|
||||||
|
child_allocation.height = allocation->height;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
child_allocation.x = allocation->x;
|
||||||
|
child_allocation.y = allocation->y + child_pos[i];
|
||||||
|
child_allocation.width = allocation->width;
|
||||||
|
child_allocation.height = child_size[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
gtk_widget_size_allocate_with_baseline (child[i], &child_allocation, baseline);
|
||||||
|
gtk_widget_get_clip (child[i], &child_clip);
|
||||||
gdk_rectangle_union (&clip, &clip, &child_clip);
|
gdk_rectangle_union (&clip, &clip, &child_clip);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -137,22 +425,141 @@ gtk_center_box_snapshot (GtkWidget *widget,
|
|||||||
{
|
{
|
||||||
GtkCenterBox *self = GTK_CENTER_BOX (widget);
|
GtkCenterBox *self = GTK_CENTER_BOX (widget);
|
||||||
|
|
||||||
|
if (self->start_widget)
|
||||||
gtk_widget_snapshot_child (widget, self->start_widget, snapshot);
|
gtk_widget_snapshot_child (widget, self->start_widget, snapshot);
|
||||||
|
|
||||||
if (self->center_widget)
|
if (self->center_widget)
|
||||||
gtk_widget_snapshot_child (widget, self->center_widget, snapshot);
|
gtk_widget_snapshot_child (widget, self->center_widget, snapshot);
|
||||||
|
|
||||||
|
if (self->end_widget)
|
||||||
gtk_widget_snapshot_child (widget, self->end_widget, snapshot);
|
gtk_widget_snapshot_child (widget, self->end_widget, snapshot);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
update_css_node_order (GtkCenterBox *self)
|
||||||
|
{
|
||||||
|
GtkCssNode *parent;
|
||||||
|
GtkCssNode *first;
|
||||||
|
GtkCssNode *last;
|
||||||
|
|
||||||
|
parent = gtk_widget_get_css_node (GTK_WIDGET (self));
|
||||||
|
|
||||||
|
if (gtk_widget_get_direction (GTK_WIDGET (self)) == GTK_TEXT_DIR_LTR)
|
||||||
|
{
|
||||||
|
first = self->start_widget ? gtk_widget_get_css_node (self->start_widget) : NULL;
|
||||||
|
last = self->end_widget ? gtk_widget_get_css_node (self->end_widget) : NULL;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
first = self->end_widget ? gtk_widget_get_css_node (self->end_widget) : NULL;
|
||||||
|
last = self->start_widget ? gtk_widget_get_css_node (self->start_widget) : NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (first)
|
||||||
|
gtk_css_node_insert_after (parent, first, NULL);
|
||||||
|
if (last)
|
||||||
|
gtk_css_node_insert_before (parent, last, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
gtk_center_box_direction_changed (GtkWidget *widget,
|
||||||
|
GtkTextDirection previous_direction)
|
||||||
|
{
|
||||||
|
update_css_node_order (GTK_CENTER_BOX (widget));
|
||||||
|
}
|
||||||
|
|
||||||
|
static GtkSizeRequestMode
|
||||||
|
gtk_center_box_get_request_mode (GtkWidget *widget)
|
||||||
|
{
|
||||||
|
GtkCenterBox *self = GTK_CENTER_BOX (widget);
|
||||||
|
gint count[3] = { 0, 0, 0 };
|
||||||
|
|
||||||
|
if (self->start_widget)
|
||||||
|
count[gtk_widget_get_request_mode (self->start_widget)]++;
|
||||||
|
|
||||||
|
if (self->center_widget)
|
||||||
|
count[gtk_widget_get_request_mode (self->center_widget)]++;
|
||||||
|
|
||||||
|
if (self->end_widget)
|
||||||
|
count[gtk_widget_get_request_mode (self->end_widget)]++;
|
||||||
|
|
||||||
|
if (!count[GTK_SIZE_REQUEST_HEIGHT_FOR_WIDTH] &&
|
||||||
|
!count[GTK_SIZE_REQUEST_WIDTH_FOR_HEIGHT])
|
||||||
|
return GTK_SIZE_REQUEST_CONSTANT_SIZE;
|
||||||
|
else
|
||||||
|
return count[GTK_SIZE_REQUEST_WIDTH_FOR_HEIGHT] > count[GTK_SIZE_REQUEST_HEIGHT_FOR_WIDTH]
|
||||||
|
? GTK_SIZE_REQUEST_WIDTH_FOR_HEIGHT
|
||||||
|
: GTK_SIZE_REQUEST_HEIGHT_FOR_WIDTH;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
gtk_center_box_set_property (GObject *object,
|
||||||
|
guint prop_id,
|
||||||
|
const GValue *value,
|
||||||
|
GParamSpec *pspec)
|
||||||
|
{
|
||||||
|
GtkCenterBox *self = GTK_CENTER_BOX (object);
|
||||||
|
|
||||||
|
switch (prop_id)
|
||||||
|
{
|
||||||
|
case PROP_ORIENTATION:
|
||||||
|
{
|
||||||
|
GtkOrientation orientation = g_value_get_enum (value);
|
||||||
|
if (self->orientation != orientation)
|
||||||
|
{
|
||||||
|
self->orientation = orientation;
|
||||||
|
_gtk_orientable_set_style_classes (GTK_ORIENTABLE (self));
|
||||||
|
gtk_widget_queue_resize (GTK_WIDGET (self));
|
||||||
|
g_object_notify (object, "orientation");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
gtk_center_box_get_property (GObject *object,
|
||||||
|
guint prop_id,
|
||||||
|
GValue *value,
|
||||||
|
GParamSpec *pspec)
|
||||||
|
{
|
||||||
|
GtkCenterBox *self = GTK_CENTER_BOX (object);
|
||||||
|
|
||||||
|
switch (prop_id)
|
||||||
|
{
|
||||||
|
case PROP_ORIENTATION:
|
||||||
|
g_value_set_enum (value, self->orientation);
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
gtk_center_box_class_init (GtkCenterBoxClass *klass)
|
gtk_center_box_class_init (GtkCenterBoxClass *klass)
|
||||||
{
|
{
|
||||||
|
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
||||||
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
|
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
|
||||||
|
|
||||||
|
object_class->set_property = gtk_center_box_set_property;
|
||||||
|
object_class->get_property = gtk_center_box_get_property;
|
||||||
|
|
||||||
widget_class->measure = gtk_center_box_measure;
|
widget_class->measure = gtk_center_box_measure;
|
||||||
widget_class->size_allocate = gtk_center_box_size_allocate;
|
widget_class->size_allocate = gtk_center_box_size_allocate;
|
||||||
widget_class->snapshot = gtk_center_box_snapshot;
|
widget_class->snapshot = gtk_center_box_snapshot;
|
||||||
|
widget_class->direction_changed = gtk_center_box_direction_changed;
|
||||||
|
widget_class->get_request_mode = gtk_center_box_get_request_mode;
|
||||||
|
|
||||||
|
g_object_class_override_property (object_class, PROP_ORIENTATION, "orientation");
|
||||||
|
|
||||||
|
gtk_widget_class_set_accessible_role (widget_class, ATK_ROLE_FILLER);
|
||||||
|
gtk_widget_class_set_css_name (widget_class, "box");
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@@ -163,14 +570,34 @@ gtk_center_box_init (GtkCenterBox *self)
|
|||||||
self->start_widget = NULL;
|
self->start_widget = NULL;
|
||||||
self->center_widget = NULL;
|
self->center_widget = NULL;
|
||||||
self->end_widget = NULL;
|
self->end_widget = NULL;
|
||||||
|
|
||||||
|
self->orientation = GTK_ORIENTATION_HORIZONTAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* gtk_center_box_new:
|
||||||
|
*
|
||||||
|
* Creates a new #GtkCenterBox.
|
||||||
|
*
|
||||||
|
* Returns: the new #GtkCenterBox.
|
||||||
|
*
|
||||||
|
* Since: 3.92
|
||||||
|
*/
|
||||||
GtkWidget *
|
GtkWidget *
|
||||||
gtk_center_box_new (void)
|
gtk_center_box_new (void)
|
||||||
{
|
{
|
||||||
return GTK_WIDGET (g_object_new (GTK_TYPE_CENTER_BOX, NULL));
|
return GTK_WIDGET (g_object_new (GTK_TYPE_CENTER_BOX, NULL));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* gtk_center_box_set_start_widget:
|
||||||
|
* @self: a #GtkCenterBox
|
||||||
|
* @child: the child
|
||||||
|
*
|
||||||
|
* Sets the start widget.
|
||||||
|
*
|
||||||
|
* Since: 3.92
|
||||||
|
*/
|
||||||
void
|
void
|
||||||
gtk_center_box_set_start_widget (GtkCenterBox *self,
|
gtk_center_box_set_start_widget (GtkCenterBox *self,
|
||||||
GtkWidget *child)
|
GtkWidget *child)
|
||||||
@@ -181,8 +608,19 @@ gtk_center_box_set_start_widget (GtkCenterBox *self,
|
|||||||
self->start_widget = child;
|
self->start_widget = child;
|
||||||
if (child)
|
if (child)
|
||||||
gtk_widget_set_parent (child, GTK_WIDGET (self));
|
gtk_widget_set_parent (child, GTK_WIDGET (self));
|
||||||
|
|
||||||
|
update_css_node_order (self);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* gtk_center_box_set_center_widget:
|
||||||
|
* @self: a #GtkCenterBox
|
||||||
|
* @child: the child
|
||||||
|
*
|
||||||
|
* Sets the center widget.
|
||||||
|
*
|
||||||
|
* Since: 3.92
|
||||||
|
*/
|
||||||
void
|
void
|
||||||
gtk_center_box_set_center_widget (GtkCenterBox *self,
|
gtk_center_box_set_center_widget (GtkCenterBox *self,
|
||||||
GtkWidget *child)
|
GtkWidget *child)
|
||||||
@@ -193,8 +631,19 @@ gtk_center_box_set_center_widget (GtkCenterBox *self,
|
|||||||
self->center_widget = child;
|
self->center_widget = child;
|
||||||
if (child)
|
if (child)
|
||||||
gtk_widget_set_parent (child, GTK_WIDGET (self));
|
gtk_widget_set_parent (child, GTK_WIDGET (self));
|
||||||
|
|
||||||
|
update_css_node_order (self);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* gtk_center_box_set_end_widget:
|
||||||
|
* @self: a #GtkCenterBox
|
||||||
|
* @child: the child
|
||||||
|
*
|
||||||
|
* Sets the end widget.
|
||||||
|
*
|
||||||
|
* Since: 3.92
|
||||||
|
*/
|
||||||
void
|
void
|
||||||
gtk_center_box_set_end_widget (GtkCenterBox *self,
|
gtk_center_box_set_end_widget (GtkCenterBox *self,
|
||||||
GtkWidget *child)
|
GtkWidget *child)
|
||||||
@@ -205,20 +654,52 @@ gtk_center_box_set_end_widget (GtkCenterBox *self,
|
|||||||
self->end_widget = child;
|
self->end_widget = child;
|
||||||
if (child)
|
if (child)
|
||||||
gtk_widget_set_parent (child, GTK_WIDGET (self));
|
gtk_widget_set_parent (child, GTK_WIDGET (self));
|
||||||
|
|
||||||
|
update_css_node_order (self);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* gtk_center_box_get_start_widget:
|
||||||
|
* @self: a #GtkCenterBox
|
||||||
|
*
|
||||||
|
* Gets the start widget.
|
||||||
|
*
|
||||||
|
* Returns: the start widget.
|
||||||
|
*
|
||||||
|
* Since: 3.92
|
||||||
|
*/
|
||||||
GtkWidget *
|
GtkWidget *
|
||||||
gtk_center_box_get_start_widget (GtkCenterBox *self)
|
gtk_center_box_get_start_widget (GtkCenterBox *self)
|
||||||
{
|
{
|
||||||
return self->start_widget;
|
return self->start_widget;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* gtk_center_box_get_center_widget:
|
||||||
|
* @self: a #GtkCenterBox
|
||||||
|
*
|
||||||
|
* Gets the center widget.
|
||||||
|
*
|
||||||
|
* Returns: the center widget.
|
||||||
|
*
|
||||||
|
* Since: 3.92
|
||||||
|
*/
|
||||||
GtkWidget *
|
GtkWidget *
|
||||||
gtk_center_box_get_center_widget (GtkCenterBox *self)
|
gtk_center_box_get_center_widget (GtkCenterBox *self)
|
||||||
{
|
{
|
||||||
return self->center_widget;
|
return self->center_widget;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* gtk_center_box_get_end_widget:
|
||||||
|
* @self: a #GtkCenterBox
|
||||||
|
*
|
||||||
|
* Gets the end widget.
|
||||||
|
*
|
||||||
|
* Returns: the end widget.
|
||||||
|
*
|
||||||
|
* Since: 3.92
|
||||||
|
*/
|
||||||
GtkWidget *
|
GtkWidget *
|
||||||
gtk_center_box_get_end_widget (GtkCenterBox *self)
|
gtk_center_box_get_end_widget (GtkCenterBox *self)
|
||||||
{
|
{
|
||||||
|
60
gtk/gtkcenterbox.h
Normal file
60
gtk/gtkcenterbox.h
Normal file
@@ -0,0 +1,60 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2017 Timm Bäder <mail@baedert.org>
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 2 of the License, or (at your
|
||||||
|
* option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful, but
|
||||||
|
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||||
|
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
|
||||||
|
* License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with this program; if not, write to the Free Software Foundation,
|
||||||
|
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
*
|
||||||
|
* Author: Timm Bäder <mail@baedert.org>
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __GTK_CENTER_BOX_H__
|
||||||
|
#define __GTK_CENTER_BOX_H__
|
||||||
|
|
||||||
|
#include "gtkwidget.h"
|
||||||
|
|
||||||
|
#define GTK_TYPE_CENTER_BOX (gtk_center_box_get_type ())
|
||||||
|
#define GTK_CENTER_BOX(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_CENTER_BOX, GtkCenterBox))
|
||||||
|
#define GTK_CENTER_BOX_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GTK_TYPE_CENTER_BOX, GtkCenterBoxClass))
|
||||||
|
#define GTK_IS_CENTER_BOX(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_CENTER_BOX))
|
||||||
|
#define GTK_IS_CENTER_BOX_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_TYPE_CENTER_BOX))
|
||||||
|
#define GTK_CENTER_BOX_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_CENTER_BOX, GtkCenterBoxClass))
|
||||||
|
|
||||||
|
typedef struct _GtkCenterBox GtkCenterBox;
|
||||||
|
typedef struct _GtkCenterBoxClass GtkCenterBoxClass;
|
||||||
|
|
||||||
|
GDK_AVAILABLE_IN_3_92
|
||||||
|
GType gtk_center_box_get_type (void) G_GNUC_CONST;
|
||||||
|
|
||||||
|
GDK_AVAILABLE_IN_3_92
|
||||||
|
GtkWidget *gtk_center_box_new (void);
|
||||||
|
GDK_AVAILABLE_IN_3_92
|
||||||
|
void gtk_center_box_set_start_widget (GtkCenterBox *self,
|
||||||
|
GtkWidget *child);
|
||||||
|
GDK_AVAILABLE_IN_3_92
|
||||||
|
void gtk_center_box_set_center_widget (GtkCenterBox *self,
|
||||||
|
GtkWidget *child);
|
||||||
|
GDK_AVAILABLE_IN_3_92
|
||||||
|
void gtk_center_box_set_end_widget (GtkCenterBox *self,
|
||||||
|
GtkWidget *child);
|
||||||
|
|
||||||
|
GDK_AVAILABLE_IN_3_92
|
||||||
|
GtkWidget * gtk_center_box_get_start_widget (GtkCenterBox *self);
|
||||||
|
GDK_AVAILABLE_IN_3_92
|
||||||
|
GtkWidget * gtk_center_box_get_center_widget (GtkCenterBox *self);
|
||||||
|
GDK_AVAILABLE_IN_3_92
|
||||||
|
GtkWidget * gtk_center_box_get_end_widget (GtkCenterBox *self);
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
@@ -1,43 +0,0 @@
|
|||||||
|
|
||||||
#ifndef __GTK_CENTER_BOX_H__
|
|
||||||
#define __GTK_CENTER_BOX_H__
|
|
||||||
|
|
||||||
#include "gtkwidget.h"
|
|
||||||
|
|
||||||
#define GTK_TYPE_CENTER_BOX (gtk_center_box_get_type ())
|
|
||||||
#define GTK_CENTER_BOX(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_CENTER_BOX, GtkCenterBox))
|
|
||||||
#define GTK_CENTER_BOX_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GTK_TYPE_CENTER_BOX, GtkCenterBoxClass))
|
|
||||||
#define GTK_IS_CENTER_BOX(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_CENTER_BOX))
|
|
||||||
#define GTK_IS_CENTER_BOX_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_TYPE_CENTER_BOX))
|
|
||||||
#define GTK_CENTER_BOX_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_CENTER_BOX, GtkCenterBoxClass))
|
|
||||||
|
|
||||||
typedef struct _GtkCenterBox GtkCenterBox;
|
|
||||||
typedef struct _GtkCenterBoxClass GtkCenterBoxClass;
|
|
||||||
|
|
||||||
struct _GtkCenterBox
|
|
||||||
{
|
|
||||||
GtkWidget parent_instance;
|
|
||||||
|
|
||||||
GtkWidget *start_widget;
|
|
||||||
GtkWidget *center_widget;
|
|
||||||
GtkWidget *end_widget;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct _GtkCenterBoxClass
|
|
||||||
{
|
|
||||||
GtkWidgetClass parent_class;
|
|
||||||
};
|
|
||||||
|
|
||||||
GType gtk_center_box_get_type (void) G_GNUC_CONST;
|
|
||||||
|
|
||||||
GtkWidget *gtk_center_box_new (void);
|
|
||||||
void gtk_center_box_set_start_widget (GtkCenterBox *self, GtkWidget *child);
|
|
||||||
void gtk_center_box_set_center_widget (GtkCenterBox *self, GtkWidget *child);
|
|
||||||
void gtk_center_box_set_end_widget (GtkCenterBox *self, GtkWidget *child);
|
|
||||||
|
|
||||||
GtkWidget * gtk_center_box_get_start_widget (GtkCenterBox *self);
|
|
||||||
GtkWidget * gtk_center_box_get_center_widget (GtkCenterBox *self);
|
|
||||||
GtkWidget * gtk_center_box_get_end_widget (GtkCenterBox *self);
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
|
@@ -157,6 +157,7 @@ noinst_PROGRAMS = $(TEST_PROGS) \
|
|||||||
testpopupat \
|
testpopupat \
|
||||||
testgaction \
|
testgaction \
|
||||||
testwidgetfocus \
|
testwidgetfocus \
|
||||||
|
testcenterbox \
|
||||||
$(NULL)
|
$(NULL)
|
||||||
|
|
||||||
if USE_X11
|
if USE_X11
|
||||||
@@ -270,6 +271,7 @@ testtitlebar_DEPENDENCIES = $(TEST_DEPS)
|
|||||||
testwindowsize_DEPENDENCIES = $(TEST_DEPS)
|
testwindowsize_DEPENDENCIES = $(TEST_DEPS)
|
||||||
listmodel_DEPENDENCIES = $(TEST_DEPS)
|
listmodel_DEPENDENCIES = $(TEST_DEPS)
|
||||||
testwidgetfocus_DEPENDENCIES = $(TEST_DEPS)
|
testwidgetfocus_DEPENDENCIES = $(TEST_DEPS)
|
||||||
|
testcenterbox_DEPENDENCIES = $(TEST_DEPS)
|
||||||
|
|
||||||
animated_resizing_SOURCES = \
|
animated_resizing_SOURCES = \
|
||||||
animated-resizing.c \
|
animated-resizing.c \
|
||||||
@@ -461,6 +463,8 @@ listmodel_SOURCES = listmodel.c
|
|||||||
|
|
||||||
testwidgetfocus_SOURCES = testwidgetfocus.c
|
testwidgetfocus_SOURCES = testwidgetfocus.c
|
||||||
|
|
||||||
|
testcenterbox_SOURCES = testcenterbox.c
|
||||||
|
|
||||||
EXTRA_DIST += \
|
EXTRA_DIST += \
|
||||||
gradient1.png \
|
gradient1.png \
|
||||||
testgtk.1 \
|
testgtk.1 \
|
||||||
|
@@ -127,6 +127,8 @@ gtk_tests = [
|
|||||||
['testpopup'],
|
['testpopup'],
|
||||||
['testpopupat'],
|
['testpopupat'],
|
||||||
['testgaction'],
|
['testgaction'],
|
||||||
|
['testwidgetfocus'],
|
||||||
|
['testcenterbox'],
|
||||||
]
|
]
|
||||||
|
|
||||||
if os_linux
|
if os_linux
|
||||||
|
36
tests/testcenterbox.c
Normal file
36
tests/testcenterbox.c
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
#include <gtk/gtk.h>
|
||||||
|
|
||||||
|
int
|
||||||
|
main (int argc, char *argv[])
|
||||||
|
{
|
||||||
|
GtkWidget *window;
|
||||||
|
GtkWidget *box;
|
||||||
|
GtkWidget *child;
|
||||||
|
|
||||||
|
gtk_init ();
|
||||||
|
|
||||||
|
if (g_getenv ("RTL"))
|
||||||
|
gtk_widget_set_default_direction (GTK_TEXT_DIR_RTL);
|
||||||
|
|
||||||
|
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
|
||||||
|
box = gtk_center_box_new ();
|
||||||
|
gtk_container_add (GTK_CONTAINER (window), box);
|
||||||
|
|
||||||
|
child = gtk_label_new ("Start Start Start Start Start");
|
||||||
|
gtk_label_set_ellipsize (GTK_LABEL (child), PANGO_ELLIPSIZE_END);
|
||||||
|
gtk_center_box_set_start_widget (GTK_CENTER_BOX (box), child);
|
||||||
|
|
||||||
|
child = gtk_label_new ("Center");
|
||||||
|
gtk_label_set_ellipsize (GTK_LABEL (child), PANGO_ELLIPSIZE_END);
|
||||||
|
gtk_center_box_set_center_widget (GTK_CENTER_BOX (box), child);
|
||||||
|
|
||||||
|
child = gtk_label_new ("End");
|
||||||
|
gtk_label_set_ellipsize (GTK_LABEL (child), PANGO_ELLIPSIZE_END);
|
||||||
|
gtk_center_box_set_end_widget (GTK_CENTER_BOX (box), child);
|
||||||
|
|
||||||
|
gtk_widget_show (window);
|
||||||
|
|
||||||
|
gtk_main ();
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
Reference in New Issue
Block a user