6#include "fifechan/widgets/listbox.hpp"
13#include "fifechan/font.hpp"
14#include "fifechan/graphics.hpp"
15#include "fifechan/key.hpp"
16#include "fifechan/listeners/selectionlistener.hpp"
17#include "fifechan/listmodel.hpp"
18#include "fifechan/mouseinput.hpp"
43 assert(
"graphics must not be null" && graphics !=
nullptr);
44 assert(
"font must not be null" &&
getFont() !=
nullptr);
64 int numberOfRows = (currentClipArea.
height / rowHeight) + 2;
66 numberOfRows = std::min(numberOfRows,
mListModel->getNumberOfElements());
76 startRow = -1 * (
getY() / rowHeight);
84 int y = rowHeight * startRow;
85 for (i = startRow; i < startRow + numberOfRows; ++i) {
121 }
else if (selected >=
mListModel->getNumberOfElements()) {
144 Key
const key = keyEvent.
getKey();
146 if (key.getValue() == fcn::Key::KEY_RETURN || key.getValue() == fcn::Key::SPACE) {
149 }
else if (key.getValue() == fcn::Key::UP) {
150 assert(
"list model must exist for UP" &&
mListModel !=
nullptr);
162 }
else if (key.getValue() == fcn::Key::DOWN) {
163 assert(
"list model must exist for DOWN" &&
mListModel !=
nullptr);
171 }
else if (key.getValue() == fcn::Key::HOME) {
174 }
else if (key.getValue() == fcn::Key::END) {
175 assert(
"list model must exist for END" &&
mListModel !=
nullptr);
183 if (mouseEvent.
getButton() == MouseEvent::Button::Left) {
228 static_cast<void>(recursion);
236 int const elements =
mListModel->getNumberOfElements();
237 for (
int i = 0; i < elements; ++i) {
278 (*iter)->valueChanged(event);
A rectangle specifically used for clipping rendering regions.
virtual int getHeight() const =0
Gets the height of the glyphs in the font.
Abstract interface providing primitive drawing functions (lines, rectangles, etc.).
void drawText(std::string const &text, int x, int y)
Draws text with a default left alignment.
virtual ClipRectangle const & getCurrentClipArea()
Gets the current clip area.
virtual void setFont(Font *font)
Sets the font to use when drawing text.
virtual void setColor(Color const &color)=0
Sets the color to use when drawing.
virtual void fillRectangle(Rectangle const &rectangle)=0
Draws a filled rectangle.
Key const & getKey() const
Gets the key of the event.
void setListModel(ListModel *listModel)
Sets the list model to use.
void setWrappingEnabled(bool wrappingEnabled)
Sets the list box to wrap or not when selecting items with a keyboard.
void adjustSize() override
Resizes the widget's size to fit the content exactly.
int getSelected() const
Gets the selected item as an index in the list model.
void mouseWheelMovedDown(MouseEvent &mouseEvent) override
Called when the mouse wheel has moved down on the widget area.
void mouseDragged(MouseEvent &mouseEvent) override
Called when the mouse has moved and the mouse has previously been pressed on the widget.
bool isWrappingEnabled() const
Checks whether the list box wraps when selecting items with a keyboard.
void mouseWheelMovedUp(MouseEvent &mouseEvent) override
Called when the mouse wheel has moved up on the widget area.
SelectionListenerList::iterator SelectionListenerIterator
Iterator for SelectionListenerList.
int mSelected
The selected item as an index in the list model.
void logic() override
Called for all widgets in the GUI each time Gui::logic is called.
void addSelectionListener(SelectionListener *selectionListener)
Adds a selection listener to the list box.
void adjustSizeImpl()
Concrete implementation of adjustSize.
void removeSelectionListener(SelectionListener *selectionListener)
Removes a selection listener from the list box.
bool mWrappingEnabled
True if wrapping is enabled, false otherwise.
void mousePressed(MouseEvent &mouseEvent) override
Called when a mouse button has been pressed down on the widget area.
void resizeToContent(bool recursion=true) override
Resizes the widget's size to fit the content exactly, calls recursively all childs.
void keyPressed(KeyEvent &keyEvent) override
Called if a key is pressed when the widget has keyboard focus.
ListModel * mListModel
The list model to use.
ListModel * getListModel() const
Gets the list model used.
void draw(Graphics *graphics) override
Draws the widget.
SelectionListenerList mSelectionListeners
The selection listeners of the list box.
void distributeValueChangedEvent()
Notifies all registered selection listeners of a value change.
void setSelected(int selected)
Sets the selected item.
virtual unsigned int getRowHeight() const
Gets the height of a row.
Interface for a data model representing a list (used by ListBox/DropDown).
Represents a mouse event.
int getY() const
Gets the y coordinate of the mouse event.
MouseEvent::Button getButton() const
Gets the button of the mouse event.
Represents a rectangular area (X, Y, Width, Height).
int y
Holds the x coordinate of the rectangle.
int height
Holds the height of the rectangle.
Represents a change in selection state (e.g., list item selected).
Interface for listening to selection change events.
Used replacement tokens by configure_file():