/* canvas-layout.c generated by valac 0.56.19, the Vala compiler
 * generated from canvas-layout.vala, do not modify */

/*
 * Copyright (c) 2025 focus-timer contributors
 *
 * SPDX-License-Identifier: GPL-3.0-or-later
 *
 * Authors: Kamil Prusko <kamilprusko@gmail.com>
 */

#include <gtk/gtk.h>
#include <graphene-gobject.h>
#include <gdk/gdk.h>
#include <glib.h>
#include <float.h>
#include <math.h>
#include "ft_ui.h"
#include <string.h>
#include <cairo-gobject.h>
#include <glib-object.h>

#define FT_CANVAS_LAYOUT_EPSILON 0.00001
#if !defined(VALA_STRICT_C)
#if !defined(__clang__) && defined(__GNUC__) && (__GNUC__ >= 14)
#pragma GCC diagnostic warning "-Wincompatible-pointer-types"
#elif defined(__clang__) && (__clang_major__ >= 16)
#pragma clang diagnostic ignored "-Wincompatible-function-pointer-types"
#pragma clang diagnostic ignored "-Wincompatible-pointer-types"
#endif
#endif

typedef struct _FtCanvasLayoutChild FtCanvasLayoutChild;
typedef struct _FtCanvasLayoutChildClass FtCanvasLayoutChildClass;
typedef struct _FtCanvasLayoutChildPrivate FtCanvasLayoutChildPrivate;
enum  {
	FT_CANVAS_LAYOUT_CHILD_0_PROPERTY,
	FT_CANVAS_LAYOUT_CHILD_X_PROPERTY,
	FT_CANVAS_LAYOUT_CHILD_Y_PROPERTY,
	FT_CANVAS_LAYOUT_CHILD_X_ORIGIN_PROPERTY,
	FT_CANVAS_LAYOUT_CHILD_Y_ORIGIN_PROPERTY,
	FT_CANVAS_LAYOUT_CHILD_NUM_PROPERTIES
};
static GParamSpec* ft_canvas_layout_child_properties[FT_CANVAS_LAYOUT_CHILD_NUM_PROPERTIES];
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
typedef struct _FtCanvasLayout FtCanvasLayout;
typedef struct _FtCanvasLayoutClass FtCanvasLayoutClass;
typedef struct _FtCanvasLayoutPrivate FtCanvasLayoutPrivate;
enum  {
	FT_CANVAS_LAYOUT_0_PROPERTY,
	FT_CANVAS_LAYOUT_NUM_PROPERTIES
};
static GParamSpec* ft_canvas_layout_properties[FT_CANVAS_LAYOUT_NUM_PROPERTIES];
typedef struct _FtCanvas FtCanvas;
typedef struct _FtCanvasClass FtCanvasClass;

struct _FtCanvasLayoutChild {
	GtkLayoutChild parent_instance;
	FtCanvasLayoutChildPrivate * priv;
	graphene_rect_t range;
	GdkRectangle absolute_bounds;
};

struct _FtCanvasLayoutChildClass {
	GtkLayoutChildClass parent_class;
};

struct _FtCanvasLayoutChildPrivate {
	gfloat _x;
	gfloat _y;
	gint _x_origin;
	gint _y_origin;
};

struct _FtCanvasLayout {
	GtkLayoutManager parent_instance;
	FtCanvasLayoutPrivate * priv;
};

struct _FtCanvasLayoutClass {
	GtkLayoutManagerClass parent_class;
};

static gint FtCanvasLayoutChild_private_offset;
static gpointer ft_canvas_layout_child_parent_class = NULL;
static gpointer ft_canvas_layout_parent_class = NULL;

static void ft_canvas_layout_child_finalize (GObject * obj);
static GType ft_canvas_layout_child_get_type_once (void);
static void _vala_ft_canvas_layout_child_get_property (GObject * object,
                                                guint property_id,
                                                GValue * value,
                                                GParamSpec * pspec);
static void _vala_ft_canvas_layout_child_set_property (GObject * object,
                                                guint property_id,
                                                const GValue * value,
                                                GParamSpec * pspec);
static inline void ft_canvas_layout_calculate_child_bounds (FtCanvasLayout* self,
                                              FtCanvasLayoutChild* child,
                                              gfloat x_scale,
                                              gfloat y_scale,
                                              GdkRectangle* result);
static void ft_canvas_layout_calculate_bounds (FtCanvasLayout* self,
                                        GtkWidget* widget,
                                        GdkRectangle* result);
static inline gint ft_canvas_layout_calculate_width (FtCanvasLayout* self,
                                       GtkWidget* widget);
static inline gint ft_canvas_layout_calculate_height (FtCanvasLayout* self,
                                        GtkWidget* widget);
static GtkLayoutChild* ft_canvas_layout_real_create_layout_child (GtkLayoutManager* base,
                                                           GtkWidget* widget,
                                                           GtkWidget* for_child);
