Class WLayout

  • All Implemented Interfaces:
    WLayoutItem
    Direct Known Subclasses:
    WBorderLayout, WBoxLayout, WFitLayout, WGridLayout

    public abstract class WLayout
    extends WObject
    implements WLayoutItem
    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 Detail

      • WLayout

        protected WLayout()
        Create a layout.
    • Method Detail

      • setDefaultImplementation

        public static void setDefaultImplementation​(LayoutImplementation implementation)
        Sets the preferred layout implementation globally.

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

        Because there are cases where LayoutImplementation.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()

      • addItem

        public abstract void addItem​(WLayoutItem item)
        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 item)
      • addWidget

        public void addWidget​(WWidget w)
        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 w)
      • getCount

        public abstract int getCount()
        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 getItemAt().

      • indexOf

        public int indexOf​(WLayoutItem item)
        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:
        getItemAt(int index)
      • isImplementationIsFlexLayout

        public boolean isImplementationIsFlexLayout()
      • setObjectName

        public void setObjectName​(java.lang.String name)
        Description copied from class: WObject
        Sets an object name.

        The object name can be used to easily identify a type of object in the DOM, and does not need to be unique. It will usually reflect the widget type or role. The object name is prepended to the auto-generated object WObject.getId().

        The default object name is empty.

        Overrides:
        setObjectName in class WObject
        Parameters:
        name - the object name.
      • update

        protected void update​(WLayoutItem item)
        Update the layout.

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

      • itemAdded

        protected void itemAdded​(WLayoutItem item)
      • itemRemoved

        protected void itemRemoved​(WLayoutItem item)
      • setImpl

        protected void setImpl​(WLayoutImpl impl)
      • updateImplementation

        protected void updateImplementation()