diff --git a/src/frontend/InventoryView.cpp b/src/frontend/InventoryView.cpp index 12665300..e5e6dab5 100644 --- a/src/frontend/InventoryView.cpp +++ b/src/frontend/InventoryView.cpp @@ -259,7 +259,7 @@ void SlotView::clicked(gui::GUI* gui, mousecode button) { } } -void SlotView::focus(gui::GUI* gui) { +void SlotView::onFocus(gui::GUI* gui) { clicked(gui, mousecode::BUTTON_1); } diff --git a/src/frontend/InventoryView.h b/src/frontend/InventoryView.h index 7cab1131..93258e8a 100644 --- a/src/frontend/InventoryView.h +++ b/src/frontend/InventoryView.h @@ -73,7 +73,7 @@ public: bool isHighlighted() const; virtual void clicked(gui::GUI*, mousecode) override; - virtual void focus(gui::GUI*) override; + virtual void onFocus(gui::GUI*) override; void bind( int64_t inventoryid, diff --git a/src/frontend/gui/GUI.cpp b/src/frontend/gui/GUI.cpp index a55ce768..f3146e49 100644 --- a/src/frontend/gui/GUI.cpp +++ b/src/frontend/gui/GUI.cpp @@ -58,7 +58,7 @@ void GUI::actMouse(float delta) { } if (focus != pressed) { focus = pressed; - focus->focus(this); + focus->onFocus(this); return; } } @@ -175,7 +175,7 @@ void GUI::setFocus(std::shared_ptr node) { } focus = node; if (focus) { - focus->focus(this); + focus->onFocus(this); } } diff --git a/src/frontend/gui/UINode.h b/src/frontend/gui/UINode.h index a79717cf..eadfa5ca 100644 --- a/src/frontend/gui/UINode.h +++ b/src/frontend/gui/UINode.h @@ -24,34 +24,50 @@ namespace gui { top=left, bottom=right, }; + /// @brief Base abstract class for all UI elements class UINode { - /** - * element identifier used for direct access in UiDocument - */ + /// @brief element identifier used for direct access in UiDocument std::string id = ""; protected: + /// @brief element position within the parent element glm::vec2 pos {0.0f}; + /// @brief element size (width, height) glm::vec2 size; + /// @brief minimal element size glm::vec2 minSize {1.0f}; + /// @brief element primary color (background-color or text-color if label) glm::vec4 color {1.0f}; + /// @brief element color when mouse is over it glm::vec4 hoverColor {1.0f}; + /// @brief element margin (only supported for Panel sub-nodes) glm::vec4 margin {1.0f}; + /// @brief is element visible bool visible = true; + /// @brief is mouse over the element bool hover = false; + /// @brief is mouse has been pressed over the element and not released yet bool pressed = false; + /// @brief is element focused bool focused = false; + /// @brief is element opaque for cursor interaction bool interactive = true; + /// @brief does the element support resizing by parent elements bool resizing = true; + /// @brief z-index property specifies the stack order of an element int zindex = 0; + /// @brief element content alignment (supported by Label only) Align align = Align::left; + /// @brief parent element UINode* parent = nullptr; + /// @brief position supplier for the element (called on parent element size update) vec2supplier positionfunc = nullptr; + UINode(glm::vec2 size); public: virtual ~UINode(); - /** Called every frame for all visible elements - * @param delta delta time - */ + + /// @brief Called every frame for all visible elements + /// @param delta delta timУ virtual void act(float delta) {}; virtual void draw(const GfxContext* pctx, Assets* assets) = 0; @@ -67,11 +83,12 @@ namespace gui { virtual void setParent(UINode* node); UINode* getParent() const; - /** Set element color (doesn't affect inner elements). - Also replaces hover color to avoid adding extra properties. */ + /// @brief Set element color (doesn't affect inner elements). + /// Also replaces hover color to avoid adding extra properties virtual void setColor(glm::vec4 newColor); - /** Get element color (float R,G,B,A in range [0.0, 1.0])*/ + /// @brief Get element color + /// @return (float R,G,B,A in range [0.0, 1.0]) glm::vec4 getColor() const; virtual void setHoverColor(glm::vec4 newColor); @@ -80,12 +97,14 @@ namespace gui { virtual void setMargin(glm::vec4 margin); glm::vec4 getMargin() const; - /** Influences container elements sort order - Doesn't work in Panel */ + /// @brief Specifies the stack order of an element + /// @attention Is not supported by Panel virtual void setZIndex(int idx); + + /// @brief Get element z-index int getZIndex() const; - virtual void focus(GUI*) {focused = true;} + virtual void onFocus(GUI*) {focused = true;} virtual void click(GUI*, int x, int y); virtual void clicked(GUI*, mousecode button) {} virtual void mouseMove(GUI*, int x, int y) {}; diff --git a/src/frontend/gui/controls.cpp b/src/frontend/gui/controls.cpp index a7165662..d6e2b413 100644 --- a/src/frontend/gui/controls.cpp +++ b/src/frontend/gui/controls.cpp @@ -585,8 +585,8 @@ void TextBox::setOnEditStart(runnable oneditstart) { onEditStart = oneditstart; } -void TextBox::focus(GUI* gui) { - Panel::focus(gui); +void TextBox::onFocus(GUI* gui) { + Panel::onFocus(gui); if (onEditStart){ setCaret(input.size()); onEditStart(); diff --git a/src/frontend/gui/controls.h b/src/frontend/gui/controls.h index 539e46a9..79cacf38 100644 --- a/src/frontend/gui/controls.h +++ b/src/frontend/gui/controls.h @@ -272,7 +272,7 @@ namespace gui { /// @brief Set runnable called on textbox focus virtual void setOnEditStart(runnable oneditstart); - virtual void focus(GUI*) override; + virtual void onFocus(GUI*) override; virtual void refresh() override; virtual void click(GUI*, int, int) override; virtual void mouseMove(GUI*, int x, int y) override;