static GtkSizeRequestMode ft_canvas_layout_real_get_request_mode (GtkLayoutManager* base,
                                                           GtkWidget* widget);
static void ft_canvas_layout_real_measure (GtkLayoutManager* base,
                                    GtkWidget* widget,
                                    GtkOrientation orientation,
                                    gint for_size,
                                    gint* minimum,
                                    gint* natural,
                                    gint* minimum_baseline,
                                    gint* natural_baseline);
static void ft_canvas_layout_real_allocate (GtkLayoutManager* base,
                                     GtkWidget* widget,
                                     gint width,
                                     gint height,
                                     gint baseline);
VALA_EXTERN void ft_canvas_update_origin (FtCanvas* self);
static GType ft_canvas_layout_get_type_once (void);

static inline gpointer
ft_canvas_layout_child_get_instance_private (FtCanvasLayoutChild* self)
{
	return G_STRUCT_MEMBER_P (self, FtCanvasLayoutChild_private_offset);
}

/**
         * Calculate widget's bounds. The bounds position is in relative units from its origin.
         */
static gpointer
_g_object_ref0 (gpointer self)
{
	return self ? g_object_ref (self) : NULL;
}

void
ft_canvas_layout_child_calculate_bounds (FtCanvasLayoutChild* self,
                                         GdkRectangle* result)
{
	GdkRectangle bounds = {0};
	gint _tmp0_;
	gint _tmp1_;
	GdkRectangle _tmp2_ = {0};
	GtkWidget* widget = NULL;
	GtkWidget* _tmp3_;
	GtkWidget* _tmp4_;
	GtkWidget* _tmp5_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->_x_origin;
	_tmp1_ = self->priv->_y_origin;
	memset (&_tmp2_, 0, sizeof (GdkRectangle));
	_tmp2_.x = -_tmp0_;
	_tmp2_.y = -_tmp1_;
	_tmp2_.width = 0;
	_tmp2_.height = 0;
	bounds = _tmp2_;
	_tmp3_ = gtk_layout_child_get_child_widget ((GtkLayoutChild*) self);
	_tmp4_ = _g_object_ref0 (_tmp3_);
	widget = _tmp4_;
	_tmp5_ = widget;
	if (_tmp5_ != NULL) {
		GtkWidget* _tmp6_;
		gint _tmp7_ = 0;
		GtkWidget* _tmp8_;
		gint _tmp9_ = 0;
		_tmp6_ = widget;
		gtk_widget_measure (_tmp6_, GTK_ORIENTATION_HORIZONTAL, -1, NULL, &_tmp7_, NULL, NULL);
		bounds.width = _tmp7_;
		_tmp8_ = widget;
		gtk_widget_measure (_tmp8_, GTK_ORIENTATION_VERTICAL, -1, NULL, &_tmp9_, NULL, NULL);
		bounds.height = _tmp9_;
	}
	*result = bounds;
	_g_object_unref0 (widget);
	return;
}

void
ft_canvas_layout_child_set_range (FtCanvasLayoutChild* self,
                                  gfloat x_from,
                                  gfloat x_to,
                                  gfloat y_from,
                                  gfloat y_to)
{
	g_return_if_fail (self != NULL);
	memset (&self->range, 0, sizeof (graphene_rect_t));
	graphene_rect_init (&self->range, x_from, y_from, x_to - x_from, y_to - y_from);
}

FtCanvasLayoutChild*
ft_canvas_layout_child_construct (GType object_type)
{
	FtCanvasLayoutChild * self = NULL;
	self = (FtCanvasLayoutChild*) g_object_new (object_type, NULL);
	return self;
}

FtCanvasLayoutChild*
ft_canvas_layout_child_new (void)
{
	return ft_canvas_layout_child_construct (FT_TYPE_CANVAS_LAYOUT_CHILD);
}

gfloat
ft_canvas_layout_child_get_x (FtCanvasLayoutChild* self)
{
	gfloat result;
	g_return_val_if_fail (self != NULL, -1.0F);
	result = self->priv->_x;
	return result;
}

void
ft_canvas_layout_child_set_x (FtCanvasLayoutChild* self,
                              gfloat value)
{
	gfloat old_value;
	g_return_if_fail (self != NULL);
	old_value = ft_canvas_layout_child_get_x (self);
	if (old_value != value) {
		self->priv->_x = value;
		g_object_notify_by_pspec ((GObject *) self, ft_canvas_layout_child_properties[FT_CANVAS_LAYOUT_CHILD_X_PROPERTY]);
	}
}

gfloat
ft_canvas_layout_child_get_y (FtCanvasLayoutChild* self)
{
	gfloat result;
	g_return_val_if_fail (self != NULL, -1.0F);
	result = self->priv->_y;
	return result;
}

void
ft_canvas_layout_child_set_y (FtCanvasLayoutChild* self,
                              gfloat value)
{
	gfloat old_value;
	g_return_if_fail (self != NULL);
	old_value = ft_canvas_layout_child_get_y (self);
	if (old_value != value) {
		self->priv->_y = value;
		g_object_notify_by_pspec ((GObject *) self, ft_canvas_layout_child_properties[FT_CANVAS_LAYOUT_CHILD_Y_PROPERTY]);
	}
}

