FifeGUI 0.2.0
A C++ GUI library designed for games.
fcn::AdjustingContainer Class Reference

#include <adjustingcontainer.hpp>

Inheritance diagram for fcn::AdjustingContainer:
fcn::Container fcn::Widget

Public Types

enum class  Alignment : uint8_t { Left = 0 , Center , Right }
Public Types inherited from fcn::Container
enum class  LayoutPolicy : uint8_t {
  Absolute , AutoSize , Vertical , Horizontal ,
  Circular
}
Public Types inherited from fcn::Widget
enum class  SelectionMode : uint8_t { None = 0 , Border = 1 , Background = 2 }

Public Member Functions

void add (Widget *widget) override
void add (Widget *widget, int x, int y) override
virtual void adjustContent ()
 AdjustingContainer (AdjustingContainer &&)=delete
 AdjustingContainer (AdjustingContainer const &)=delete
void adjustSize () override
void expandContent (bool recursion) override
Rectangle getChildrenArea () override
Alignment getColumnAlignment (unsigned int column) const
virtual unsigned int getNumberOfColumns () const
AdjustingContainer & operator= (AdjustingContainer &&)=delete
AdjustingContainer & operator= (AdjustingContainer const &)=delete
void remove (Widget *widget) override
void removeAllChildren () override
void resizeToContent (bool recursion) override
virtual void setColumnAlignment (unsigned int column, Alignment alignment)
virtual void setNumberOfColumns (unsigned int numberOfColumns)
Public Member Functions inherited from fcn::Container
void addContainerListener (ContainerListener *containerListener)
virtual void addWidget (std::unique_ptr< Widget > widget)
virtual void addWidget (std::unique_ptr< Widget > widget, int x, int y)
void adjustSize () override
 Container ()
 Container (Container &&)=delete
 Container (Container const &)=delete
