ManaPlus
Public Member Functions | Private Attributes
LayoutHelper Class Reference

#include <layouthelper.h>

Inheritance diagram for LayoutHelper:
WidgetListener

Public Member Functions

 LayoutHelper (BasicContainer2 *const container)
 
 ~LayoutHelper ()
 
const LayoutgetLayout () const A_CONST
 
void reflowLayout (int w, int h)
 
LayoutCellplace (const int x, const int y, Widget *const wg, const int w, const int h)
 
ContainerPlacer getPlacer (const int x, const int y)
 
void widgetResized (const Event &event)
 
- Public Member Functions inherited from WidgetListener
virtual ~WidgetListener ()
 
virtual void widgetMoved (const Event &event)
 
virtual void widgetHidden (const Event &event)
 
virtual void widgetShown (const Event &event)
 

Private Attributes

Layout mLayout
 
BasicContainer2mContainer
 

Additional Inherited Members

- Protected Member Functions inherited from WidgetListener
 WidgetListener ()
 

Detailed Description

A helper class for adding a layout to a Guichan container widget. The layout will register itself as a widget listener and relayout the widgets in the container dynamically on resize.

Definition at line 39 of file layouthelper.h.

Constructor & Destructor Documentation

◆ LayoutHelper()

LayoutHelper::LayoutHelper ( BasicContainer2 *const  container)
explicit

Constructor.

Definition at line 31 of file layouthelper.cpp.

31  :
33  mLayout(),
34  mContainer(container)
35 {
36  if (mContainer != nullptr)
38 }
Layout mLayout
Definition: layouthelper.h:92
BasicContainer2 * mContainer
Definition: layouthelper.h:93
void addWidgetListener(WidgetListener *const widgetListener)
Definition: widget.cpp:302

References Widget::addWidgetListener(), and mContainer.

◆ ~LayoutHelper()

LayoutHelper::~LayoutHelper ( )

Destructor.

Definition at line 40 of file layouthelper.cpp.

41 {
42  if (mContainer != nullptr)
44 }
void removeWidgetListener(WidgetListener *const widgetListener)
Definition: widget.cpp:307

References mContainer, and Widget::removeWidgetListener().

Member Function Documentation

◆ getLayout()

const Layout & LayoutHelper::getLayout ( ) const

Gets the layout handler.

Definition at line 46 of file layouthelper.cpp.

47 {
48  return mLayout;
49 }

References mLayout.

Referenced by StatsClanTab::updateClan(), and RelationClanTab::updateClan().

◆ getPlacer()

ContainerPlacer LayoutHelper::getPlacer ( const int  x,
const int  y 
)

◆ place()

LayoutCell & LayoutHelper::place ( const int  x,
const int  y,
Widget *const  wg,
const int  w,
const int  h 
)

Adds a widget to the container and sets it at given cell.

Definition at line 51 of file layouthelper.cpp.

54 {
55  if (mContainer != nullptr)
56  mContainer->add(wg);
57  return mLayout.place(wg, x, y, w, h);
58 }
virtual void add(Widget *const widget)
LayoutCell & place(Widget *const wg, const int x, const int y, const int w, const int h)
Definition: layoutcell.cpp:111

References BasicContainer2::add(), mContainer, mLayout, LayoutCell::place(), x, and y.

◆ reflowLayout()

void LayoutHelper::reflowLayout ( int  w,
int  h 
)

Computes the position of the widgets according to the current layout. Resizes the managed container so that the layout fits.

Note
This function is meant to be called with fixed-size containers.
Parameters
wif non-zero, force the container to this width.
hif non-zero, force the container to this height.

Definition at line 65 of file layouthelper.cpp.

66 {
67  mLayout.reflow(w, h);
68  if (mContainer != nullptr)
69  mContainer->setSize(w, h);
70 }
void reflow(int &nW, int &nH)
Definition: layout.cpp:36
void setSize(const int width, const int height)
Definition: widget.cpp:367

References mContainer, mLayout, Layout::reflow(), and Widget::setSize().

◆ widgetResized()

void LayoutHelper::widgetResized ( const Event event)
virtual

Called whenever the managed container changes size.

Reimplemented from WidgetListener.

Definition at line 72 of file layouthelper.cpp.

73 {
74  if (mContainer == nullptr)
75  return;
76  const Rect area = mContainer->getChildrenArea();
77  int w = area.width;
78  int h = area.height;
79  mLayout.reflow(w, h);
80 }
Definition: rect.h:74
int width
Definition: rect.h:219
int height
Definition: rect.h:224

References BasicContainer::getChildrenArea(), Rect::height, mContainer, mLayout, Layout::reflow(), and Rect::width.

Field Documentation

◆ mContainer

BasicContainer2* LayoutHelper::mContainer
private

Managed container

Definition at line 93 of file layouthelper.h.

Referenced by getPlacer(), LayoutHelper(), place(), reflowLayout(), widgetResized(), and ~LayoutHelper().

◆ mLayout

Layout LayoutHelper::mLayout
private

Layout handler

Definition at line 92 of file layouthelper.h.

Referenced by getLayout(), getPlacer(), place(), reflowLayout(), and widgetResized().


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