gint
ft_canvas_layout_child_get_x_origin (FtCanvasLayoutChild* self)
{
	gint result;
	g_return_val_if_fail (self != NULL, -1);
	result = self->priv->_x_origin;
	return result;
}

void
ft_canvas_layout_child_set_x_origin (FtCanvasLayoutChild* self,
                                     gint value)
{
	gint old_value;
	g_return_if_fail (self != NULL);
	old_value = ft_canvas_layout_child_get_x_origin (self);
	if (old_value != value) {
		self->priv->_x_origin = value;
		g_object_notify_by_pspec ((GObject *) self, ft_canvas_layout_child_properties[FT_CANVAS_LAYOUT_CHILD_X_ORIGIN_PROPERTY]);
	}
}

gint
ft_canvas_layout_child_get_y_origin (FtCanvasLayoutChild* self)
{
	gint result;
	g_return_val_if_fail (self != NULL, -1);
	result = self->priv->_y_origin;
	return result;
}

void
ft_canvas_layout_child_set_y_origin (FtCanvasLayoutChild* self,
                                     gint value)
{
	gint old_value;
	g_return_if_fail (self != NULL);
	old_value = ft_canvas_layout_child_get_y_origin (self);
	if (old_value != value) {
		self->priv->_y_origin = value;
		g_object_notify_by_pspec ((GObject *) self, ft_canvas_layout_child_properties[FT_CANVAS_LAYOUT_CHILD_Y_ORIGIN_PROPERTY]);
	}
}

static void
ft_canvas_layout_child_class_init (FtCanvasLayoutChildClass * klass,
                                   gpointer klass_data)
{
	ft_canvas_layout_child_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &FtCanvasLayoutChild_private_offset);
	G_OBJECT_CLASS (klass)->get_property = _vala_ft_canvas_layout_child_get_property;
	G_OBJECT_CLASS (klass)->set_property = _vala_ft_canvas_layout_child_set_property;
	G_OBJECT_CLASS (klass)->finalize = ft_canvas_layout_child_finalize;
	/**
	         * Absolute position in the value space.
	         */
	g_object_class_install_property (G_OBJECT_CLASS (klass), FT_CANVAS_LAYOUT_CHILD_X_PROPERTY, ft_canvas_layout_child_properties[FT_CANVAS_LAYOUT_CHILD_X_PROPERTY] = g_param_spec_float ("x", "x", "x", -G_MAXFLOAT, G_MAXFLOAT, 0.0f, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE));
	/**
	         * Absolute position in the value space.
	         */
	g_object_class_install_property (G_OBJECT_CLASS (klass), FT_CANVAS_LAYOUT_CHILD_Y_PROPERTY, ft_canvas_layout_child_properties[FT_CANVAS_LAYOUT_CHILD_Y_PROPERTY] = g_param_spec_float ("y", "y", "y", -G_MAXFLOAT, G_MAXFLOAT, 0.0f, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE));
	/**
	         * Offset from the widget's top-left corner in pixels.
	         */
	g_object_class_install_property (G_OBJECT_CLASS (klass), FT_CANVAS_LAYOUT_CHILD_X_ORIGIN_PROPERTY, ft_canvas_layout_child_properties[FT_CANVAS_LAYOUT_CHILD_X_ORIGIN_PROPERTY] = g_param_spec_int ("x-origin", "x-origin", "x-origin", G_MININT, G_MAXINT, 0, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE));
	/**
	         * Offset from the widget's top-left corner in pixels.
	         */
	g_object_class_install_property (G_OBJECT_CLASS (klass), FT_CANVAS_LAYOUT_CHILD_Y_ORIGIN_PROPERTY, ft_canvas_layout_child_properties[FT_CANVAS_LAYOUT_CHILD_Y_ORIGIN_PROPERTY] = g_param_spec_int ("y-origin", "y-origin", "y-origin", G_MININT, G_MAXINT, 0, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE));
}

static void
ft_canvas_layout_child_instance_init (FtCanvasLayoutChild * self,
                                      gpointer klass)
{
	self->priv = ft_canvas_layout_child_get_instance_private (self);
	self->priv->_x = 0.0f;
	self->priv->_y = 0.0f;
	self->priv->_x_origin = 0;
	self->priv->_y_origin = 0;
}

static void
ft_canvas_layout_child_finalize (GObject * obj)
{
	FtCanvasLayoutChild * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, FT_TYPE_CANVAS_LAYOUT_CHILD, FtCanvasLayoutChild);
	G_OBJECT_CLASS (ft_canvas_layout_child_parent_class)->finalize (obj);
}

/**
     * A `Gtk.LayoutChild` for `Ft.Canvas` widgets, storing per-child layout properties
     */
