Wt: Wt::WLayout Class Reference

Wt 4.10.4

Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | Protected Member Functions | Private Member Functions | List of all members
Wt::WLayout Class Referenceabstract

An abstract base class for layout managers. More...

`#include <Wt/WLayout.h>`

Inheritance diagram for Wt::WLayout:
[legend]

## Public Member Functions
virtual | ~WLayout ()
| Destructor.
void | setPreferredImplementation (LayoutImplementation implementation)
| Set the preferred layout implementation.
virtual void | addItem (std::unique_ptr< WLayoutItem > item)=0
| Adds a layout item.
void | addWidget (std::unique_ptr< WWidget > widget)
| Adds the given widget to the layout.
virtual std::unique_ptr< WLayoutItem > | removeItem (WLayoutItem *item)=0
| Removes a layout item (widget or nested layout).
std::unique_ptr< WWidget > | removeWidget (WWidget *widget)
| Removes the given widget from the layout.
virtual int | count () const =0
| Returns the number of items in this layout.
virtual WLayoutItem * | itemAt (int index) const =0
| Returns the layout item at a specific index.
virtual int | indexOf (WLayoutItem *item) const
| Returns the index of a given item.
virtual WWidgetItem * | findWidgetItem (WWidget *widget) override
| Finds the widget item associated with the given widget.
virtual WWidget * | widget () override
| Returns the widget that is held by this WLayoutItem.
virtual WLayout * | layout () override
| Returns the layout that implements this WLayoutItem.
virtual WLayout * | parentLayout () const override
| Returns the layout in which this item is contained.
void | setContentsMargins (int left, int top, int right, int bottom)
| Set contents margins (in pixels).
void | getContentsMargins (int *left, int *top, int *right, int *bottom) const
| Returns the contents margins.
Public Member Functions inherited from Wt::WLayoutItem
virtual | ~WLayoutItem ()
| Destructor.
Public Member Functions inherited from Wt::WObject
void | addChild (std::unique_ptr< WObject > child)
| Add a child WObject whose lifetime is determined by this WObject.
template<typename Child >
Child * | addChild (std::unique_ptr< Child > child)
| Add a child WObject, returning a raw pointer.
std::unique_ptr< WObject > | removeChild (WObject *child)
| Remove a child WObject, so its lifetime is no longer determined by this WObject.
template<typename Child >
std::unique_ptr< Child > | removeChild (Child *child)
| Remove a child WObject, so its lifetime is no longer determined by this WObject.
virtual const std::string | id () const
| Returns the (unique) identifier for this object.
virtual void | setObjectName (const std::string &name)
| Sets an object name.
virtual std::string | objectName () const
| Returns the object name.
void | resetLearnedSlots ()
| Resets learned stateless slot implementations.
template<class T >
void | resetLearnedSlot (void(T::*method)())
| Resets a learned stateless slot implementation.
template<class T >
WStatelessSlot * | implementStateless (void(T::*method)())
| Declares a slot to be stateless and learn client-side behaviour on first invocation.
template<class T >
WStatelessSlot * | implementStateless (void(T::*method)(), void(T::*undoMethod)())
| Declares a slot to be stateless and learn client-side behaviour in advance.
void | isNotStateless ()
| Marks the current function as not stateless.
template<class T >
WStatelessSlot * | implementJavaScript (void(T::*method)(), const std::string &jsCode)
| Provides a JavaScript implementation for a method.
Public Member Functions inherited from Wt::Core::observable
| observable () noexcept
| Default constructor.
virtual | ~observable ()
| Destructor.
template<typename... Args, typename C >
auto | bindSafe (void(C::*method)(Args...)) noexcept
| Protects a method call against object destruction.
template<typename... Args, typename C >
auto | bindSafe (void(C::*method)(Args...) const) const noexcept
| Protects a const method call against object destruction.
template<typename Function >
auto | bindSafe (const Function &function) noexcept
| Protects a function against object destruction.

## Static Public Member Functions
static void | setDefaultImplementation (LayoutImplementation implementation)
| Sets the preferred layout implementation globally.
Static Public Member Functions inherited from Wt::WObject

## Protected Member Functions
| WLayout ()
| Create a layout.
void | update (WLayoutItem *item=nullptr)
| Update the layout.
virtual void | setParentWidget (WWidget *parent) override
| Internal method.
Protected Member Functions inherited from Wt::WObject
virtual WStatelessSlot * | getStateless (Method method)
| On-demand stateless slot implementation.

## Private Member Functions
virtual void | setParentLayout (WLayout *parentLayout) override
| Internal method.

## Additional Inherited Members
Public Types inherited from Wt::WLayoutItem
Public Types inherited from Wt::WObject
typedef void(WObject::*) | Method()
| Typedef for a WObject method without arguments.

## Detailed Description

An abstract base class for layout managers.

This class is the abstract base class for any layout manager. A layout manager is associated with a container widget, and manages the layout of children inside the whole space available to the container widget.

The implementation of the layout manager depends on the container widget to which it is set, and is therefore deferred to WLayoutImpl.

Note
  When applying a layout manager to a WContainerWidget, you may not define any padding for the container widget. Instead, use setContentsMargins().

## Constructor & Destructor Documentation

## ◆ ~WLayout()

