gtkmm: Gtk::ConstraintLayout Class Reference

gtkmm 4.2.0

Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | Related Functions | List of all members
Gtk::ConstraintLayout Class Reference

A layout manager using constraints. More...

`#include <gtkmm/constraintlayout.h>`

Inheritance diagram for Gtk::ConstraintLayout:
[legend]

## Public Types
using | VFLmap = std::map< Glib::ustring, Glib::RefPtr< ConstraintTarget > >
| A map type, used by add_constraints_from_description(). More...
Public Types inherited from Glib::Object
typedef void(*)(gpointer data | DestroyNotify)

## Public Member Functions
| ConstraintLayout (ConstraintLayout&& src) noexcept
ConstraintLayout& | operator= (ConstraintLayout&& src) noexcept
| ~ConstraintLayout () noexcept override
GtkConstraintLayout* | gobj ()
| Provides access to the underlying C GObject. More...
const GtkConstraintLayout* | gobj () const
| Provides access to the underlying C GObject. More...
GtkConstraintLayout* | gobj_copy ()
| Provides access to the underlying C instance. The caller is responsible for unrefing it. Use when directly setting fields in structs. More...
void | add_constraint (const Glib::RefPtr< Constraint >& constraint)
| Adds a constraint to the layout manager. More...
void | remove_constraint (const Glib::RefPtr< Constraint >& constraint)
| Removes `constraint` from the layout manager, so that it no longer influences the layout. More...
void | remove_all_constraints ()
| Removes all constraints from the layout manager. More...
void | add_guide (const Glib::RefPtr< ConstraintGuide >& guide)
| Adds a guide to `layout`. More...
void | remove_guide (const Glib::RefPtr< ConstraintGuide >& guide)
| Removes `guide` from the layout manager, so that it no longer influences the layout. More...
std::vector< Glib::RefPtr< Constraint > > | add_constraints_from_description (const std::vector< Glib::ustring >& lines, int hspacing, int vspacing, const VFLmap& views)
| Creates a list of constraints from a formal description using a compact description syntax called VFL, or "Visual Format Language". More...
Glib::RefPtr< Gio::ListModel > | observe_constraints ()
| Returns a `GListModel` to track the constraints that are part of the layout. More...
Glib::RefPtr< const Gio::ListModel > | observe_constraints () const
| Returns a `GListModel` to track the constraints that are part of the layout. More...
Glib::RefPtr< Gio::ListModel > | observe_guides ()
| Returns a `GListModel` to track the guides that are part of the layout. More...
Glib::RefPtr< const Gio::ListModel > | observe_guides () const
| Returns a `GListModel` to track the guides that are part of the layout. More...
Public Member Functions inherited from Gtk::LayoutManager
| LayoutManager (LayoutManager&& src) noexcept
LayoutManager& | operator= (LayoutManager&& src) noexcept
| ~LayoutManager () noexcept override
GtkLayoutManager* | gobj ()
| Provides access to the underlying C GObject. More...
const GtkLayoutManager* | gobj () const
| Provides access to the underlying C GObject. More...
GtkLayoutManager* | gobj_copy ()
| Provides access to the underlying C instance. The caller is responsible for unrefing it. Use when directly setting fields in structs. More...
void | measure (Widget& widget, Orientation orientation, int for_size, int& minimum, int& natural, int& minimum_baseline, int& natural_baseline) const
| Measures the size of the widget using manager, for the given orientation and size. More...
void | allocate (Widget& widget, int width, int height, int baseline)
| Assigns the given width, height, and baseline to a widget, and computes the position and sizes of the children of the widget using the layout management policy of manager. More...
SizeRequestMode | get_request_mode () const
| Retrieves the request mode of manager. More...
Widget* | get_widget ()
| Retrieves the `GtkWidget` using the given `GtkLayoutManager`. More...
const Widget* | get_widget () const
| Retrieves the `GtkWidget` using the given `GtkLayoutManager`. More...
void | layout_changed ()
| Queues a resize on the `GtkWidget` using manager, if any. More...
Glib::RefPtr< LayoutChild > | get_layout_child (Widget& child)
| Retrieves a `GtkLayoutChild` instance for the `GtkLayoutManager`, creating one if necessary. More...
Glib::RefPtr< const LayoutChild > | get_layout_child (Widget& child) const
| Retrieves a `GtkLayoutChild` instance for the `GtkLayoutManager`, creating one if necessary. More...
Public Member Functions inherited from Glib::Object
| Object (const Object &)=delete
Object & | operator= (const Object &)=delete
| Object (Object &&src) noexcept
Object & | operator= (Object &&src) noexcept
void * | get_data (const QueryQuark &key)
void | set_data (const Quark &key, void *data)
void | set_data (const Quark &key, void *data, DestroyNotify notify)
void | remove_data (const QueryQuark &quark)
void * | steal_data (const QueryQuark &quark)
Glib::RefPtr< Glib::Object > | wrap (GObject *object, bool take_copy=false)
Public Member Functions inherited from Glib::ObjectBase
| ObjectBase (const ObjectBase &)=delete
ObjectBase & | operator= (const ObjectBase &)=delete
void | set_property_value (const Glib::ustring &property_name, const Glib::ValueBase &value)
void | get_property_value (const Glib::ustring &property_name, Glib::ValueBase &value) const
void | set_property (const Glib::ustring &property_name, const PropertyType &value)
void | get_property (const Glib::ustring &property_name, PropertyType &value) const
PropertyType | get_property (const Glib::ustring &property_name) const
sigc::connection | connect_property_changed (const Glib::ustring &property_name, const sigc::slot< void()> &slot)
sigc::connection | connect_property_changed (const Glib::ustring &property_name, sigc::slot< void()> &&slot)
void | freeze_notify ()
void | thaw_notify ()
virtual void | reference () const
virtual void | unreference () const
GObject * | gobj ()
const GObject * | gobj () const
GObject * | gobj_copy () const
Public Member Functions inherited from Gtk::Buildable
| Buildable (Buildable&& src) noexcept
Buildable& | operator= (Buildable&& src) noexcept
| ~Buildable () noexcept override
GtkBuildable* | gobj ()
| Provides access to the underlying C GObject. More...
const GtkBuildable* | gobj () const
| Provides access to the underlying C GObject. More...
Glib::ustring | get_buildable_id () const
| Gets the ID of the buildable object. More...
Public Member Functions inherited from Glib::Interface
| Interface ()
| Interface (Interface &&src) noexcept
Interface & | operator= (Interface &&src) noexcept
| Interface (const Glib::Interface_Class &interface_class)
| Interface (GObject *castitem)
| ~Interface () noexcept override
| Interface (const Interface &)=delete
Interface & | operator= (const Interface &)=delete
GObject * | gobj ()
const GObject * | gobj () const