static GType
ft_canvas_layout_child_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (FtCanvasLayoutChildClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) ft_canvas_layout_child_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (FtCanvasLayoutChild), 0, (GInstanceInitFunc) ft_canvas_layout_child_instance_init, NULL };
	GType ft_canvas_layout_child_type_id;
	ft_canvas_layout_child_type_id = g_type_register_static (gtk_layout_child_get_type (), "FtCanvasLayoutChild", &g_define_type_info, 0);
	FtCanvasLayoutChild_private_offset = g_type_add_instance_private (ft_canvas_layout_child_type_id, sizeof (FtCanvasLayoutChildPrivate));
	return ft_canvas_layout_child_type_id;
}

GType
ft_canvas_layout_child_get_type (void)
{
	static volatile gsize ft_canvas_layout_child_type_id__once = 0;
	if (g_once_init_enter (&ft_canvas_layout_child_type_id__once)) {
		GType ft_canvas_layout_child_type_id;
		ft_canvas_layout_child_type_id = ft_canvas_layout_child_get_type_once ();
		g_once_init_leave (&ft_canvas_layout_child_type_id__once, ft_canvas_layout_child_type_id);
	}
	return ft_canvas_layout_child_type_id__once;
}

static void
_vala_ft_canvas_layout_child_get_property (GObject * object,
                                           guint property_id,
                                           GValue * value,
                                           GParamSpec * pspec)
{
	FtCanvasLayoutChild * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, FT_TYPE_CANVAS_LAYOUT_CHILD, FtCanvasLayoutChild);
	switch (property_id) {
		case FT_CANVAS_LAYOUT_CHILD_X_PROPERTY:
		g_value_set_float (value, ft_canvas_layout_child_get_x (self));
		break;
		case FT_CANVAS_LAYOUT_CHILD_Y_PROPERTY:
		g_value_set_float (value, ft_canvas_layout_child_get_y (self));
		break;
		case FT_CANVAS_LAYOUT_CHILD_X_ORIGIN_PROPERTY:
		g_value_set_int (value, ft_canvas_layout_child_get_x_origin (self));
		break;
		case FT_CANVAS_LAYOUT_CHILD_Y_ORIGIN_PROPERTY:
		g_value_set_int (value, ft_canvas_layout_child_get_y_origin (self));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

static void
_vala_ft_canvas_layout_child_set_property (GObject * object,
                                           guint property_id,
                                           const GValue * value,
                                           GParamSpec * pspec)
{
	FtCanvasLayoutChild * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, FT_TYPE_CANVAS_LAYOUT_CHILD, FtCanvasLayoutChild);
	switch (property_id) {
		case FT_CANVAS_LAYOUT_CHILD_X_PROPERTY:
		ft_canvas_layout_child_set_x (self, g_value_get_float (value));
		break;
		case FT_CANVAS_LAYOUT_CHILD_Y_PROPERTY:
		ft_canvas_layout_child_set_y (self, g_value_get_float (value));
		break;
		case FT_CANVAS_LAYOUT_CHILD_X_ORIGIN_PROPERTY:
		ft_canvas_layout_child_set_x_origin (self, g_value_get_int (value));
		break;
		case FT_CANVAS_LAYOUT_CHILD_Y_ORIGIN_PROPERTY:
		ft_canvas_layout_child_set_y_origin (self, g_value_get_int (value));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

/**
         * Calculate child's bounds in `Canvas` coordinates.
         */
static inline void
ft_canvas_layout_calculate_child_bounds (FtCanvasLayout* self,
                                         FtCanvasLayoutChild* child,
                                         gfloat x_scale,
                                         gfloat y_scale,
                                         GdkRectangle* result)
{
	GdkRectangle _tmp0_ = {0};
	gfloat _tmp1_;
	gfloat _tmp2_;
	gfloat _tmp3_;
	gfloat _tmp4_;
	GdkRectangle _tmp5_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (child != NULL);
	ft_canvas_layout_child_calculate_bounds (child, &_tmp0_);
	child->absolute_bounds = _tmp0_;
	_tmp1_ = ft_canvas_layout_child_get_x (child);
	_tmp2_ = _tmp1_;
	child->absolute_bounds.x = child->absolute_bounds.x + ((gint) roundf (x_scale * _tmp2_));
	_tmp3_ = ft_canvas_layout_child_get_y (child);
	_tmp4_ = _tmp3_;
	child->absolute_bounds.y = child->absolute_bounds.y - ((gint) roundf (y_scale * _tmp4_));
	_tmp5_ = child->absolute_bounds;
	*result = _tmp5_;
	return;
}

/**
         * Calculate bounds for all children in `Canvas` coordinates.
         */
static void
ft_canvas_layout_calculate_bounds (FtCanvasLayout* self,
                                   GtkWidget* widget,
                                   GdkRectangle* result)
{
	FtCanvas* canvas = NULL;
	FtCanvas* _tmp0_;
	gfloat x_scale = 0.0F;
	FtCanvas* _tmp1_;
	gfloat _tmp2_;
	gfloat _tmp3_;
	gfloat y_scale = 0.0F;
	FtCanvas* _tmp4_;
	gfloat _tmp5_;
	gfloat _tmp6_;
	GdkRectangle bounds = {0};
	gboolean is_first_child = FALSE;
	g_return_if_fail (self != NULL);
	g_return_if_fail (widget != NULL);
	_tmp0_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_CAST (widget, FT_TYPE_CANVAS, FtCanvas));
	canvas = _tmp0_;
	_tmp1_ = canvas;
	_tmp2_ = ft_canvas_get_x_scale (_tmp1_);
	_tmp3_ = _tmp2_;
	x_scale = _tmp3_;
	_tmp4_ = canvas;
	_tmp5_ = ft_canvas_get_y_scale (_tmp4_);
	_tmp6_ = _tmp5_;
	y_scale = _tmp6_;
	memset (&bounds, 0, sizeof (GdkRectangle));
	is_first_child = TRUE;
	{
		GtkWidget* child_widget = NULL;
		GtkWidget* _tmp7_;
		GtkWidget* _tmp8_;
		_tmp7_ = gtk_widget_get_first_child (widget);
		_tmp8_ = _g_object_ref0 (_tmp7_);
		child_widget = _tmp8_;
		{
			gboolean _tmp9_ = FALSE;
			_tmp9_ = TRUE;
			while (TRUE) {
				GtkWidget* _tmp13_;
				FtCanvasLayoutChild* layout_child = NULL;
				GtkWidget* _tmp14_;
				GtkLayoutChild* _tmp15_;
				FtCanvasLayoutChild* _tmp16_;
				FtCanvasLayoutChild* _tmp17_;
				GdkRectangle child_bounds = {0};
				FtCanvasLayoutChild* _tmp18_;
				GdkRectangle _tmp19_ = {0};
				if (!_tmp9_) {
					GtkWidget* _tmp10_;
					GtkWidget* _tmp11_;
					GtkWidget* _tmp12_;
					_tmp10_ = child_widget;
					_tmp11_ = gtk_widget_get_next_sibling (_tmp10_);
					_tmp12_ = _g_object_ref0 (_tmp11_);
					_g_object_unref0 (child_widget);
					child_widget = _tmp12_;
				}
				_tmp9_ = FALSE;
				_tmp13_ = child_widget;
				if (!(_tmp13_ != NULL)) {
					break;
				}
				_tmp14_ = child_widget;
				_tmp15_ = gtk_layout_manager_get_layout_child ((GtkLayoutManager*) self, _tmp14_);
				_tmp16_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_CAST (_tmp15_, FT_TYPE_CANVAS_LAYOUT_CHILD, FtCanvasLayoutChild));
				layout_child = _tmp16_;
				_tmp17_ = layout_child;
				if (_tmp17_ == NULL) {
					_g_object_unref0 (layout_child);
					continue;
				}
				_tmp18_ = layout_child;
				ft_canvas_layout_calculate_child_bounds (self, _tmp18_, x_scale, y_scale, &_tmp19_);
				child_bounds = _tmp19_;
				if (is_first_child) {
					GdkRectangle _tmp20_;
					_tmp20_ = child_bounds;
					bounds = _tmp20_;
					is_first_child = FALSE;
				} else {
					GdkRectangle _tmp21_;
					GdkRectangle _tmp22_ = {0};
					_tmp21_ = child_bounds;
					gdk_rectangle_union (&bounds, &_tmp21_, &_tmp22_);
					bounds = _tmp22_;
				}
				_g_object_unref0 (layout_child);
			}
		}
		_g_object_unref0 (child_widget);
	}
	*result = bounds;
	_g_object_unref0 (canvas);
	return;
}

