|
FifeGUI 0.2.0
A C++ GUI library designed for games.
|
#include <listbox.hpp>
Public Member Functions | |
| void | addSelectionListener (SelectionListener *selectionListener) |
| void | adjustSize () override |
| void | draw (Graphics *graphics) override |
| ListModel * | getListModel () const |
| virtual unsigned int | getRowHeight () const |
| int | getSelected () const |
| bool | isWrappingEnabled () const |
| void | keyPressed (KeyEvent &keyEvent) override |
| ListBox (ListBox &&)=delete | |
| ListBox (ListBox const &)=delete | |
| ListBox (ListModel *listModel) | |
| void | logic () override |
| void | mouseDragged (MouseEvent &mouseEvent) override |
| void | mousePressed (MouseEvent &mouseEvent) override |
| void | mouseWheelMovedDown (MouseEvent &mouseEvent) override |
| void | mouseWheelMovedUp (MouseEvent &mouseEvent) override |
| ListBox & | operator= (ListBox &&)=delete |
| ListBox & | operator= (ListBox const &)=delete |
| void | removeSelectionListener (SelectionListener *selectionListener) |
| void | resizeToContent () |
| void | resizeToContent (bool recursion) override |
| void | setListModel (ListModel *listModel) |
| void | setSelected (int selected) |
| void | setWrappingEnabled (bool wrappingEnabled) |
| 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 | expandContent (bool recursion) |
| 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 |
| virtual Rectangle | getChildrenArea () |
| unsigned int | getChildrenCount () const |
| Rectangle const & | getDimension () const |
| Size const & | getFixedSize () const |
| Font * | getFont () 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 Widget * | getParent () const |
| Color const & | getSelectionColor () const |
| SelectionMode | getSelectionMode () const |
| virtual Widget * | getTop () const |
| unsigned int | getVisibleChildrenCount () const |
| Widget * | getWidgetAt (int x, int y) |
| virtual Widget * | getWidgetAt (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 | isLayouted () |
| 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 | moveToBottom (Widget *widget) |
| virtual void | moveToTop (Widget *widget) |
| Widget & | operator= (Widget &&)=delete |
| Widget & | operator= (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 | |
| Public Member Functions inherited from fcn::MouseListener | |
| virtual void | mouseClicked (MouseEvent &mouseEvent) |
| virtual void | mouseEntered (MouseEvent &mouseEvent) |
| virtual void | mouseExited (MouseEvent &mouseEvent) |
| MouseListener (MouseListener &&)=default | |
| MouseListener (MouseListener const &)=default | |
| virtual void | mouseMoved (MouseEvent &mouseEvent) |
| virtual void | mouseReleased (MouseEvent &mouseEvent) |
| virtual void | mouseWheelMovedLeft (MouseEvent &mouseEvent) |
| virtual void | mouseWheelMovedRight (MouseEvent &mouseEvent) |
| MouseListener & | operator= (MouseListener &&)=default |
| MouseListener & | operator= (MouseListener const &)=default |
| Public Member Functions inherited from fcn::KeyListener | |
| KeyListener (KeyListener &&)=default | |
| KeyListener (KeyListener const &)=default | |
| virtual void | keyReleased (KeyEvent &keyEvent) |
| KeyListener & | operator= (KeyListener &&)=default |
| KeyListener & | operator= (KeyListener const &)=default |
Protected Types | |
| using | SelectionListenerIterator = SelectionListenerList::iterator |
| using | SelectionListenerList = std::list<SelectionListener*> |
Protected Member Functions | |
| void | adjustSizeImpl () |
| void | distributeValueChangedEvent () |
| 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 () |
| virtual Widget * | findWidgetById (std::string const &id) |
| std::list< Widget * > const & | getChildren () const |
| virtual void | remove (Widget *widget) |
| virtual void | removeAllChildren () |
| void | resizeToChildren () |
| Protected Member Functions inherited from fcn::MouseListener | |
| MouseListener ()=default | |
| Protected Member Functions inherited from fcn::KeyListener | |
| KeyListener ()=default | |
Additional Inherited Members | |
| Public Types inherited from fcn::Widget | |
| enum class | SelectionMode : uint8_t { None = 0 , Border = 1 , Background = 2 } |
| 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) |
| Static Protected Attributes inherited from fcn::Widget | |
| static DefaultFont | mDefaultFont |
| static Font * | mGlobalFont = nullptr |
| static DeathListener * | mGuiDeathListener = nullptr |
| static VisibilityEventHandler * | mVisibilityEventHandler = nullptr |
| static std::list< Widget * > | mWidgetInstances |
A scrollable list box allowing item selection.
To be able display a list the list box uses a user provided list model. A list model can be any class that implements the ListModel interface.
If an item is selected in the list box a select event will be sent to all selection listeners of the list box. If an item is selected by using a mouse click or by using the enter or space key an action event will be sent to all action listeners of the list box.
Definition at line 33 of file listbox.hpp.
|
protected |
Typedef.
Definition at line 199 of file listbox.hpp.
|
protected |
Typdef.
Definition at line 189 of file listbox.hpp.
| fcn::ListBox::ListBox | ( | ) |
Definition at line 18 of file listbox.cpp.
|
explicit |
Constructor.
| listModel | the list model to use. |
Definition at line 27 of file listbox.cpp.
References fcn::Widget::addKeyListener(), fcn::Widget::addMouseListener(), fcn::Widget::setFocusable(), setListModel(), and fcn::Widget::setWidth().
| void fcn::ListBox::addSelectionListener | ( | SelectionListener * | selectionListener | ) |
Adds a selection listener to the list box.
When the selection changes an event will be sent to all selection listeners of the list box.
If you delete your selection listener, be sure to also remove it using removeSelectionListener().
| selectionListener | The selection listener to add. |
Definition at line 251 of file listbox.cpp.
References mSelectionListeners.
|
overridevirtual |
Resizes the widget's size to fit the content exactly.
Reimplemented from fcn::Widget.
Definition at line 236 of file listbox.cpp.
References adjustSizeImpl().
|
protected |
Concrete implementation of adjustSize.
Constructors and internal methods should call this non-virtual helper to avoid virtual dispatch during construction.
Definition at line 221 of file listbox.cpp.
References fcn::Widget::getFont(), getRowHeight(), fcn::Widget::getWidth(), mListModel, fcn::Widget::setHeight(), and fcn::Widget::setWidth().
Referenced by adjustSize(), logic(), resizeToContent(), and setListModel().
|
protected |
Distributes a value changed event to all selection listeners of the list box.
Definition at line 261 of file listbox.cpp.
References mSelectionListeners.
Referenced by setSelected().
|
overridevirtual |
Draws the widget.
The call to draw is initiated by the widget's parent. The graphics object is set up so that all drawing is relative to the widget, i.e coordinate (0,0) is the top left corner of the widget. It is not possible to draw outside of a widget's dimension. If a widget has children, the parent's draw function will always be called before the children's draw functions are called.
NOTE: A widget with children won't draw its children unless the children area given by Widget::getChildrenArea returns a none empty rectangle inside the widgets dimension. The children area is considered relative to the widget's position.
| Graphics & Rendering | A graphics object to draw with. |
Implements fcn::Widget.
Definition at line 37 of file listbox.cpp.
References fcn::Graphics::drawText(), fcn::Graphics::fillRectangle(), fcn::Widget::getBackgroundColor(), fcn::Graphics::getCurrentClipArea(), fcn::Widget::getFont(), fcn::Widget::getForegroundColor(), fcn::Widget::getHeight(), getRowHeight(), fcn::Widget::getSelectionColor(), fcn::Widget::getWidth(), fcn::Widget::getY(), fcn::Rectangle::height, mListModel, mSelected, fcn::Graphics::setColor(), and fcn::Graphics::setFont().
| ListModel * fcn::ListBox::getListModel | ( | ) | const |
Gets the list model used.
Definition at line 211 of file listbox.cpp.
References mListModel.
Referenced by keyPressed().
|
virtual |
Gets the height of a row.
Should be overridden if another row height than the font height is preferred.
Definition at line 271 of file listbox.cpp.
References fcn::Widget::getFont(), and fcn::Font::getHeight().
Referenced by adjustSizeImpl(), draw(), mousePressed(), and setSelected().
| int fcn::ListBox::getSelected | ( | ) | const |
Gets the selected item as an index in the list model.
Definition at line 102 of file listbox.cpp.
References mSelected.
Referenced by keyPressed(), mouseWheelMovedDown(), and mouseWheelMovedUp().
| bool fcn::ListBox::isWrappingEnabled | ( | ) | const |
Checks whether the list box wraps when selecting items with a keyboard.
Wrapping means that the selection of items will be wrapped. That is, if the first item is selected and up is pressed, the last item will get selected. If the last item is selected and down is pressed, the first item will get selected.
Definition at line 241 of file listbox.cpp.
References mWrappingEnabled.
|
overridevirtual |
Called if a key is pressed when the widget has keyboard focus.
If a key is held down the widget will generate multiple key presses.
| keyEvent | Describes the event. |
Reimplemented from fcn::KeyListener.
Definition at line 135 of file listbox.cpp.
References fcn::InputEvent::consume(), fcn::Widget::distributeActionEvent(), fcn::KeyEvent::getKey(), getListModel(), getSelected(), fcn::Key::getValue(), mSelected, mWrappingEnabled, and setSelected().
|
overridevirtual |
Called for all widgets in the gui each time Gui::logic is called.
You can do logic stuff here like playing an animation.
Reimplemented from fcn::Widget.
Definition at line 97 of file listbox.cpp.
References adjustSizeImpl().
|
overridevirtual |
Called when the mouse has moved and the mouse has previously been pressed on the widget.
| mouseEvent | Describes the event. |
Reimplemented from fcn::MouseListener.
Definition at line 199 of file listbox.cpp.
References fcn::InputEvent::consume().
|
overridevirtual |
Called when a mouse button has been pressed on the widget area.
NOTE: A mouse press is NOT equal to a mouse click. Use mouseClickMessage to check for mouse clicks.
| mouseEvent | Describes the event. |
Reimplemented from fcn::MouseListener.
Definition at line 171 of file listbox.cpp.
References fcn::Widget::distributeActionEvent(), fcn::MouseEvent::getButton(), getRowHeight(), fcn::MouseEvent::getY(), and setSelected().
|
overridevirtual |
Called when the mouse wheel has moved down on the widget area.
| mouseEvent | Describes the event. |
Reimplemented from fcn::MouseListener.
Definition at line 190 of file listbox.cpp.
References fcn::InputEvent::consume(), getSelected(), fcn::Widget::isFocused(), and setSelected().
|
overridevirtual |
Called when the mouse wheel has moved up on the widget area.
| mouseEvent | Describes the event. |
Reimplemented from fcn::MouseListener.
Definition at line 179 of file listbox.cpp.
References fcn::InputEvent::consume(), getSelected(), fcn::Widget::isFocused(), and setSelected().
| void fcn::ListBox::removeSelectionListener | ( | SelectionListener * | selectionListener | ) |
Removes a selection listener from the list box.
| selectionListener | The selection listener to remove. |
Definition at line 256 of file listbox.cpp.
References mSelectionListeners.
|
inline |
Resizes the widget's size to fit the content exactly, calls recursively all childs.
This is a convenience wrapper that calls resizeToContent(true).
Definition at line 1417 of file widget.hpp.
|
overridevirtual |
Resize this widget to fit its content.
| recursion | If true, perform the resize operation recursively on children. |
Reimplemented from fcn::Widget.
Definition at line 216 of file listbox.cpp.
References adjustSizeImpl().
| void fcn::ListBox::setListModel | ( | ListModel * | listModel | ) |
Sets the list model to use.
| listModel | the list model to use. |
Definition at line 204 of file listbox.cpp.
References adjustSizeImpl(), mListModel, and mSelected.
Referenced by ListBox().
| void fcn::ListBox::setSelected | ( | int | selected | ) |
Sets the selected item.
The selected item is represented by an index from the list model.
| selected | the selected item as an index from the list model. |
Definition at line 107 of file listbox.cpp.
References distributeValueChangedEvent(), getRowHeight(), fcn::Rectangle::height, mListModel, mSelected, fcn::Widget::showPart(), and fcn::Rectangle::y.
Referenced by keyPressed(), mousePressed(), mouseWheelMovedDown(), and mouseWheelMovedUp().
| void fcn::ListBox::setWrappingEnabled | ( | bool | wrappingEnabled | ) |
Sets the list box to wrap or not when selecting items with a keyboard.
Wrapping means that the selection of items will be wrapped. That is, if the first item is selected and up is pressed, the last item will get selected. If the last item is selected and down is pressed, the first item will get selected.
Definition at line 246 of file listbox.cpp.
References mWrappingEnabled.
|
protected |
The list model to use.
Definition at line 179 of file listbox.hpp.
Referenced by adjustSizeImpl(), draw(), getListModel(), setListModel(), and setSelected().
|
protected |
The selected item as an index in the list model.
Definition at line 174 of file listbox.hpp.
Referenced by draw(), getSelected(), keyPressed(), setListModel(), and setSelected().
|
protected |
The selection listeners of the list box.
Definition at line 194 of file listbox.hpp.
Referenced by addSelectionListener(), distributeValueChangedEvent(), and removeSelectionListener().
|
protected |
True if wrapping is enabled, false otherwise.
Definition at line 184 of file listbox.hpp.
Referenced by isWrappingEnabled(), keyPressed(), and setWrappingEnabled().