## Static Public Member Functions
static GType | get_type ()
| Get the GType for this class, for use with the underlying GObject type system. More...
static Glib::RefPtr< ConstraintLayout > | create ()
Static Public Member Functions inherited from Gtk::LayoutManager
static GType | get_type ()
| Get the GType for this class, for use with the underlying GObject type system. More...
Static Public Member Functions inherited from Gtk::Buildable
static void | add_interface (GType gtype_implementer)
static GType | get_type ()
| Get the GType for this class, for use with the underlying GObject type system. More...

## Protected Member Functions
| ConstraintLayout ()
Protected Member Functions inherited from Gtk::LayoutManager
| LayoutManager ()
| There is no create() method that corresponds to this constructor, because only derived classes shall be created. More...
virtual SizeRequestMode | get_request_mode_vfunc (const Widget& widget) const
virtual void | measure_vfunc (const Widget& widget, Orientation orientation, int for_size, int& minimum, int& natural, int& minimum_baseline, int& natural_baseline) const
virtual void | allocate_vfunc (const Widget& widget, int width, int height, int baseline)
virtual Glib::RefPtr< LayoutChild > | create_layout_child_vfunc (const Widget& widget, const Widget& for_child)
virtual void | root_vfunc ()
virtual void | unroot_vfunc ()
Protected Member Functions inherited from Glib::Object
| Object ()
| Object (const Glib::ConstructParams &construct_params)
| Object (GObject *castitem)
| ~Object () noexcept override
Protected Member Functions inherited from Glib::ObjectBase
| ObjectBase ()
| ObjectBase (const char *custom_type_name)
| ObjectBase (const std::type_info &custom_type_info)
| ObjectBase (ObjectBase &&src) noexcept
ObjectBase & | operator= (ObjectBase &&src) noexcept
virtual | ~ObjectBase () noexcept=0
void | initialize (GObject *castitem)
void | initialize_move (GObject *castitem, Glib::ObjectBase *previous_wrapper)
Protected Member Functions inherited from Gtk::Buildable
| Buildable ()
| You should derive from this class to use it. More...