static inline gint
ft_canvas_layout_calculate_width (FtCanvasLayout* self,
                                  GtkWidget* widget)
{
	GdkRectangle _tmp0_ = {0};
	gint _tmp1_;
	gint _tmp2_;
	gint result;
	g_return_val_if_fail (self != NULL, -1);
	g_return_val_if_fail (widget != NULL, -1);
	ft_canvas_layout_calculate_bounds (self, widget, &_tmp0_);
	g_object_get (widget, "width-request", &_tmp1_, NULL);
	_tmp2_ = _tmp1_;
	result = MAX (_tmp0_.width, _tmp2_);
	return result;
}

static inline gint
ft_canvas_layout_calculate_height (FtCanvasLayout* self,
                                   GtkWidget* widget)
{
	GdkRectangle _tmp0_ = {0};
	gint _tmp1_;
	gint _tmp2_;
	gint result;
	g_return_val_if_fail (self != NULL, -1);
	g_return_val_if_fail (widget != NULL, -1);
	ft_canvas_layout_calculate_bounds (self, widget, &_tmp0_);
	g_object_get (widget, "height-request", &_tmp1_, NULL);
	_tmp2_ = _tmp1_;
	result = MAX (_tmp0_.height, _tmp2_);
	return result;
}

/**
         * Calculate value bounds aka value range
         */