void draw (Graphics *graphics) override
void expandContent ()
void expandContent (bool recursion) override
WidgetfindWidgetById (std::string const &id) override
WidgetgetBackgroundWidget ()
WidgetgetChild (unsigned int index) const
Rectangle getChildrenArea () override
virtual unsigned int getHorizontalSpacing () const
virtual LayoutPolicy getLayout () const
virtual unsigned int getVerticalSpacing () const
bool isLayouted () override
virtual bool isOpaque () const
virtual bool isUniformSize () const
Containeroperator= (Container &&)=delete
Containeroperator= (Container const &)=delete
void remove (Widget *widget) override
void removeAllChildren () override
void removeContainerListener (ContainerListener *containerListener)
void resizeToContent ()
void resizeToContent (bool recursion) override
void setBackgroundWidget (Widget *widget)
virtual void setHorizontalSpacing (unsigned int spacing)
virtual void setLayout (LayoutPolicy policy)
virtual void setOpaque (bool opaque)
virtual void setUniformSize (bool uniform)
virtual void setVerticalSpacing (unsigned int spacing)
Public Member Functions inherited from fcn::Widget
virtual void _draw (Graphics *graphics)
virtual FocusHandler_getFocusHandler ()
virtual std::list< FocusListener * > const & _getFocusListeners ()
virtual FocusHandler_getInternalFocusHandler ()
virtual std::list< KeyListener * > const & _getKeyListeners ()
virtual std::list< MouseListener * > const & _getMouseListeners ()
virtual void _logic ()
virtual void _setFocusHandler (FocusHandler *focusHandler)
virtual void _setParent (Widget *parent)
void adaptLayout ()
virtual void adaptLayout (bool top)
void addActionListener (ActionListener *actionListener)
void addDeathListener (DeathListener *deathListener)
void addFocusListener (FocusListener *focusListener)
void addKeyListener (KeyListener *keyListener)
void addMouseListener (MouseListener *mouseListener)
void addWidgetListener (WidgetListener *widgetListener)
virtual void drawBorder (Graphics *graphics)
virtual void drawOutline (Graphics *graphics)
virtual void drawSelectionFrame (Graphics *graphics)
void expandContent ()
virtual void focusNext ()
virtual void focusPrevious ()
virtual void fontChanged ()
virtual void getAbsolutePosition (int &x, int &y) const
std::string const & getActionEventId () const
Color const & getBackgroundColor () const
Color const & getBaseColor () const
Color const & getBorderColor () const
unsigned int getBorderSize () const
unsigned int getChildrenCount () const
Rectangle const & getDimension () const
Size const & getFixedSize () const
FontgetFont () const
Color const & getForegroundColor () const
int getHeight () const
std::string const & getId () const
void getLastPosition (int &x, int &y) const
int getMarginBottom () const
int getMarginLeft () const
int getMarginRight () const
int getMarginTop () const
Size const & getMaxSize () const
Size const & getMinSize () const
Color const & getOutlineColor () const
unsigned int getOutlineSize () const
unsigned int getPaddingBottom () const
unsigned int getPaddingLeft () const
unsigned int getPaddingRight () const
unsigned int getPaddingTop () const
virtual WidgetgetParent () const
Color const & getSelectionColor () const
SelectionMode getSelectionMode () const
virtual WidgetgetTop () const
unsigned int getVisibleChildrenCount () const
WidgetgetWidgetAt (int x, int y)
virtual WidgetgetWidgetAt (int x, int y, Widget *exclude)
std::list< Widget * > getWidgetsIn (Rectangle const &area)
virtual std::list< Widget * > getWidgetsIn (Rectangle const &area, Widget *ignore)
int getWidth () const
int getX () const
int getY () const
bool isEnabled () const
bool isFixedSize () const
bool isFocusable () const
virtual bool isFocused () const
bool isHorizontalExpand () const
bool isLastPositionSet () const
virtual bool isModalFocusable () const
virtual bool isModalFocused () const
virtual bool isModalMouseInputFocusable () const
virtual bool isModalMouseInputFocused () const
bool isSetVisible () const
bool isTabInEnabled () const
bool isTabOutEnabled () const
bool isVerticalExpand () const
bool isVisible () const
virtual void logic ()
virtual void moveToBottom (Widget *widget)
virtual void moveToTop (Widget *widget)
Widgetoperator= (Widget &&)=delete
Widgetoperator= (Widget const &)=delete
virtual void releaseModalFocus ()
virtual void releaseModalMouseInputFocus ()
void removeActionListener (ActionListener *actionListener)
void removeDeathListener (DeathListener *deathListener)
void removeFocusListener (FocusListener *focusListener)
void removeKeyListener (KeyListener *keyListener)
void removeMouseListener (MouseListener *mouseListener)
void removeWidgetListener (WidgetListener *widgetListener)
virtual void requestFocus ()
virtual void requestModalFocus ()
virtual void requestModalMouseInputFocus ()
virtual void requestMoveToBottom ()
virtual void requestMoveToTop ()
void resizeToContent ()
void setActionEventId (std::string const &actionEventId)
virtual void setBackgroundColor (Color const &color)
virtual void setBaseColor (Color const &color)
virtual void setBorderColor (Color const &color)
void setBorderSize (unsigned int size)
void setDimension (Rectangle const &dimension)
void setEnabled (bool enabled)
void setFixedSize (Size const &size)
void setFocusable (bool focusable)
virtual void setFont (Font *font)
virtual void setForegroundColor (Color const &color)
void setHeight (int height)
void setHorizontalExpand (bool expand)
void setId (std::string const &id)
void setInternalFocusHandler (FocusHandler *internalFocusHandler)
void setLastPosition (int x, int y)
void setMargin (int margin)
void setMarginBottom (int margin)
void setMarginLeft (int margin)
void setMarginRight (int margin)
void setMarginTop (int margin)
void setMaxSize (Size const &size)
void setMinSize (Size const &size)
virtual void setOutlineColor (Color const &color)
void setOutlineSize (unsigned int size)
void setPadding (unsigned int padding)
void setPaddingBottom (unsigned int padding)
void setPaddingLeft (unsigned int padding)
void setPaddingRight (unsigned int padding)
void setPaddingTop (unsigned int padding)
void setPosition (int x, int y)
virtual void setSelectionColor (Color const &color)
virtual void setSelectionMode (SelectionMode mode)
void setSize (int width, int height)
void setTabInEnabled (bool enabled)
void setTabOutEnabled (bool enabled)
void setVerticalExpand (bool expand)
void setVisible (bool visible)
void setWidth (int width)
void setX (int x)
void setY (int y)
virtual void showPart (Rectangle rectangle)
virtual void showWidgetPart (Widget *widget, Rectangle area)
 Widget ()
 Widget (Widget &&)=delete
 Widget (Widget const &)=delete