## Related Functions
(Note that these are not member functions.)
Glib::RefPtr< Gtk::ConstraintLayout > | wrap (GtkConstraintLayout* object, bool take_copy=false)
| A Glib::wrap() method for this object. More...
Related Functions inherited from Gtk::LayoutManager
Glib::RefPtr< Gtk::LayoutManager > | wrap (GtkLayoutManager* object, bool take_copy=false)
| A Glib::wrap() method for this object. More...
Related Functions inherited from Gtk::Buildable
Glib::RefPtr< Gtk::Buildable > | wrap (GtkBuildable* object, bool take_copy=false)
| A Glib::wrap() method for this object. More...

## Detailed Description

A layout manager using constraints.

ConstraintLayout is a layout manager that uses relations between widget attributes, expressed via Gtk::Constraint instances, to measure and allocate widgets.

See the description of GtkConstraintLayout in GTK for a detailed description of how constraints work.

Since gtkmm 3.96:

## Member Typedef Documentation

## ◆ VFLmap

using Gtk::ConstraintLayout::VFLmap = std::map<Glib::ustring, Glib::RefPtr<ConstraintTarget> >

A map type, used by add_constraints_from_description().

## Constructor & Destructor Documentation

## ◆ ConstraintLayout() [1/2]

Gtk::ConstraintLayout::ConstraintLayout | ( | ConstraintLayout&& | src | ) |
| noexcept

## ◆ ~ConstraintLayout()

Gtk::ConstraintLayout::~ConstraintLayout | ( |  | ) |
| overridenoexcept

## ◆ ConstraintLayout() [2/2]

Gtk::ConstraintLayout::ConstraintLayout | ( |  | ) |
| protected

## Member Function Documentation

## ◆ add_constraint()

void Gtk::ConstraintLayout::add_constraint | ( | const Glib::RefPtr< Constraint >& | constraint | ) |

Adds a constraint to the layout manager.

The [property Gtk.Constraint:source] and [property Gtk.Constraint:target] properties of `constraint` can be:

- set to `<tt>nullptr</tt>` to indicate that the constraint refers to the widget using `layout`
- set to the [class Gtk.Widget] using `layout`
- set to a child of the [class Gtk.Widget] using `layout`
- set to a [class Gtk.ConstraintGuide] that is part of `layout`

The layout acquires the ownership of constraint after calling this function.

Parameters

  constraint | A [class Gtk.Constraint].

## ◆ add_constraints_from_description()

std::vector<Glib::RefPtr<Constraint> > Gtk::ConstraintLayout::add_constraints_from_description | ( | const std::vector< Glib::ustring > & | lines,
|  | int | hspacing,
|  | int | vspacing,
|  | const VFLmap& | views
| ) |  |

Creates a list of constraints from a formal description using a compact description syntax called VFL, or "Visual Format Language".

The Visual Format Language is based on Apple's AutoLayout VFL. See also the description of gtk_constraint_layout_add_constraints_from_descriptionv() in GTK.

The views dictionary is used to match Gtk::ConstraintTargets to the symbolic view name inside the VFL.

Note: The VFL grammar used by GTK is slightly different than the one defined by Apple, as it can use symbolic values for the constraint's strength instead of numeric values; additionally, GTK allows adding simple arithmetic operations inside predicates.

Parameters

  lines | A vector of Visual Format Language lines defining a set of constraints.
  hspacing | Default horizontal spacing value, or -1 for the fallback value.
  vspacing | Default vertical spacing value, or -1 for the fallback value.
  views | A dictionary of [ name, target ] pairs; the `name` keys map to the view names in the VFL lines, while the `target` values map to children of the widget using a Gtk::ConstraintLayout, or guides.

Returns
  The vector of Gtk::Constraints that were added to the layout.

Exceptions

  Gtk::ConstraintVflParserError |

## ◆ add_guide()

void Gtk::ConstraintLayout::add_guide | ( | const Glib::RefPtr< ConstraintGuide >& | guide | ) |

Adds a guide to `layout`.

A guide can be used as the source or target of constraints, like a widget, but it is not visible.