void
ft_canvas_layout_calculate_range (FtCanvasLayout* self,
                                  GtkWidget* widget,
                                  graphene_rect_t* result)
{
	graphene_rect_t range = {0};
	gboolean is_first_child = FALSE;
	g_return_if_fail (self != NULL);
	g_return_if_fail (widget != NULL);
	memset (&range, 0, sizeof (graphene_rect_t));
	is_first_child = TRUE;
	{
		GtkWidget* child_widget = NULL;
		GtkWidget* _tmp0_;
		GtkWidget* _tmp1_;
		_tmp0_ = gtk_widget_get_first_child (widget);
		_tmp1_ = _g_object_ref0 (_tmp0_);
		child_widget = _tmp1_;
		{
			gboolean _tmp2_ = FALSE;
			_tmp2_ = TRUE;
			while (TRUE) {
				GtkWidget* _tmp6_;
				FtCanvasLayoutChild* layout_child = NULL;
				GtkWidget* _tmp7_;
				GtkLayoutChild* _tmp8_;
				FtCanvasLayoutChild* _tmp9_;
				FtCanvasLayoutChild* _tmp10_;
				if (!_tmp2_) {
					GtkWidget* _tmp3_;
					GtkWidget* _tmp4_;
					GtkWidget* _tmp5_;
					_tmp3_ = child_widget;
					_tmp4_ = gtk_widget_get_next_sibling (_tmp3_);
					_tmp5_ = _g_object_ref0 (_tmp4_);
					_g_object_unref0 (child_widget);
					child_widget = _tmp5_;
				}
				_tmp2_ = FALSE;
				_tmp6_ = child_widget;
				if (!(_tmp6_ != NULL)) {
					break;
				}
				_tmp7_ = child_widget;
				_tmp8_ = gtk_layout_manager_get_layout_child ((GtkLayoutManager*) self, _tmp7_);
				_tmp9_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_CAST (_tmp8_, FT_TYPE_CANVAS_LAYOUT_CHILD, FtCanvasLayoutChild));
				layout_child = _tmp9_;
				_tmp10_ = layout_child;
				if (_tmp10_ == NULL) {
					_g_object_unref0 (layout_child);
					continue;
				}
				if (is_first_child) {
					FtCanvasLayoutChild* _tmp11_;
					graphene_rect_t _tmp12_;
					_tmp11_ = layout_child;
					_tmp12_ = _tmp11_->range;
					range = _tmp12_;
					is_first_child = FALSE;
				} else {
					FtCanvasLayoutChild* _tmp13_;
					graphene_rect_t _tmp14_;
					graphene_rect_t _tmp15_ = {0};
					_tmp13_ = layout_child;
					_tmp14_ = _tmp13_->range;
					graphene_rect_union (&range, &_tmp14_, &_tmp15_);
					range = _tmp15_;
				}
				_g_object_unref0 (layout_child);
			}
		}
		_g_object_unref0 (child_widget);
	}
	*result = range;
	return;
}

/**
         * Calculate and canvas origin point
         *
         * The origin point is absolute (centre of coordinate system).
         */
gboolean
ft_canvas_layout_calculate_origin (FtCanvasLayout* self,
                                   GtkWidget* widget,
                                   gint* x_origin,
                                   gint* y_origin)
{
	gint _vala_x_origin = 0;
	gint _vala_y_origin = 0;
	FtCanvas* canvas = NULL;
	FtCanvas* _tmp0_;
	FtCanvas* _tmp1_;
	gboolean result;
	g_return_val_if_fail (self != NULL, FALSE);
	g_return_val_if_fail (widget != NULL, FALSE);
	_tmp0_ = _g_object_ref0 (FT_IS_CANVAS (widget) ? ((FtCanvas*) widget) : NULL);
	canvas = _tmp0_;
	_tmp1_ = canvas;
	if (_tmp1_ != NULL) {
		GdkRectangle bounds = {0};
		GdkRectangle _tmp2_ = {0};
		gint x_offset = 0;
		gint _tmp3_;
		gint _tmp4_;
		GdkRectangle _tmp5_;
		gint y_offset = 0;
		gint _tmp6_;
		gint _tmp7_;
		GdkRectangle _tmp8_;
		GdkRectangle _tmp9_;
		GdkRectangle _tmp10_;
		ft_canvas_layout_calculate_bounds (self, widget, &_tmp2_);
		bounds = _tmp2_;
		g_object_get (widget, "width-request", &_tmp3_, NULL);
		_tmp4_ = _tmp3_;
		_tmp5_ = bounds;
		x_offset = MAX (_tmp4_ - _tmp5_.width, 0);
		g_object_get (widget, "height-request", &_tmp6_, NULL);
		_tmp7_ = _tmp6_;
		_tmp8_ = bounds;
		y_offset = MAX (_tmp7_ - _tmp8_.height, 0);
		_tmp9_ = bounds;
		_vala_x_origin = (-_tmp9_.x) + x_offset;
		_tmp10_ = bounds;
		_vala_y_origin = (-_tmp10_.y) + y_offset;
		result = TRUE;
		_g_object_unref0 (canvas);
		if (x_origin) {
			*x_origin = _vala_x_origin;
		}
		if (y_origin) {
			*y_origin = _vala_y_origin;
		}
		return result;
	} else {
		_vala_x_origin = 0;
		_vala_y_origin = 0;
		result = FALSE;
		_g_object_unref0 (canvas);
		if (x_origin) {
			*x_origin = _vala_x_origin;
		}
		if (y_origin) {
			*y_origin = _vala_y_origin;
		}
		return result;
	}
}

