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())
115 for (uint32_t i = 0; i < elemSize; ++i)
123 platform->getVideo()->getImageRenderer()->drawRectangle(0,0,platform->getVideo()->getScreenWidth(), platform->getVideo()->getScreenHeight(), (
PixelColor){0xbe, 0xca, 0xd5, 0x70});
128 if(
state != STATE::DISABLED)
129 state = STATE::DEFAULT;
132 for (uint32_t i = 0; i < elemSize; ++i)
143 for (uint32_t i = 0; i < elemSize; ++i)
154 for (uint32_t i = 0; i < elemSize; ++i)
176 for (uint32_t i = 0; i < elemSize; ++i)
180 else if(
_elements.at(i)->isFocused() == 1)
197 for (i = 0; i < elemSize; ++i)
209 for (i = 0; i < elemSize; ++i)
211 if(
_elements.at(i)->isFocused() == 0 &&
_elements.at(i)->getState() != STATE::DISABLED)
220 else if(controller->isSecondaryPressed())
222 for (i = found; i < elemSize; ++i)
224 if(
_elements.at(i)->isFocused() == 0 &&
_elements.at(i)->getState() != STATE::DISABLED)
235 for (i = 0; i < found; ++i)
237 if(
_elements.at(i)->isFocused() == 0 &&
_elements.at(i)->getState() != STATE::DISABLED)
253 for (uint32_t i = 0; i < elemSize; ++i)
255 if(
_elements.at(i)->getState() == STATE::SELECTED)
271 size_t before = out.size();
272 e->collectNavigable(out);
273 if(!(out.size() == before + 1 && out.back() == e))
282 std::vector<GuiNavItem> items(list.size());
283 for (
size_t i = 0; i < list.size(); ++i)
285 if(current < 0 && list[i]->
getState() == STATE::SELECTED)
287 items[i].r.x = (float)list[i]->
getLeft();
288 items[i].r.y = (float)list[i]->
getTop();
289 items[i].r.w = (float)list[i]->
getWidth();
290 items[i].r.h = (float)list[i]->
getHeight();
291 items[i].selectable = list[i]->isSelectable() && list[i]->isVisible() && list[i]->getState() != STATE::DISABLED;
295 if(next >= 0 && next != current)
297 list[next]->setState(STATE::SELECTED);
299 list[current]->resetState();
305 std::vector<GuiElement*> nav;
322 left =
_elements.at(selected)->getLeft();
328 for (i = 0; i < elemSize; ++i)
345 for (i = 0; i < elemSize; ++i)
349 if(
_elements.at(i)->getTop()*dir > top*dir)
367 _elements.at(found)->setState(STATE::SELECTED);
375 std::vector<GuiElement*> nav;
390 left =
_elements.at(selected)->getLeft();
396 for (uint32_t i = 0; i < elemSize; ++i)
400 if(
_elements.at(i)->getTop()*dir > top*dir)
409 abs(
_elements.at(found)->getLeft() - left))
421 _elements.at(found)->setState(STATE::SELECTED);
430 for (uint32_t i = 0; i < elemSize; i++)
442 for (uint32_t i = 0; i < elemSize; ++i)
452 if(controller->right())
454 else if(controller->
left())
456 else if(controller->
down())
458 else if(controller->
up())
Umbrella header for the platform-agnostic libgui core.
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.
int focus
Element focus (-1 = focus disabled, 0 = not focused, 1 = focused)
STATE state
Element state (DEFAULT, SELECTED, CLICKED, DISABLED)
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 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.