The `layout` acquires the ownership of `guide` after calling this function.

Parameters

  guide | A [class Gtk.ConstraintGuide] object.

## ◆ create()

static Glib::RefPtr<ConstraintLayout> Gtk::ConstraintLayout::create | ( |  | ) |
| static

## ◆ get_type()

static GType Gtk::ConstraintLayout::get_type | ( |  | ) |
| static

Get the GType for this class, for use with the underlying GObject type system.

## ◆ gobj() [1/2]

GtkConstraintLayout* Gtk::ConstraintLayout::gobj | ( |  | ) |
| inline

Provides access to the underlying C GObject.

## ◆ gobj() [2/2]

const GtkConstraintLayout* Gtk::ConstraintLayout::gobj | ( |  | ) | const
| inline

Provides access to the underlying C GObject.

## ◆ gobj_copy()

GtkConstraintLayout* Gtk::ConstraintLayout::gobj_copy | ( |  | ) |

Provides access to the underlying C instance. The caller is responsible for unrefing it. Use when directly setting fields in structs.

## ◆ observe_constraints() [1/2]

Glib::RefPtr<Gio::ListModel> Gtk::ConstraintLayout::observe_constraints | ( |  | ) |

Returns a `GListModel` to track the constraints that are part of the layout.

Calling this function will enable extra internal bookkeeping to track constraints and emit signals on the returned listmodel. It may slow down operations a lot.

Applications should try hard to avoid calling this function because of the slowdowns.

Returns
  A `GListModel` tracking the layout's constraints.

## ◆ observe_constraints() [2/2]

Glib::RefPtr<const Gio::ListModel> Gtk::ConstraintLayout::observe_constraints | ( |  | ) | const

Returns a `GListModel` to track the constraints that are part of the layout.

Calling this function will enable extra internal bookkeeping to track constraints and emit signals on the returned listmodel. It may slow down operations a lot.

Applications should try hard to avoid calling this function because of the slowdowns.

Returns
  A `GListModel` tracking the layout's constraints.

## ◆ observe_guides() [1/2]

Glib::RefPtr<Gio::ListModel> Gtk::ConstraintLayout::observe_guides | ( |  | ) |

Returns a `GListModel` to track the guides that are part of the layout.

Calling this function will enable extra internal bookkeeping to track guides and emit signals on the returned listmodel. It may slow down operations a lot.

Applications should try hard to avoid calling this function because of the slowdowns.

Returns
  A `GListModel` tracking the layout's guides.

## ◆ observe_guides() [2/2]

Glib::RefPtr<const Gio::ListModel> Gtk::ConstraintLayout::observe_guides | ( |  | ) | const

Returns a `GListModel` to track the guides that are part of the layout.

Calling this function will enable extra internal bookkeeping to track guides and emit signals on the returned listmodel. It may slow down operations a lot.

Applications should try hard to avoid calling this function because of the slowdowns.

Returns
  A `GListModel` tracking the layout's guides.

## ◆ operator=()

ConstraintLayout& Gtk::ConstraintLayout::operator= | ( | ConstraintLayout&& | src | ) |
| noexcept

## ◆ remove_all_constraints()

void Gtk::ConstraintLayout::remove_all_constraints | ( |  | ) |

Removes all constraints from the layout manager.

## ◆ remove_constraint()

void Gtk::ConstraintLayout::remove_constraint | ( | const Glib::RefPtr< Constraint >& | constraint | ) |

Removes `constraint` from the layout manager, so that it no longer influences the layout.

Parameters

  constraint | A [class Gtk.Constraint].

## ◆ remove_guide()

void Gtk::ConstraintLayout::remove_guide | ( | const Glib::RefPtr< ConstraintGuide >& | guide | ) |

Removes `guide` from the layout manager, so that it no longer influences the layout.

Parameters

  guide | A [class Gtk.ConstraintGuide] object.

## Friends And Related Function Documentation

## ◆ wrap()

Glib::RefPtr< Gtk::ConstraintLayout > wrap | ( | GtkConstraintLayout * | object,
|  | bool | take_copy = `false`
| ) |  |
| related

A Glib::wrap() method for this object.

Parameters

  object | The C instance.
  take_copy | False if the result should take ownership of the C instance. True if it should take a new copy or ref.

Returns
  A C++ instance that wraps this C instance.