5#include "fifechan/widgets/listbox.hpp"
9#include "fifechan/font.hpp"
10#include "fifechan/graphics.hpp"
11#include "fifechan/key.hpp"
12#include "fifechan/listmodel.hpp"
13#include "fifechan/mouseinput.hpp"
14#include "fifechan/selectionlistener.hpp"
57 int numberOfRows = (currentClipArea.
height / rowHeight) + 2;
59 numberOfRows = std::min(numberOfRows,
mListModel->getNumberOfElements());
69 startRow = -1 * (
getY() / rowHeight);
77 int y = rowHeight * startRow;
78 for (i = startRow; i < startRow + numberOfRows; ++i) {
114 }
else if (selected >=
mListModel->getNumberOfElements()) {
142 }
else if (key.
getValue() == Key::Up) {
154 }
else if (key.
getValue() == Key::Down) {
162 }
else if (key.
getValue() == Key::Home) {
165 }
else if (key.
getValue() == Key::End) {
173 if (mouseEvent.
getButton() == MouseEvent::Button::Left) {
218 static_cast<void>(recursion);
226 int const elements =
mListModel->getNumberOfElements();
227 for (
int i = 0; i < elements; ++i) {
267 (*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.
Represents a keyboard key or character code.
int getValue() const
Gets the value of the key.
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
Typedef.
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 resizeToContent()
Resizes the widget's size to fit the content exactly, calls recursively all childs.
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 on the widget area.
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()
Distributes a value changed event to all selection listeners of the list box.
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.