static GtkLayoutChild*
ft_canvas_layout_real_create_layout_child (GtkLayoutManager* base,
                                           GtkWidget* widget,
                                           GtkWidget* for_child)
{
	FtCanvasLayout * self;
	GObject* _tmp0_;
	GObject* _tmp1_;
	GtkLayoutChild* result;
	self = (FtCanvasLayout*) base;
	g_return_val_if_fail (widget != NULL, NULL);
	g_return_val_if_fail (for_child != NULL, NULL);
	_tmp0_ = g_object_new (FT_TYPE_CANVAS_LAYOUT_CHILD, "layout-manager", self, "child-widget", for_child, NULL);
	_tmp1_ = G_IS_INITIALLY_UNOWNED (_tmp0_) ? g_object_ref_sink (_tmp0_) : _tmp0_;
	result = G_TYPE_CHECK_INSTANCE_CAST (_tmp1_, gtk_layout_child_get_type (), GtkLayoutChild);
	return result;
}

static GtkSizeRequestMode
ft_canvas_layout_real_get_request_mode (GtkLayoutManager* base,
                                        GtkWidget* widget)
{
	FtCanvasLayout * self;
	GtkSizeRequestMode result;
	self = (FtCanvasLayout*) base;
	g_return_val_if_fail (widget != NULL, 0);
	result = GTK_SIZE_REQUEST_CONSTANT_SIZE;
	return result;
}

static void
ft_canvas_layout_real_measure (GtkLayoutManager* base,
                               GtkWidget* widget,
                               GtkOrientation orientation,
                               gint for_size,
                               gint* minimum,
                               gint* natural,
                               gint* minimum_baseline,
                               gint* natural_baseline)
{
	FtCanvasLayout * self;
	gint _vala_minimum = 0;
	gint _vala_natural = 0;
	gint _vala_minimum_baseline = 0;
	gint _vala_natural_baseline = 0;
	gint _tmp0_ = 0;
	self = (FtCanvasLayout*) base;
	g_return_if_fail (widget != NULL);
	if (orientation == GTK_ORIENTATION_HORIZONTAL) {
		_tmp0_ = ft_canvas_layout_calculate_width (self, widget);
	} else {
		_tmp0_ = ft_canvas_layout_calculate_height (self, widget);
	}
	_vala_natural = _tmp0_;
	_vala_minimum = _vala_natural;
	_vala_minimum_baseline = -1;
	_vala_natural_baseline = -1;
	if (minimum) {
		*minimum = _vala_minimum;
	}
	if (natural) {
		*natural = _vala_natural;
	}
	if (minimum_baseline) {
		*minimum_baseline = _vala_minimum_baseline;
	}
	if (natural_baseline) {
		*natural_baseline = _vala_natural_baseline;
	}
}

/**
         * Place items for given size.
         *
         * We likely execute it having `origin` point computed earlier.
         */
