5#include "fifechan/widgets/dropdown.hpp"
9#include "fifechan/exception.hpp"
10#include "fifechan/font.hpp"
11#include "fifechan/graphics.hpp"
12#include "fifechan/key.hpp"
13#include "fifechan/listmodel.hpp"
14#include "fifechan/mouseinput.hpp"
15#include "fifechan/widgets/listbox.hpp"
16#include "fifechan/widgets/scrollarea.hpp"
46 mListBox->addSelectionListener(
this);
81 highlightColor = faceColor + 0x303030;
82 highlightColor.
a = alpha;
83 shadowColor = faceColor - 0x303030;
84 shadowColor.
a = alpha;
108 if ((
mListBox->getListModel() !=
nullptr) &&
mListBox->getSelected() >= 0) {
113 }
else if ((
mListBox->getListModel() !=
nullptr) &&
mListBox->getSelected() < 0) {
138 Color highlightColor;
146 highlightColor = faceColor - 0x303030;
147 highlightColor.
a = alpha;
148 shadowColor = faceColor + 0x303030;
149 shadowColor.
a = alpha;
154 highlightColor = faceColor + 0x303030;
155 highlightColor.
a = alpha;
156 shadowColor = faceColor - 0x303030;
157 shadowColor.
a = alpha;
175 int const n = currentClipArea.
height / 3;
176 int const dx = currentClipArea.
height / 2;
177 int const dy = (currentClipArea.
height * 2) / 3;
178 for (i = 0; i < n; i++) {
179 graphics->
drawLine(dx - i + offset, dy - i + offset, dx + i + offset, dy - i + offset);
204 }
else if (key.
getValue() == Key::Up) {
207 }
else if (key.
getValue() == Key::Down) {
254 }
else if (mouseEvent.
getButton() == MouseEvent::Button::Left) {
283 throwException(
"Scroll area has been deleted.");
287 throwException(
"List box has been deleted.");
290 int const listBoxHeight =
mListBox->getHeight();
303 if (listBoxHeight > h - h2 - 2) {
414 mListBox->setBackgroundColor(color);
427 mListBox->setForegroundColor(color);
496 (*iter)->valueChanged(event);
Represents an action trigger (e.g., button click).
A rectangle specifically used for clipping rendering regions.
uint8_t a
Alpha color component (0-255).
void draw(Graphics *graphics) override
Draws the widget.
virtual void death(Event const &event)
DeathListener callback invoked when a observed widget is destroyed.
void setFont(Font *font) override
Set the font used to render items in the dropdown.
void action(ActionEvent const &actionEvent) override
Called when an action is received from a widget.
DropDown(ListModel *listModel=nullptr, ScrollArea *scrollArea=nullptr, ListBox *listBox=nullptr)
Constructor.
bool mInternalListBox
True if an internal list box is used, false if a list box has been passed to the drop down which the ...
bool mIsDragged
True if the drop down is dragged.
bool mInternalScrollArea
True if an internal scroll area is used, false if a scroll area has been passed to the drop down whic...
void focusLost(Event const &event) override
Called when a widget loses focus.
void adjustSize() override
Resizes the widget's size to fit the content exactly.
ScrollArea * mScrollArea
The scroll area used.
virtual void dropDown()
Sets the drop down to be dropped down.
void mouseWheelMovedDown(MouseEvent &mouseEvent) override
Called when the mouse wheel has moved down on the widget area.
std::unique_ptr< ScrollArea > mOwnedScrollArea
Owned internal scroll area when not supplied externally.
void mouseDragged(MouseEvent &mouseEvent) override
Called when the mouse has moved and the mouse has previously been pressed on the widget.
Rectangle getChildrenArea() override
Gets the area of the widget occupied by the widget's children.
void valueChanged(SelectionEvent const &event) override
Called when the value of a selection has been changed in a Widget.
void removeSelectionListener(SelectionListener *selectionListener)
Removes a selection listener from the drop down.
virtual void drawButton(Graphics *graphics)
Draws the button of the drop down.
SelectionListenerList mSelectionListeners
The selection listener's of the drop down.
int getSelected() const
Gets the selected item as an index in the list model.
ListBox * mListBox
The list box used.
void setListModel(ListModel *listModel)
Sets the list model to use when displaying the list.
void keyPressed(KeyEvent &keyEvent) override
Called if a key is pressed when the widget has keyboard focus.
void mouseReleased(MouseEvent &mouseEvent) override
Called when a mouse button has been released on the widget area.
void setForegroundColor(Color const &color) override
Set the foreground/text color used in the dropdown.
void adjustHeight()
Adjusts the height of the drop down to fit the height of the drop down's parent's height.
void setBackgroundColor(Color const &color) override
Set the explicit background color for the dropdown.
void resizeToContent()
Resizes the widget's size to fit the content exactly, calls recursively all childs.
bool mDroppedDown
True if the drop down is dropped down, false otherwise.
bool mPushed
True if the drop down has been pushed with the mouse, false otherwise.
void setSelected(int selected)
Sets the selected item.
void setBaseColor(Color const &color) override
Set the base color used for the dropdown background/controls.
virtual void foldUp()
Sets the drop down to be folded up.
void setSelectionColor(Color const &color) override
Set the color used for the selected item highlight.
void addSelectionListener(SelectionListener *selectionListener)
Adds a selection listener to the drop down.
void distributeValueChangedEvent()
Distributes a value changed event to all selection listeners of the drop down.
ListModel * getListModel() const
Gets the list model used.
std::unique_ptr< ListBox > mOwnedListBox
Owned internal list box when not supplied externally.
FocusHandler mInternalFocusHandler
The internal focus handler used to keep track of focus for the internal list box.
void mousePressed(MouseEvent &mouseEvent) override
Called when a mouse button has been pressed on the widget area.
SelectionListenerList::iterator SelectionListenerIterator
Typedef.
int mFoldedUpHeight
Holds what the height is if the drop down is folded up.
void mouseWheelMovedUp(MouseEvent &mouseEvent) override
Called when the mouse wheel has moved up on the widget area.
Base class for all GUI event objects.
Widget * getSource() const
Gets the source widget of the event.
Abstract interface for font rendering.
virtual int getHeight() const =0
Gets the height of the glyphs in the font.
Abstract interface providing primitive drawing functions (lines, rectangles, etc.).
virtual void popClipArea()
Removes the top most clip area from the stack.
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 bool pushClipArea(Rectangle area)
Pushes a clip area onto the stack.
virtual void setFont(Font *font)
Sets the font to use when drawing text.
virtual void drawLine(int x1, int y1, int x2, int y2)=0
Draws a line.
virtual void setColor(Color const &color)=0
Sets the color to use when drawing.
virtual void drawRectangle(Rectangle const &rectangle)=0
Draws a simple, non-filled rectangle with a one pixel width.
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.
A scrollable list box allowing item selection.
void removeSelectionListener(SelectionListener *selectionListener)
Removes a selection listener from the list box.
Interface for a data model representing a list (used by ListBox/DropDown).
Represents a mouse event.
int getX() const
Gets the x coordinate of the 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 width
Holds the width of the rectangle.
int height
Holds the height of the rectangle.
Represents a change in selection state (e.g., list item selected).