Compare commits
5 Commits
main
...
wip/otte/f
Author | SHA1 | Date | |
---|---|---|---|
|
bba54eeb71 | ||
|
fdfcc55ef1 | ||
|
d45985861e | ||
|
7f9604cf26 | ||
|
ba07082f3e |
@@ -128,6 +128,9 @@
|
||||
<file>gtkfishbowl.c</file>
|
||||
<file>gtkfishbowl.h</file>
|
||||
</gresource>
|
||||
<gresource prefix="/flipper">
|
||||
<file>flipper.ui</file>
|
||||
</gresource>
|
||||
<gresource prefix="/frames">
|
||||
<file>frames.ui</file>
|
||||
</gresource>
|
||||
@@ -278,6 +281,7 @@
|
||||
<file>filtermodel.c</file>
|
||||
<file>fishbowl.c</file>
|
||||
<file>fixed.c</file>
|
||||
<file>flipper.c</file>
|
||||
<file>flowbox.c</file>
|
||||
<file>frames.c</file>
|
||||
<file>font_features.c</file>
|
||||
|
34
demos/gtk-demo/flipper.c
Normal file
34
demos/gtk-demo/flipper.c
Normal file
@@ -0,0 +1,34 @@
|
||||
/* Flipper
|
||||
* #Keywords: Rotation, Rotate, Orientation
|
||||
*
|
||||
* Demonstrates the GtkFlipper widget, which makes it easy to apply orientation
|
||||
* changes to widgets.
|
||||
*/
|
||||
|
||||
#include <gtk/gtk.h>
|
||||
|
||||
GtkWidget *
|
||||
do_flipper (GtkWidget *do_widget)
|
||||
{
|
||||
static GtkWidget *window = NULL;
|
||||
|
||||
if (!window)
|
||||
{
|
||||
GtkBuilder *builder;
|
||||
|
||||
builder = gtk_builder_new_from_resource ("/flipper/flipper.ui");
|
||||
|
||||
window = GTK_WIDGET (gtk_builder_get_object (builder, "window"));
|
||||
gtk_window_set_display (GTK_WINDOW (window), gtk_widget_get_display (do_widget));
|
||||
g_object_add_weak_pointer (G_OBJECT (window), (gpointer *)&window);
|
||||
|
||||
g_object_unref (builder);
|
||||
}
|
||||
|
||||
if (!gtk_widget_get_visible (window))
|
||||
gtk_widget_show (window);
|
||||
else
|
||||
gtk_window_destroy (GTK_WINDOW (window));
|
||||
|
||||
return window;
|
||||
}
|
114
demos/gtk-demo/flipper.ui
Normal file
114
demos/gtk-demo/flipper.ui
Normal file
@@ -0,0 +1,114 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<interface>
|
||||
<object class="GtkWindow" id="window">
|
||||
<property name="title">Flipper</property>
|
||||
<child>
|
||||
<object class="GtkGrid">
|
||||
<property name="margin-top">10</property>
|
||||
<property name="margin-bottom">10</property>
|
||||
<property name="margin-start">10</property>
|
||||
<property name="margin-end">10</property>
|
||||
<child>
|
||||
<object class="GtkDropDown" id="content">
|
||||
<property name="model">
|
||||
<object class="GtkStringList">
|
||||
<items>
|
||||
<item>Picture</item>
|
||||
<item>Label</item>
|
||||
</items>
|
||||
</object>
|
||||
</property>
|
||||
<layout>
|
||||
<property name="row">0</property>
|
||||
<property name="column">0</property>
|
||||
</layout>
|
||||
</object>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkCheckButton" id="flip_h">
|
||||
<property name="label">Flip horizontally</property>
|
||||
<layout>
|
||||
<property name="row">1</property>
|
||||
<property name="column">0</property>
|
||||
</layout>
|
||||
</object>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkCheckButton" id="flip_v">
|
||||
<property name="label">Flip vertically</property>
|
||||
<layout>
|
||||
<property name="row">2</property>
|
||||
<property name="column">0</property>
|
||||
</layout>
|
||||
</object>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkCheckButton" id="rotate">
|
||||
<property name="label">Rotate</property>
|
||||
<layout>
|
||||
<property name="row">3</property>
|
||||
<property name="column">0</property>
|
||||
</layout>
|
||||
</object>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkLabel">
|
||||
<property name="vexpand">1</property>
|
||||
<layout>
|
||||
<property name="row">4</property>
|
||||
<property name="column">0</property>
|
||||
</layout>
|
||||
</object>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkStack">
|
||||
<binding name="visible-child-name">
|
||||
<lookup name='string' type='GtkStringObject'><lookup name='selected-item'>content</lookup></lookup>
|
||||
</binding>
|
||||
<child>
|
||||
<object class="GtkStackPage">
|
||||
<property name="name">Picture</property>
|
||||
<property name="child">
|
||||
<object class="GtkFlipper">
|
||||
<property name="flip-horizontal" bind-source="flip_h" bind-property="active"/>
|
||||
<property name="flip-vertical" bind-source="flip_v" bind-property="active"/>
|
||||
<property name="rotate" bind-source="rotate" bind-property="active"/>
|
||||
<property name="child">
|
||||
<object class="GtkPicture">
|
||||
<property name="file">resource:///css_blendmodes/ducky.png</property>
|
||||
</object>
|
||||
</property>
|
||||
</object>
|
||||
</property>
|
||||
</object>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkStackPage">
|
||||
<property name="name">Label</property>
|
||||
<property name="child">
|
||||
<object class="GtkFlipper">
|
||||
<property name="halign">fill</property>
|
||||
<property name="valign">fill</property>
|
||||
<property name="flip-horizontal" bind-source="flip_h" bind-property="active"/>
|
||||
<property name="flip-vertical" bind-source="flip_v" bind-property="active"/>
|
||||
<property name="rotate" bind-source="rotate" bind-property="active"/>
|
||||
<property name="child">
|
||||
<object class="GtkLabel">
|
||||
<property name="label">This is not a rubber duck!</property>
|
||||
</object>
|
||||
</property>
|
||||
</object>
|
||||
</property>
|
||||
</object>
|
||||
</child>
|
||||
<layout>
|
||||
<property name="row">0</property>
|
||||
<property name="column">1</property>
|
||||
<property name="row-span">5</property>
|
||||
</layout>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
</interface>
|
@@ -28,6 +28,7 @@ demos = files([
|
||||
'filtermodel.c',
|
||||
'fishbowl.c',
|
||||
'fixed.c',
|
||||
'flipper.c',
|
||||
'fontrendering.c',
|
||||
'frames.c',
|
||||
'gears.c',
|
||||
|
@@ -2938,7 +2938,7 @@ gsk_gl_render_job_visit_text_node (GskGLRenderJob *job,
|
||||
const PangoFont *font = gsk_text_node_get_font (node);
|
||||
const PangoGlyphInfo *glyphs = gsk_text_node_get_glyphs (node, NULL);
|
||||
const graphene_point_t *offset = gsk_text_node_get_offset (node);
|
||||
float text_scale = MAX (job->scale_x, job->scale_y); /* TODO: Fix for uneven scales? */
|
||||
float text_scale = MAX (fabs (job->scale_x), fabs (job->scale_y)); /* TODO: Fix for uneven scales? */
|
||||
guint num_glyphs = gsk_text_node_get_num_glyphs (node);
|
||||
float x = offset->x + job->offset_x;
|
||||
float y = offset->y + job->offset_y;
|
||||
|
@@ -94,6 +94,7 @@
|
||||
#include <gtk/gtkconstraintlayout.h>
|
||||
#include <gtk/gtkconstraint.h>
|
||||
#include <gtk/gtkcssprovider.h>
|
||||
#include <gtk/gtkcustomfilter.h>
|
||||
#include <gtk/gtkcustomlayout.h>
|
||||
#include <gtk/gtkcustomsorter.h>
|
||||
#include <gtk/gtkdebug.h>
|
||||
@@ -132,8 +133,8 @@
|
||||
#include <gtk/gtkfilefilter.h>
|
||||
#include <gtk/gtkfilter.h>
|
||||
#include <gtk/gtkfilterlistmodel.h>
|
||||
#include <gtk/gtkcustomfilter.h>
|
||||
#include <gtk/gtkflattenlistmodel.h>
|
||||
#include <gtk/gtkflipper.h>
|
||||
#include <gtk/gtkflowbox.h>
|
||||
#include <gtk/deprecated/gtkfontbutton.h>
|
||||
#include <gtk/deprecated/gtkfontchooser.h>
|
||||
|
544
gtk/gtkflipper.c
Normal file
544
gtk/gtkflipper.c
Normal file
@@ -0,0 +1,544 @@
|
||||
/*
|
||||
* Copyright © 2021 Benjamin Otte
|
||||
*
|
||||
* This library 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.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library 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 library. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Authors: Benjamin Otte <otte@gnome.org>
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include "gtkflipper.h"
|
||||
|
||||
#include <glib/gi18n-lib.h>
|
||||
#include "gtkprivate.h"
|
||||
|
||||
/**
|
||||
* GtkFlipper:
|
||||
*
|
||||
* `GtkFlipper` is a widget to flip or rotate a child widget.
|
||||
*
|
||||
* 
|
||||
*
|
||||
* Widgets can be flipped horiontally and vertically, and they can
|
||||
* be rotated. The properties of the flipper only allow rotating
|
||||
* clockwise by 90°, but flipping both horizontally and vertically
|
||||
* achieves a 180° rotation, so you can do that to achieve 180°
|
||||
* and 270° rotations.
|
||||
*
|
||||
* In technical terms this widget implements the dihedral group
|
||||
* [Dih4](https://en.wikipedia.org/wiki/Examples_of_groups#dihedral_group_of_order_8)
|
||||
* for the child widget.
|
||||
*
|
||||
* The order that operations on the child are performed when enabled is:
|
||||
*
|
||||
* * flip horizontally
|
||||
* * flip vertically
|
||||
* * rotate
|
||||
*
|
||||
* `GtkFlipper` was added in GTK 4.10.
|
||||
*/
|
||||
|
||||
struct _GtkFlipper
|
||||
{
|
||||
GtkWidget parent_instance;
|
||||
|
||||
GtkWidget *child;
|
||||
|
||||
guint flip_horizontal :1;
|
||||
guint flip_vertical :1;
|
||||
guint rotate :1;
|
||||
};
|
||||
|
||||
enum
|
||||
{
|
||||
PROP_0,
|
||||
PROP_CHILD,
|
||||
PROP_FLIP_HORIZONTAL,
|
||||
PROP_FLIP_VERTICAL,
|
||||
PROP_ROTATE,
|
||||
|
||||
N_PROPS
|
||||
};
|
||||
|
||||
G_DEFINE_TYPE (GtkFlipper, gtk_flipper, GTK_TYPE_WIDGET)
|
||||
|
||||
static GParamSpec *properties[N_PROPS] = { NULL, };
|
||||
|
||||
static GtkSizeRequestMode
|
||||
gtk_flipper_get_request_mode (GtkWidget *widget)
|
||||
{
|
||||
GtkFlipper *self = GTK_FLIPPER (widget);
|
||||
GtkSizeRequestMode mode;
|
||||
|
||||
if (!self->child)
|
||||
return GTK_SIZE_REQUEST_CONSTANT_SIZE;
|
||||
|
||||
mode = gtk_widget_get_request_mode (self->child);
|
||||
|
||||
if (!self->rotate)
|
||||
return mode;
|
||||
|
||||
switch (mode)
|
||||
{
|
||||
case GTK_SIZE_REQUEST_HEIGHT_FOR_WIDTH:
|
||||
return GTK_SIZE_REQUEST_WIDTH_FOR_HEIGHT;
|
||||
case GTK_SIZE_REQUEST_WIDTH_FOR_HEIGHT:
|
||||
return GTK_SIZE_REQUEST_HEIGHT_FOR_WIDTH;
|
||||
case GTK_SIZE_REQUEST_CONSTANT_SIZE:
|
||||
default:
|
||||
return mode;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
gtk_flipper_measure (GtkWidget *widget,
|
||||
GtkOrientation orientation,
|
||||
int for_size,
|
||||
int *minimum,
|
||||
int *natural,
|
||||
int *minimum_baseline,
|
||||
int *natural_baseline)
|
||||
{
|
||||
GtkFlipper *self = GTK_FLIPPER (widget);
|
||||
|
||||
if (self->rotate)
|
||||
orientation = OPPOSITE_ORIENTATION (orientation);
|
||||
|
||||
if (self->child && gtk_widget_get_visible (self->child))
|
||||
gtk_widget_measure (self->child,
|
||||
orientation,
|
||||
for_size,
|
||||
minimum, natural,
|
||||
minimum_baseline, natural_baseline);
|
||||
|
||||
if (self->rotate || self->flip_vertical)
|
||||
{
|
||||
*minimum_baseline = -1;
|
||||
*natural_baseline = -1;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
gtk_flipper_size_allocate (GtkWidget *widget,
|
||||
int width,
|
||||
int height,
|
||||
int baseline)
|
||||
{
|
||||
GtkFlipper *self = GTK_FLIPPER (widget);
|
||||
GskTransform *transform = NULL;
|
||||
|
||||
if (!self->child || !gtk_widget_get_visible (self->child))
|
||||
return;
|
||||
|
||||
if (self->flip_horizontal)
|
||||
{
|
||||
transform = gsk_transform_translate (transform, &GRAPHENE_POINT_INIT (width, 0));
|
||||
transform = gsk_transform_scale (transform, -1, 1);
|
||||
}
|
||||
|
||||
if (self->flip_vertical)
|
||||
{
|
||||
transform = gsk_transform_translate (transform, &GRAPHENE_POINT_INIT (0, height));
|
||||
transform = gsk_transform_scale (transform, 1, -1);
|
||||
baseline = -1;
|
||||
}
|
||||
|
||||
if (self->rotate)
|
||||
{
|
||||
int tmp = width;
|
||||
width = height;
|
||||
height = tmp;
|
||||
transform = gsk_transform_rotate (transform, 90);
|
||||
transform = gsk_transform_translate (transform, &GRAPHENE_POINT_INIT (0, -height));
|
||||
baseline = -1;
|
||||
}
|
||||
|
||||
gtk_widget_allocate (self->child, width, height, baseline, transform);
|
||||
}
|
||||
|
||||
static void
|
||||
gtk_flipper_compute_expand (GtkWidget *widget,
|
||||
gboolean *hexpand,
|
||||
gboolean *vexpand)
|
||||
{
|
||||
GtkFlipper *self = GTK_FLIPPER (widget);
|
||||
|
||||
if (self->child)
|
||||
{
|
||||
if (self->rotate)
|
||||
{
|
||||
*hexpand = gtk_widget_compute_expand (self->child, GTK_ORIENTATION_HORIZONTAL);
|
||||
*vexpand = gtk_widget_compute_expand (self->child, GTK_ORIENTATION_VERTICAL);
|
||||
}
|
||||
else
|
||||
{
|
||||
*hexpand = gtk_widget_compute_expand (self->child, GTK_ORIENTATION_VERTICAL);
|
||||
*vexpand = gtk_widget_compute_expand (self->child, GTK_ORIENTATION_HORIZONTAL);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
*hexpand = FALSE;
|
||||
*vexpand = FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
gtk_flipper_dispose (GObject *object)
|
||||
{
|
||||
GtkFlipper *self = GTK_FLIPPER (object);
|
||||
|
||||
g_clear_pointer (&self->child, gtk_widget_unparent);
|
||||
|
||||
G_OBJECT_CLASS (gtk_flipper_parent_class)->dispose (object);
|
||||
}
|
||||
|
||||
static void
|
||||
gtk_flipper_get_property (GObject *object,
|
||||
guint property_id,
|
||||
GValue *value,
|
||||
GParamSpec *pspec)
|
||||
{
|
||||
GtkFlipper *self = GTK_FLIPPER (object);
|
||||
|
||||
switch (property_id)
|
||||
{
|
||||
case PROP_CHILD:
|
||||
g_value_set_object (value, self->child);
|
||||
break;
|
||||
|
||||
case PROP_FLIP_HORIZONTAL:
|
||||
g_value_set_boolean (value, self->flip_horizontal);
|
||||
break;
|
||||
|
||||
case PROP_FLIP_VERTICAL:
|
||||
g_value_set_boolean (value, self->flip_vertical);
|
||||
break;
|
||||
|
||||
case PROP_ROTATE:
|
||||
g_value_set_boolean (value, self->rotate);
|
||||
break;
|
||||
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
gtk_flipper_set_property (GObject *object,
|
||||
guint property_id,
|
||||
const GValue *value,
|
||||
GParamSpec *pspec)
|
||||
{
|
||||
GtkFlipper *self = GTK_FLIPPER (object);
|
||||
|
||||
switch (property_id)
|
||||
{
|
||||
case PROP_CHILD:
|
||||
gtk_flipper_set_child (self, g_value_get_object (value));
|
||||
break;
|
||||
|
||||
case PROP_FLIP_HORIZONTAL:
|
||||
gtk_flipper_set_flip_horizontal (self, g_value_get_boolean (value));
|
||||
break;
|
||||
|
||||
case PROP_FLIP_VERTICAL:
|
||||
gtk_flipper_set_flip_vertical (self, g_value_get_boolean (value));
|
||||
break;
|
||||
|
||||
case PROP_ROTATE:
|
||||
gtk_flipper_set_rotate (self, g_value_get_boolean (value));
|
||||
break;
|
||||
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
gtk_flipper_class_init (GtkFlipperClass *klass)
|
||||
{
|
||||
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
|
||||
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
|
||||
|
||||
widget_class->get_request_mode = gtk_flipper_get_request_mode;
|
||||
widget_class->measure = gtk_flipper_measure;
|
||||
widget_class->size_allocate = gtk_flipper_size_allocate;
|
||||
widget_class->compute_expand = gtk_flipper_compute_expand;
|
||||
|
||||
gobject_class->dispose = gtk_flipper_dispose;
|
||||
gobject_class->get_property = gtk_flipper_get_property;
|
||||
gobject_class->set_property = gtk_flipper_set_property;
|
||||
|
||||
/**
|
||||
* GtkFlipper:child: (attributes org.gtk.Property.get=gtk_flipper_get_child org.gtk.Property.set=gtk_flipper_set_child)
|
||||
*
|
||||
* The child to display
|
||||
*/
|
||||
properties[PROP_CHILD] =
|
||||
g_param_spec_object ("child", NULL, NULL,
|
||||
GTK_TYPE_WIDGET,
|
||||
G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS);
|
||||
|
||||
/**
|
||||
* GtkFlipper:flip-horizontal: (attributes org.gtk.Property.get=gtk_flipper_get_flip_horizontal org.gtk.Property.set=gtk_flipper_set_flip_horizontal)
|
||||
*
|
||||
* If the flipper should automatically begin playing.
|
||||
*/
|
||||
properties[PROP_FLIP_HORIZONTAL] =
|
||||
g_param_spec_boolean ("flip-horizontal", NULL, NULL,
|
||||
FALSE,
|
||||
G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS);
|
||||
|
||||
/**
|
||||
* GtkFlipper:flip-vertical: (attributes org.gtk.Property.get=gtk_flipper_get_flip_vertical org.gtk.Property.set=gtk_flipper_set_flip_vertical)
|
||||
*
|
||||
* If the flipper should automatically begin playing.
|
||||
*/
|
||||
properties[PROP_FLIP_VERTICAL] =
|
||||
g_param_spec_boolean ("flip-vertical", NULL, NULL,
|
||||
FALSE,
|
||||
G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS);
|
||||
|
||||
/**
|
||||
* GtkFlipper:rotate: (attributes org.gtk.Property.get=gtk_flipper_get_rotate org.gtk.Property.set=gtk_flipper_set_rotate)
|
||||
*
|
||||
* Rotates the child by 90° if set. This is applied after any flipping.
|
||||
*/
|
||||
properties[PROP_ROTATE] =
|
||||
g_param_spec_boolean ("rotate", NULL, NULL,
|
||||
FALSE,
|
||||
G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS);
|
||||
|
||||
g_object_class_install_properties (gobject_class, N_PROPS, properties);
|
||||
|
||||
gtk_widget_class_set_css_name (widget_class, I_("flipper"));
|
||||
}
|
||||
|
||||
static void
|
||||
gtk_flipper_init (GtkFlipper *self)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* gtk_flipper_new:
|
||||
* @child (nullable): The child widget to display
|
||||
*
|
||||
* Creates a new `GtkFlipper` containing @child.
|
||||
*
|
||||
* Returns: a new `GtkFlipper`
|
||||
*
|
||||
* Since: 4.10
|
||||
*/
|
||||
GtkWidget *
|
||||
gtk_flipper_new (GtkWidget *child)
|
||||
{
|
||||
return g_object_new (GTK_TYPE_FLIPPER,
|
||||
"child", child,
|
||||
NULL);
|
||||
}
|
||||
|
||||
/**
|
||||
* gtk_flipper_get_child: (attributes org.gtk.Method.get_property=child)
|
||||
* @self: a `GtkFlipper`
|
||||
*
|
||||
* Returns the child of the flipper if one is set.
|
||||
*
|
||||
* Returns: (transfer none) (nullable): The child
|
||||
*
|
||||
* Since: 4.10
|
||||
*/
|
||||
GtkWidget *
|
||||
gtk_flipper_get_child (GtkFlipper *self)
|
||||
{
|
||||
g_return_val_if_fail (GTK_IS_FLIPPER (self), FALSE);
|
||||
|
||||
return self->child;
|
||||
}
|
||||
|
||||
/**
|
||||
* gtk_flipper_set_child: (attributes org.gtk.Method.set_property=child)
|
||||
* @self: a `GtkFlipper`
|
||||
* @child (nullable): the child to display
|
||||
*
|
||||
* Sets the child to display.
|
||||
*
|
||||
* Since: 4.10
|
||||
*/
|
||||
void
|
||||
gtk_flipper_set_child (GtkFlipper *self,
|
||||
GtkWidget *child)
|
||||
{
|
||||
g_return_if_fail (GTK_IS_FLIPPER (self));
|
||||
g_return_if_fail (child == NULL || GTK_IS_WIDGET (child));
|
||||
|
||||
if (self->child == child)
|
||||
return;
|
||||
|
||||
g_clear_pointer (&self->child, gtk_widget_unparent);
|
||||
|
||||
if (child)
|
||||
{
|
||||
self->child = child;
|
||||
gtk_widget_set_parent (self->child, GTK_WIDGET (self));
|
||||
}
|
||||
|
||||
gtk_widget_queue_resize (GTK_WIDGET (self));
|
||||
|
||||
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_CHILD]);
|
||||
}
|
||||
|
||||
/**
|
||||
* gtk_flipper_get_flip_horizontal: (attributes org.gtk.Method.get_property=flip-horizontal)
|
||||
* @self: a `GtkFlipper`
|
||||
*
|
||||
* Returns %TRUE if flipper should flip the child's left and right side.
|
||||
*
|
||||
* Returns: %TRUE if the child should flip horizontally
|
||||
*
|
||||
* Since: 4.10
|
||||
*/
|
||||
gboolean
|
||||
gtk_flipper_get_flip_horizontal (GtkFlipper *self)
|
||||
{
|
||||
g_return_val_if_fail (GTK_IS_FLIPPER (self), FALSE);
|
||||
|
||||
return self->flip_horizontal;
|
||||
}
|
||||
|
||||
/**
|
||||
* gtk_flipper_set_flip_horizontal: (attributes org.gtk.Method.set_property=flip-horizontal)
|
||||
* @self: a `GtkFlipper`
|
||||
* @flip_horizontal: whether the child should be flipped horizontal
|
||||
*
|
||||
* Sets whether the child should swap its left and right sides.
|
||||
*
|
||||
* The flipping is applied before rotating.
|
||||
*
|
||||
* Since: 4.10
|
||||
*/
|
||||
void
|
||||
gtk_flipper_set_flip_horizontal (GtkFlipper *self,
|
||||
gboolean flip_horizontal)
|
||||
{
|
||||
g_return_if_fail (GTK_IS_FLIPPER (self));
|
||||
|
||||
flip_horizontal = !!flip_horizontal;
|
||||
|
||||
if (self->flip_horizontal == flip_horizontal)
|
||||
return;
|
||||
|
||||
self->flip_horizontal = flip_horizontal;
|
||||
|
||||
gtk_widget_queue_allocate (GTK_WIDGET (self));
|
||||
|
||||
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_FLIP_HORIZONTAL]);
|
||||
}
|
||||
|
||||
/**
|
||||
* gtk_flipper_get_flip_vertical: (attributes org.gtk.Method.get_property=flip-vertical)
|
||||
* @self: a `GtkFlipper`
|
||||
*
|
||||
* Returns %TRUE if flipper should flip the child's top and bottom side.
|
||||
*
|
||||
* Returns: %TRUE if the child should flip vertically
|
||||
*
|
||||
* Since: 4.10
|
||||
*/
|
||||
gboolean
|
||||
gtk_flipper_get_flip_vertical (GtkFlipper *self)
|
||||
{
|
||||
g_return_val_if_fail (GTK_IS_FLIPPER (self), FALSE);
|
||||
|
||||
return self->flip_vertical;
|
||||
}
|
||||
|
||||
/**
|
||||
* gtk_flipper_set_flip_vertical: (attributes org.gtk.Method.set_property=flip-vertical)
|
||||
* @self: a `GtkFlipper`
|
||||
* @flip_vertical: whether the child should be flipped vertical
|
||||
*
|
||||
* Sets whether the child should swap its top and bottom sides.
|
||||
*
|
||||
* The flipping is applied before rotating.
|
||||
*
|
||||
* Since: 4.10
|
||||
*/
|
||||
void
|
||||
gtk_flipper_set_flip_vertical (GtkFlipper *self,
|
||||
gboolean flip_vertical)
|
||||
{
|
||||
g_return_if_fail (GTK_IS_FLIPPER (self));
|
||||
|
||||
flip_vertical = !!flip_vertical;
|
||||
|
||||
if (self->flip_vertical == flip_vertical)
|
||||
return;
|
||||
|
||||
self->flip_vertical = flip_vertical;
|
||||
|
||||
gtk_widget_queue_allocate (GTK_WIDGET (self));
|
||||
|
||||
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_FLIP_VERTICAL]);
|
||||
}
|
||||
|
||||
/**
|
||||
* gtk_flipper_get_rotate: (attributes org.gtk.Method.get_property=rotate)
|
||||
* @self: a `GtkFlipper`
|
||||
*
|
||||
* Returns %TRUE if flipper should rotate the child clockwise by 90°.
|
||||
*
|
||||
* Returns: %TRUE if the child should rotate
|
||||
*
|
||||
* Since: 4.10
|
||||
*/
|
||||
gboolean
|
||||
gtk_flipper_get_rotate (GtkFlipper *self)
|
||||
{
|
||||
g_return_val_if_fail (GTK_IS_FLIPPER (self), FALSE);
|
||||
|
||||
return self->rotate;
|
||||
}
|
||||
|
||||
/**
|
||||
* gtk_flipper_set_rotate: (attributes org.gtk.Method.set_property=rotate)
|
||||
* @self: a `GtkFlipper`
|
||||
* @rotate: whether the child should be rotated
|
||||
*
|
||||
* Sets whether the child should rotate the child clockwise by 90°.
|
||||
*
|
||||
* The rotation is done after any eventual flipping.
|
||||
*
|
||||
* Since: 4.10
|
||||
*/
|
||||
void
|
||||
gtk_flipper_set_rotate (GtkFlipper *self,
|
||||
gboolean rotate)
|
||||
{
|
||||
g_return_if_fail (GTK_IS_FLIPPER (self));
|
||||
|
||||
rotate = !!rotate;
|
||||
|
||||
if (self->rotate == rotate)
|
||||
return;
|
||||
|
||||
self->rotate = rotate;
|
||||
|
||||
gtk_widget_queue_resize (GTK_WIDGET (self));
|
||||
|
||||
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_ROTATE]);
|
||||
}
|
63
gtk/gtkflipper.h
Normal file
63
gtk/gtkflipper.h
Normal file
@@ -0,0 +1,63 @@
|
||||
/*
|
||||
* Copyright © 2021 Benjamin Otte
|
||||
*
|
||||
* This library 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.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library 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 library. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Authors: Benjamin Otte <otte@gnome.org>
|
||||
*/
|
||||
|
||||
#ifndef __GTK_FLIPPER_H__
|
||||
#define __GTK_FLIPPER_H__
|
||||
|
||||
#if !defined (__GTK_H_INSIDE__) && !defined (GTK_COMPILATION)
|
||||
#error "Only <gtk/gtk.h> can be included directly."
|
||||
#endif
|
||||
|
||||
#include <gtk/gtkwidget.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
#define GTK_TYPE_FLIPPER (gtk_flipper_get_type ())
|
||||
|
||||
GDK_AVAILABLE_IN_4_10
|
||||
G_DECLARE_FINAL_TYPE (GtkFlipper, gtk_flipper, GTK, FLIPPER, GtkWidget)
|
||||
|
||||
GDK_AVAILABLE_IN_4_10
|
||||
GtkWidget * gtk_flipper_new (GtkWidget *child);
|
||||
|
||||
GDK_AVAILABLE_IN_4_10
|
||||
GtkWidget * gtk_flipper_get_child (GtkFlipper *self);
|
||||
GDK_AVAILABLE_IN_4_10
|
||||
void gtk_flipper_set_child (GtkFlipper *self,
|
||||
GtkWidget *child);
|
||||
GDK_AVAILABLE_IN_4_10
|
||||
gboolean gtk_flipper_get_flip_horizontal (GtkFlipper *self);
|
||||
GDK_AVAILABLE_IN_4_10
|
||||
void gtk_flipper_set_flip_horizontal (GtkFlipper *self,
|
||||
gboolean flip_horizontal);
|
||||
GDK_AVAILABLE_IN_4_10
|
||||
gboolean gtk_flipper_get_flip_vertical (GtkFlipper *self);
|
||||
GDK_AVAILABLE_IN_4_10
|
||||
void gtk_flipper_set_flip_vertical (GtkFlipper *self,
|
||||
gboolean flip_vertical);
|
||||
GDK_AVAILABLE_IN_4_10
|
||||
gboolean gtk_flipper_get_rotate (GtkFlipper *self);
|
||||
GDK_AVAILABLE_IN_4_10
|
||||
void gtk_flipper_set_rotate (GtkFlipper *self,
|
||||
gboolean rotate);
|
||||
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* __GTK_FLIPPER_H__ */
|
@@ -232,6 +232,7 @@ gtk_public_sources = files([
|
||||
'gtkfixed.c',
|
||||
'gtkfixedlayout.c',
|
||||
'gtkflattenlistmodel.c',
|
||||
'gtkflipper.c',
|
||||
'gtkflowbox.c',
|
||||
'gtkfontchooserdialog.c',
|
||||
'gtkfontchooserutils.c',
|
||||
@@ -484,6 +485,7 @@ gtk_public_headers = files([
|
||||
'gtkfixed.h',
|
||||
'gtkfixedlayout.h',
|
||||
'gtkflattenlistmodel.h',
|
||||
'gtkflipper.h',
|
||||
'gtkflowbox.h',
|
||||
'gtkfontdialog.h',
|
||||
'gtkfontdialogbutton.h',
|
||||
|
Reference in New Issue
Block a user