static void
ft_canvas_layout_real_allocate (GtkLayoutManager* base,
                                GtkWidget* widget,
                                gint width,
                                gint height,
                                gint baseline)
{
	FtCanvasLayout * self;
	FtCanvas* canvas = NULL;
	FtCanvas* _tmp0_;
	FtCanvas* _tmp1_;
	gint x_origin = 0;
	FtCanvas* _tmp2_;
	gint _tmp3_;
	gint _tmp4_;
	gint y_origin = 0;
	FtCanvas* _tmp5_;
	gint _tmp6_;
	gint _tmp7_;
	self = (FtCanvasLayout*) base;
	g_return_if_fail (widget != NULL);
	_tmp0_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_CAST (widget, FT_TYPE_CANVAS, FtCanvas));
	canvas = _tmp0_;
	_tmp1_ = canvas;
	ft_canvas_update_origin (_tmp1_);
	_tmp2_ = canvas;
	_tmp3_ = ft_canvas_get_x_origin (_tmp2_);
	_tmp4_ = _tmp3_;
	x_origin = _tmp4_;
	_tmp5_ = canvas;
	_tmp6_ = ft_canvas_get_y_origin (_tmp5_);
	_tmp7_ = _tmp6_;
	y_origin = _tmp7_;
	{
		GtkWidget* child_widget = NULL;
		GtkWidget* _tmp8_;
		GtkWidget* _tmp9_;
		_tmp8_ = gtk_widget_get_first_child (widget);
		_tmp9_ = _g_object_ref0 (_tmp8_);
		child_widget = _tmp9_;
		{
			gboolean _tmp10_ = FALSE;
			_tmp10_ = TRUE;
			while (TRUE) {
				GtkWidget* _tmp14_;
				FtCanvasLayoutChild* layout_child = NULL;
				GtkWidget* _tmp15_;
				GtkLayoutChild* _tmp16_;
				FtCanvasLayoutChild* _tmp17_;
				FtCanvasLayoutChild* _tmp18_;
				GtkAllocation child_allocation = {0};
				FtCanvasLayoutChild* _tmp19_;
				GdkRectangle _tmp20_;
				GtkWidget* _tmp21_;
				GtkAllocation _tmp22_;
				if (!_tmp10_) {
					GtkWidget* _tmp11_;
					GtkWidget* _tmp12_;
					GtkWidget* _tmp13_;
					_tmp11_ = child_widget;
					_tmp12_ = gtk_widget_get_next_sibling (_tmp11_);
					_tmp13_ = _g_object_ref0 (_tmp12_);
					_g_object_unref0 (child_widget);
					child_widget = _tmp13_;
				}
				_tmp10_ = FALSE;
				_tmp14_ = child_widget;
				if (!(_tmp14_ != NULL)) {
					break;
				}
				_tmp15_ = child_widget;
				_tmp16_ = gtk_layout_manager_get_layout_child ((GtkLayoutManager*) self, _tmp15_);
				_tmp17_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_CAST (_tmp16_, FT_TYPE_CANVAS_LAYOUT_CHILD, FtCanvasLayoutChild));
				layout_child = _tmp17_;
				_tmp18_ = layout_child;
				if (_tmp18_ == NULL) {
					_g_object_unref0 (layout_child);
					continue;
				}
				_tmp19_ = layout_child;
				_tmp20_ = _tmp19_->absolute_bounds;
				child_allocation = (GtkAllocation) _tmp20_;
				child_allocation.x = child_allocation.x + x_origin;
				child_allocation.y = child_allocation.y + y_origin;
				_tmp21_ = child_widget;
				_tmp22_ = child_allocation;
				gtk_widget_size_allocate (_tmp21_, &_tmp22_, -1);
				_g_object_unref0 (layout_child);
			}
		}
		_g_object_unref0 (child_widget);
	}
	_g_object_unref0 (canvas);
}

FtCanvasLayout*
ft_canvas_layout_construct (GType object_type)
{
	FtCanvasLayout * self = NULL;
	self = (FtCanvasLayout*) g_object_new (object_type, NULL);
	return self;
}

FtCanvasLayout*
ft_canvas_layout_new (void)
{
	return ft_canvas_layout_construct (FT_TYPE_CANVAS_LAYOUT);
}

static void
ft_canvas_layout_class_init (FtCanvasLayoutClass * klass,
                             gpointer klass_data)
{
	ft_canvas_layout_parent_class = g_type_class_peek_parent (klass);
	((GtkLayoutManagerClass *) klass)->create_layout_child = (GtkLayoutChild* (*) (GtkLayoutManager*, GtkWidget*, GtkWidget*)) ft_canvas_layout_real_create_layout_child;
	((GtkLayoutManagerClass *) klass)->get_request_mode = (GtkSizeRequestMode (*) (GtkLayoutManager*, GtkWidget*)) ft_canvas_layout_real_get_request_mode;
	((GtkLayoutManagerClass *) klass)->measure = (void (*) (GtkLayoutManager*, GtkWidget*, GtkOrientation, gint, gint*, gint*, gint*, gint*)) ft_canvas_layout_real_measure;
	((GtkLayoutManagerClass *) klass)->allocate = (void (*) (GtkLayoutManager*, GtkWidget*, gint, gint, gint)) ft_canvas_layout_real_allocate;
}

static void
ft_canvas_layout_instance_init (FtCanvasLayout * self,
                                gpointer klass)
{
}

static GType
ft_canvas_layout_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (FtCanvasLayoutClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) ft_canvas_layout_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (FtCanvasLayout), 0, (GInstanceInitFunc) ft_canvas_layout_instance_init, NULL };
	GType ft_canvas_layout_type_id;
	ft_canvas_layout_type_id = g_type_register_static (gtk_layout_manager_get_type (), "FtCanvasLayout", &g_define_type_info, 0);
	return ft_canvas_layout_type_id;
}

GType
ft_canvas_layout_get_type (void)
{
	static volatile gsize ft_canvas_layout_type_id__once = 0;
	if (g_once_init_enter (&ft_canvas_layout_type_id__once)) {
		GType ft_canvas_layout_type_id;
		ft_canvas_layout_type_id = ft_canvas_layout_get_type_once ();
		g_once_init_leave (&ft_canvas_layout_type_id__once, ft_canvas_layout_type_id);
	}
	return ft_canvas_layout_type_id__once;
}