Protected Attributes

std::vector< AlignmentmColumnAlignment
std::vector< unsigned int > mColumnWidths
std::vector< Widget * > mContainedWidgets
unsigned int mHeight {0}
unsigned int mNumberOfColumns {1}
unsigned int mNumberOfRows {1}
std::vector< unsigned int > mRowHeights
unsigned int mWidth {0}
Protected Attributes inherited from fcn::Container
WidgetmBackgroundWidget {nullptr}
ContainerListenerList mContainerListeners
unsigned int mHorizontalSpacing {2}
LayoutPolicy mLayout {LayoutPolicy::Absolute}
bool mOpaque {true}
bool mUniform {false}
unsigned int mVerticalSpacing {2}
Protected Attributes inherited from fcn::Widget
std::string mActionEventId
std::list< ActionListener * > mActionListeners
Color mBackgroundColor {0xf9fafb}
Color mBaseColor {0xe5e7eb}
Color mBorderColor {0xd1d5db}
unsigned int mBorderSize {0}
std::list< Widget * > mChildren
FontmCurrentFont {nullptr}
std::list< DeathListener * > mDeathListeners
Rectangle mDimension
bool mEnabled {true}
Size mFixedSize {-1, -1}
bool mFixedSizeUsed {false}
bool mFocusable {false}
FocusHandlermFocusHandler {nullptr}
std::list< FocusListener * > mFocusListeners
Color mForegroundColor {0x1f2933}
bool mHExpand {false}
std::string mId
FocusHandlermInternalFocusHandler {nullptr}
std::list< KeyListener * > mKeyListeners
int mLastX {0}
int mLastY {0}
int mMarginBottom {0}
int mMarginLeft {0}
int mMarginRight {0}
int mMarginTop {0}
Size mMaxSize {std::numeric_limits<int>::max(), std::numeric_limits<int>::max()}
Size mMinSize {0, 0}
std::list< MouseListener * > mMouseListeners
Rectangle mOffsetRect
Color mOutlineColor {0x9ca3af}
unsigned int mOutlineSize {0}
unsigned int mPaddingBottom {0}
unsigned int mPaddingLeft {0}
unsigned int mPaddingRight {0}
unsigned int mPaddingTop {0}
WidgetmParent {nullptr}
Color mSelectionColor {0x3b82f6}
SelectionMode mSelectionMode {SelectionMode::None}
bool mTabIn {true}
bool mTabOut {true}
bool mVExpand {false}
bool mVisible {true}
std::list< WidgetListener * > mWidgetListeners

Additional Inherited Members