virtual Wt::WLayout::~WLayout | ( |  | ) |
| virtual

Destructor.

This will delete the layout (and nested layouts), but not the contained widgets.

## Member Function Documentation

## ◆ addItem()

virtual void Wt::WLayout::addItem | ( | std::unique_ptr< WLayoutItem > | item | ) |
| pure virtual

Adds a layout item.

The item may be a widget or nested layout.

How the item is layed out with respect to siblings is implementation specific to the layout manager. In some cases, a layout manager will overload this method with extra arguments that specify layout options.

See also
  removeItem(WLayoutItem *), addWidget(WWidget *)

Implemented in Wt::WBorderLayout, Wt::WBoxLayout, Wt::WFitLayout, and Wt::WGridLayout.

## ◆ addWidget()

void Wt::WLayout::addWidget | ( | std::unique_ptr< WWidget > | widget | ) |

Adds the given widget to the layout.

This method wraps the widget in a WWidgetItem and calls addItem(WLayoutItem *).

How the widget is layed out with respect to siblings is implementation specific to the layout manager. In some cases, a layout manager will overload this method with extra arguments that specify layout options.

See also
  removeWidget(WWidget *), addItem(WLayoutItem *)

## ◆ count()

virtual int Wt::WLayout::count | ( |  | ) | const
| pure virtual

Returns the number of items in this layout.

This may be a theoretical number, which is greater than the actual number of items. It can be used to iterate over the items in the layout, in conjunction with itemAt().

Implemented in Wt::WBorderLayout, Wt::WBoxLayout, Wt::WFitLayout, and Wt::WGridLayout.

## ◆ getContentsMargins()

void Wt::WLayout::getContentsMargins | ( | int * | left,
|  | int * | top,
|  | int * | right,
|  | int * | bottom ) const

Returns the contents margins.

See also
  setContentsMargins()

## ◆ indexOf()

virtual int Wt::WLayout::indexOf | ( | WLayoutItem * | item | ) | const
| virtual

Returns the index of a given item.

The default implementation loops over all items, and returns the index for which itemAt(index) equals `item`.

See also
  itemAt(int) const

Reimplemented in Wt::WFitLayout.

## ◆ itemAt()

virtual WLayoutItem * Wt::WLayout::itemAt | ( | int | index | ) | const
| pure virtual

Returns the layout item at a specific index.

If there is no item at the `index`, `0` is returned.

See also
  indexOf(WLayoutItem *) const, count()

Implemented in Wt::WBorderLayout, Wt::WBoxLayout, Wt::WFitLayout, and Wt::WGridLayout.

## ◆ layout()

virtual WLayout * Wt::WLayout::layout | ( |  | ) |
| overridevirtual

Returns the layout that implements this WLayoutItem.

This implements a type-safe upcasting mechanism to a WLayout.

Implements Wt::WLayoutItem.

## ◆ removeItem()

virtual std::unique_ptr< WLayoutItem > Wt::WLayout::removeItem | ( | WLayoutItem * | item | ) |
| pure virtual

Removes a layout item (widget or nested layout).

See also
  addItem(WLayoutItem *), removeWidget(WWidget *)

Implemented in Wt::WBorderLayout, Wt::WBoxLayout, Wt::WFitLayout, and Wt::WGridLayout.

## ◆ removeWidget()

std::unique_ptr< WWidget > Wt::WLayout::removeWidget | ( | WWidget * | widget | ) |

Removes the given widget from the layout.

This method finds the corresponding WWidgetItem and calls removeItem(WLayoutItem *), and returns the widget.

See also
  addWidget(WWidget *), removeItem(WLayoutItem *)

## ◆ setContentsMargins()

void Wt::WLayout::setContentsMargins | ( | int | left,
|  | int | top,
|  | int | right,
|  | int | bottom )

Set contents margins (in pixels).

The default contents margins are 9 pixels in all directions.

Note
  Only used when the layout manager is applied to a WContainerWidget.

See also
  setContentsMargins()

## ◆ setDefaultImplementation()

static void Wt::WLayout::setDefaultImplementation | ( | LayoutImplementation | implementation | ) |
| static

Sets the preferred layout implementation globally.

The default implementation for box layouts and fit layouts is Flex (if supported by the browser). Otherwise a fallback to JavaScript is used.

Because there are cases where Flex does not work properly, this method can be used to set the global preferred implementation to instead. Since this is a system-wide setting, and not a per-session setting, you should call this function before any session is created, e.g. in main() before calling WRun(). setPreferredImplementation()

## ◆ setPreferredImplementation()

void Wt::WLayout::setPreferredImplementation | ( | LayoutImplementation | implementation | ) |

Set the preferred layout implementation.

The default implementation for box layouts and fit layouts is Flex (if supported by the browser). Otherwise a fallback to JavaScript is used.

See also
  setDefaultImplementation()

## ◆ update()

void Wt::WLayout::update | ( | WLayoutItem * | item = nullptr | ) |
| protected

Update the layout.

Must be called whenever some properties of the layout have changed.

## ◆ widget()

virtual WWidget * Wt::WLayout::widget | ( |  | ) |
| overridevirtual

Returns the widget that is held by this WLayoutItem.

This implements a type-safe upcasting mechanism to a WWidgetItem.

Implements Wt::WLayoutItem.