27 e->setParent(
nullptr);
43 if (e ==
nullptr)
return;
50 if (e ==
nullptr || index > (
_elements.size() - 1))
64 for (uint32_t i = 0; i < elemSize; ++i)
78 for (uint32_t i = 0; i < elemSize; ++i)
91 for (uint32_t i = 0; i < elemSize; ++i)
111 if(
_elements.size() == 0 || !this->isVisible())
117 bool washPending =
false;
119 for (uint32_t i = 0; i < elemSize; ++i)
123 const bool disabledChild = child && child->
getState() == STATE::DISABLED && child->
isVisible();
124 if(washPending && !disabledChild)
130 if(disabledChild && !washed)
142 platform->getVideo()->getImageRenderer()->drawRectangle(0, 0, platform->getVideo()->getScreenWidth(), platform->getVideo()->getScreenHeight(), (
PixelColor){0xbe, 0xca, 0xd5, 0x70});
147 if(
state != STATE::DISABLED)
148 state = STATE::DEFAULT;
151 for (uint32_t i = 0; i < elemSize; ++i)
162 for (uint32_t i = 0; i < elemSize; ++i)
173 for (uint32_t i = 0; i < elemSize; ++i)
195 for (uint32_t i = 0; i < elemSize; ++i)
199 else if(
_elements.at(i)->isFocused() == 1)
216 for (i = 0; i < elemSize; ++i)
228 for (i = 0; i < elemSize; ++i)
230 if(
_elements.at(i)->isFocused() == 0 &&
_elements.at(i)->getState() != STATE::DISABLED)
239 else if(controller->isSecondaryPressed())
241 for (i = found; i < elemSize; ++i)
243 if(
_elements.at(i)->isFocused() == 0 &&
_elements.at(i)->getState() != STATE::DISABLED)
254 for (i = 0; i < found; ++i)
256 if(
_elements.at(i)->isFocused() == 0 &&
_elements.at(i)->getState() != STATE::DISABLED)
272 for (uint32_t i = 0; i < elemSize; ++i)
274 if(
_elements.at(i)->getState() == STATE::SELECTED)
290 size_t before = out.size();
291 e->collectNavigable(out);
292 if(!(out.size() == before + 1 && out.back() == e))
301 std::vector<GuiNavItem> items(list.size());
302 for (
size_t i = 0; i < list.size(); ++i)
304 if(current < 0 && list[i]->
getState() == STATE::SELECTED)
306 items[i].r.x = (float)list[i]->
getLeft();
307 items[i].r.y = (float)list[i]->
getTop();
308 items[i].r.w = (float)list[i]->
getWidth();
309 items[i].r.h = (float)list[i]->
getHeight();
310 items[i].selectable = list[i]->isSelectable() && list[i]->isVisible() && list[i]->getState() != STATE::DISABLED;
314 if(next >= 0 && next != current)
316 list[next]->setState(STATE::SELECTED);
318 list[current]->resetState();
324 std::vector<GuiElement*> nav;
341 left =
_elements.at(selected)->getLeft();
347 for (i = 0; i < elemSize; ++i)
364 for (i = 0; i < elemSize; ++i)
368 if(
_elements.at(i)->getTop()*dir > top*dir)
386 _elements.at(found)->setState(STATE::SELECTED);
394 std::vector<GuiElement*> nav;
409 left =
_elements.at(selected)->getLeft();
415 for (uint32_t i = 0; i < elemSize; ++i)
419 if(
_elements.at(i)->getTop()*dir > top*dir)
428 abs(
_elements.at(found)->getLeft() - left))
440 _elements.at(found)->setState(STATE::SELECTED);
449 for (uint32_t i = 0; i < elemSize; i++)
461 for (uint32_t i = 0; i < elemSize; ++i)
471 if(controller->right())
473 else if(controller->
left())
475 else if(controller->
down())
477 else if(controller->
up())
Umbrella header for the platform-agnostic libgui core.
bool isVisible()
Checks whether or not the element is visible.
int getTop()
Gets the current topmost coordinate of the element Considers vertical alignment, y offset,...
void setRemoveOnDestroy(bool autoRemove)
Whether to notify parent on destruction to allow removal.
STATE getState()
Gets the element's current state.
UpdateCallback updateCB
Callback function to call when this element is updated.
int height
Element height.
GuiElement * parentElement
Parent element.
void updateEffects()
Updates the element's effects (dynamic values) Called by Draw(), used for animation purposes.
int getWidth()
Gets the current width of the element.
bool visible
Visibility of the element.
int getLeft()
Gets the current leftmost coordinate of the element Considers horizontal alignment,...
void setParent(GuiElement *e)
Set the element's parent.
virtual void draw()=0
Called constantly to redraw the element.
int focus
Element focus (-1 = focus disabled, 0 = not focused, 1 = focused)
STATE state
Element state (DEFAULT, SELECTED, CLICKED, DISABLED)
virtual GuiWindow * getAsWindow()
Attempts to cast this element as a GuiWindow (default implementation returns nullptr)
int getHeight()
Gets the height of the element.
void moveSelectionIn(std::vector< GuiElement * > &list, NAV_DIR d)
Moves the selection within a collected list by on-screen geometry.
uint32_t getSize()
Returns the size of the list of elements.
void toggleFocus(InputController *c)
Changes window focus to the next focusable window or element If no element is in focus,...
bool collectNavigation(std::vector< GuiElement * > &out)
Gathers the elements selection can move between, looking inside layout containers.
void append(GuiElement *e)
Appends a GuiElement to the GuiWindow.
bool find(GuiElement *e)
Looks for the specified GuiElement.
void setFocus(int f)
Sets the window focus.
void setVisible(bool v)
Sets the visibility of the window.
void moveSelectionVert(int d)
Moves the selected element to the element above or below.
void resetState()
Resets the window's state to STATE::DEFAULT.
GuiElement * getGuiElementAt(uint32_t index) const
Returns the GuiElement at the specified index.
void appendWithAutoRemove(GuiElement *e)
Appends a GuiElement to the GuiWindow, and instructs the GuiElement to inform its parent on destructi...
void removeAll()
Removes all GuiElements.
int getSelected()
Gets the index of the GuiElement inside the window that is currently selected.
void draw()
Draws all the elements in this GuiWindow.
void setState(STATE s, int c=-1)
Sets the window state, propagated to every child element.
void resetText()
Resets the text for all contained elements.
void update(InputController *c)
Updates the window and all elements contains within Allows the GuiWindow and all elements to respond ...
void insert(GuiElement *e, uint32_t i)
Inserts a GuiElement into the GuiWindow at the specified index.
void remove(GuiElement *e)
Removes the specified GuiElement from the GuiWindow.
std::vector< GuiElement * > _elements
Contains all elements within the GuiWindow.
void changeFocus(GuiElement *e)
Change the focus to the specified element This is intended for the primary GuiWindow only.
void drawWash()
Draws the dimming over a disabled screen: the one place that colour is set.
void moveSelectionHor(int d)
Moves the selected element to the element to the left or right.
STATE
Interaction state of a GuiElement (default, selected, clicked, held, disabled).
NAV_DIR
Directions for moving the selection.
int GuiNavigate(const std::vector< GuiNavItem > &items, int current, NAV_DIR dir)
Picks which item the selection moves to.
8-bit-per-channel RGBA color used by the video interfaces.