Static Public Member Functions inherited from fcn::Widget
static DeathListener_getGuiDeathListener ()
static VisibilityEventHandler_getVisibilityEventHandler ()
static void _setGuiDeathListener (DeathListener *deathListener)
static void _setVisibilityEventHandler (VisibilityEventHandler *visibilityEventHandler)
static void setGlobalFont (Font *font)
static bool widgetExists (Widget const *widget)
Protected Types inherited from fcn::Container
using ContainerListenerIterator = ContainerListenerList::iterator
using ContainerListenerList = std::list<ContainerListener*>
Protected Member Functions inherited from fcn::Container
void distributeWidgetAddedEvent (Widget *source)
void distributeWidgetRemovedEvent (Widget *source)
Protected Member Functions inherited from fcn::Widget
void add (Widget *widget)
void calculateSize ()
void distributeActionEvent ()
void distributeAncestorHiddenEvent (Widget *ancestor)
void distributeAncestorMovedEvent (Widget *ancestor)
void distributeAncestorShownEvent (Widget *ancestor)
void distributeHiddenEvent ()
void distributeMovedEvent ()
void distributeResizedEvent ()
void distributeShownEvent ()
std::list< Widget * > const & getChildren () const
void resizeToChildren ()
Static Protected Attributes inherited from fcn::Widget
static DefaultFont mDefaultFont
static FontmGlobalFont = nullptr
static DeathListenermGuiDeathListener = nullptr
static VisibilityEventHandlermVisibilityEventHandler = nullptr
static std::list< Widget * > mWidgetInstances

Detailed Description

Self-adjusting Container class.

AdjustingContainers are an easy way to have the GUI position a group of widgets for you. It organizes elements in a table layout with fixed columns and variable rows.

The user specifies

* <ul>
*   <li>the number of columns</li>
*   <li>horizontal spacing between columns</li>
*   <li>vertical spacing between rows</li>
*   <li>padding around the sides of the container</li>
*   <li>each column's alignment</li>
* </ul>
* 

These properties give the user a lot of flexibility to make the widgets look just right.

AdjustingContainer *adjust = new AdjustingContainer;
adjust->setPadding(5, 5, 5, 5); //left, right, top, bottom
adjust->setVerticalSpacing(3);
adjust->setColumns(3);
adjust->setColumnAlignment(0, AdjustingContainer::LEFT);
adjust->setColumnAlignment(1, AdjustingContainer::CENTER);
adjust->setColumnAlignment(2, AdjustingContainer::RIGHT);
top->add(adjust);
for(int j = 0; j < 9; j++)
{
int r = rand() % 3;
if(r == 0)
l = new fcn::Label("Short");
else if(r == 1)
l = new fcn::Label("A longer phrase");
else
l = new fcn::Label("Super long and wordy text");
adjust->add(l);
virtual void setColumnAlignment(unsigned int column, Alignment alignment)
Set a specific column's alignment.
void add(Widget *widget) override
Adds a widget to the container.
virtual void setHorizontalSpacing(unsigned int spacing)
Set the horizontal spacing between columns.
virtual void setVerticalSpacing(unsigned int spacing)
Set the vertical spacing between rows.
Displays a text caption.
Definition label.hpp:22
void setPadding(unsigned int padding)
Sets all 4 paddings to one value.
Definition widget.cpp:434

Output:

* <pre>
*+---------------------------------------------------------------------------+
*|                                                                           |
*| A longer phrase              Short             Super long and wordy text |
*|                                                                           |
*| Short             Super long and wordy text                        Short |
*|                                                                           |
*| Short                   A longer phrase                   A longer phrase |
*|                                                                           |
*+---------------------------------------------------------------------------+
* </pre>
* 

As you can see, each column is only as big as its largest element. The AdjustingContainer will resize itself and rearrange its contents based on whatever widgets it contains, allowing dynamic addition and removal while the program is running. It also plays nicely with ScrollAreas, allowing you to show a fixed, maximum size while not limiting the actual container.

Definition at line 83 of file adjustingcontainer.hpp.

Member Enumeration Documentation

◆ Alignment

enum class fcn::AdjustingContainer::Alignment : uint8_t
strong

Possible alignment values for each column.

LEFT - Align content to the left of the column. MIDDLE - Align content to the middle of the column. RIGHT - Align content to the right of the column.

Definition at line 93 of file adjustingcontainer.hpp.

Constructor & Destructor Documentation

◆ AdjustingContainer()

fcn::AdjustingContainer::AdjustingContainer ( )

Definition at line 14 of file adjustingcontainer.cpp.

Member Function Documentation

◆ add() [1/2]

void fcn::AdjustingContainer::add ( Widget * widget)
overridevirtual

Adds a widget to the container.

Parameters
widgetThe widget to add.
See also
remove, clear

Reimplemented from fcn::Container.

Definition at line 84 of file adjustingcontainer.cpp.

References fcn::Container::add(), and mContainedWidgets.

Referenced by add().

◆ add() [2/2]

void fcn::AdjustingContainer::add ( Widget * widget,
int x,
int y )
overridevirtual

Adds a widget to the container and also specifies the widget's position in the container.

The position is relative to the container and not relative to the screen.

Parameters
widgetThe widget to add.
xThe x coordinate for the widget.
yThe y coordinate for the widget.
See also
remove, clear

Reimplemented from fcn::Container.

Definition at line 90 of file adjustingcontainer.cpp.

References add().

◆ adjustContent()

void fcn::AdjustingContainer::adjustContent ( )
virtual

◆ adjustSize()

◆ expandContent()

void fcn::AdjustingContainer::expandContent ( bool recursion)
overridevirtual

Expands child widgets to fit this widget's size.

Parameters
recursionIf true, call expandContent recursively on children.

Reimplemented from fcn::Widget.

Definition at line 66 of file adjustingcontainer.cpp.

◆ getChildrenArea()

Rectangle fcn::AdjustingContainer::getChildrenArea ( )
overridevirtual

Gets the area of the widget occupied by the widget's children.

By default this method returns an empty rectangle as not all widgets are containers. If you want to make a container this method should return the area where the children resides. This method is used when drawing children of a widget when computing clip rectangles for the children.

NOTE: The returned rectangle should be relative to the widget, i.e a rectangle with x and y coordinate (0,0) and with width and height the same as the widget will let the children draw themselves in the whole widget.

An example of a widget that overloads this method is ScrollArea. A ScrollArea has a view of its constant and that view is the children area. The size of a ScrollArea's children area might vary depending on if the scroll bars of the ScrollArea is shown or not.

Returns
The area of the widget occupied by the widget's children.

Reimplemented from fcn::Widget.

Definition at line 68 of file adjustingcontainer.cpp.

References fcn::Widget::getBorderSize(), fcn::Widget::getHeight(), fcn::Widget::getWidth(), fcn::Rectangle::height, fcn::Rectangle::width, fcn::Rectangle::x, and fcn::Rectangle::y.

◆ getColumnAlignment()

AdjustingContainer::Alignment fcn::AdjustingContainer::getColumnAlignment ( unsigned int column) const

Get a specific column's alignment.

Parameters
columnthe column number, starting from 0.
Returns
The column's alignment. See enum with alignments.

Definition at line 52 of file adjustingcontainer.cpp.

References mColumnAlignment.

◆ getNumberOfColumns()

unsigned int fcn::AdjustingContainer::getNumberOfColumns ( ) const
virtual

Get the number of columns the widget is divided.

The number of rows is derived automatically from the number of widgets based on the number of columns.

Returns
The number of columns.

Definition at line 40 of file adjustingcontainer.cpp.

References mNumberOfColumns.

◆ remove()

void fcn::AdjustingContainer::remove ( Widget * widget)
overridevirtual

Removes a specific child from the widget.

THIS METHOD IS NOT SAFE TO CALL INSIDE A WIDGETS LOGIC FUNCTION INSIDE ANY LISTER FUNCTIONS!

Parameters
widgetThe widget to remove.
See also
removeAllChildren

Reimplemented from fcn::Widget.

Definition at line 101 of file adjustingcontainer.cpp.

References mContainedWidgets, and fcn::Container::remove().

◆ removeAllChildren()

void fcn::AdjustingContainer::removeAllChildren ( )
overridevirtual

Remvoes all children from the widget.

THIS METHOD IS NOT SAFE TO CALL INSIDE A WIDGETS LOGIC FUNCTION INSIDE ANY LISTER FUNCTIONS!

See also
remove

Reimplemented from fcn::Widget.

Definition at line 95 of file adjustingcontainer.cpp.

References mContainedWidgets, and fcn::Container::removeAllChildren().

◆ resizeToContent()

void fcn::AdjustingContainer::resizeToContent ( bool recursion)
overridevirtual

Resize the adjusting container to fit its children.

Parameters
recursionIf true, propagate resize to child containers.

Reimplemented from fcn::Widget.

Definition at line 60 of file adjustingcontainer.cpp.

References adjustContent(), and fcn::Container::resizeToContent().

◆ setColumnAlignment()

void fcn::AdjustingContainer::setColumnAlignment ( unsigned int column,
Alignment alignment )
virtual

Set a specific column's alignment.

Parameters
columnthe column number, starting from 0.
alignmentthe column's alignment. See enum with alignments.

Definition at line 45 of file adjustingcontainer.cpp.

References mColumnAlignment.

◆ setNumberOfColumns()

void fcn::AdjustingContainer::setNumberOfColumns ( unsigned int numberOfColumns)
virtual

Set the number of columns to divide the widgets into.

The number of rows is derived automatically from the number of widgets based on the number of columns. Default column alignment is left.

Parameters
numberOfColumnsthe number of columns.

Definition at line 25 of file adjustingcontainer.cpp.

References mColumnAlignment, and mNumberOfColumns.

Member Data Documentation

◆ mColumnAlignment

std::vector<Alignment> fcn::AdjustingContainer::mColumnAlignment
protected

The alignment of each column.

Definition at line 191 of file adjustingcontainer.hpp.

Referenced by adjustContent(), getColumnAlignment(), setColumnAlignment(), and setNumberOfColumns().

◆ mColumnWidths

std::vector<unsigned int> fcn::AdjustingContainer::mColumnWidths
protected

Computed width for each column (in pixels).

Definition at line 186 of file adjustingcontainer.hpp.

Referenced by adjustContent(), and adjustSize().

◆ mContainedWidgets

std::vector<Widget*> fcn::AdjustingContainer::mContainedWidgets
protected

The widgets contained in the adjusting container in layout order.

Definition at line 181 of file adjustingcontainer.hpp.

Referenced by add(), adjustContent(), adjustSize(), remove(), and removeAllChildren().

◆ mHeight

unsigned int fcn::AdjustingContainer::mHeight {0}
protected

Cached container height used during layout.

Definition at line 206 of file adjustingcontainer.hpp.

Referenced by adjustSize().

◆ mNumberOfColumns

unsigned int fcn::AdjustingContainer::mNumberOfColumns {1}
protected

Number of columns in the layout.

Definition at line 211 of file adjustingcontainer.hpp.

Referenced by adjustContent(), adjustSize(), getNumberOfColumns(), and setNumberOfColumns().

◆ mNumberOfRows

unsigned int fcn::AdjustingContainer::mNumberOfRows {1}
protected

Number of rows in the layout (derived from children count).

Definition at line 216 of file adjustingcontainer.hpp.

Referenced by adjustSize().

◆ mRowHeights

std::vector<unsigned int> fcn::AdjustingContainer::mRowHeights
protected

Computed height for each row (in pixels).

Definition at line 196 of file adjustingcontainer.hpp.

Referenced by adjustContent(), and adjustSize().

◆ mWidth

unsigned int fcn::AdjustingContainer::mWidth {0}
protected

Cached container width used during layout.

Definition at line 201 of file adjustingcontainer.hpp.

Referenced by adjustSize().


The documentation for this class was generated from the following files: