more docs, minor refactor

This commit is contained in:
MihailRis
2024-03-06 10:26:05 +03:00
parent f428a24a16
commit 13f7d3a5d3
6 changed files with 38 additions and 19 deletions
+1 -1
View File
@@ -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); clicked(gui, mousecode::BUTTON_1);
} }
+1 -1
View File
@@ -73,7 +73,7 @@ public:
bool isHighlighted() const; bool isHighlighted() const;
virtual void clicked(gui::GUI*, mousecode) override; virtual void clicked(gui::GUI*, mousecode) override;
virtual void focus(gui::GUI*) override; virtual void onFocus(gui::GUI*) override;
void bind( void bind(
int64_t inventoryid, int64_t inventoryid,
+2 -2
View File
@@ -58,7 +58,7 @@ void GUI::actMouse(float delta) {
} }
if (focus != pressed) { if (focus != pressed) {
focus = pressed; focus = pressed;
focus->focus(this); focus->onFocus(this);
return; return;
} }
} }
@@ -175,7 +175,7 @@ void GUI::setFocus(std::shared_ptr<UINode> node) {
} }
focus = node; focus = node;
if (focus) { if (focus) {
focus->focus(this); focus->onFocus(this);
} }
} }
+31 -12
View File
@@ -24,34 +24,50 @@ namespace gui {
top=left, bottom=right, top=left, bottom=right,
}; };
/// @brief Base abstract class for all UI elements
class UINode { class UINode {
/** /// @brief element identifier used for direct access in UiDocument
* element identifier used for direct access in UiDocument
*/
std::string id = ""; std::string id = "";
protected: protected:
/// @brief element position within the parent element
glm::vec2 pos {0.0f}; glm::vec2 pos {0.0f};
/// @brief element size (width, height)
glm::vec2 size; glm::vec2 size;
/// @brief minimal element size
glm::vec2 minSize {1.0f}; glm::vec2 minSize {1.0f};
/// @brief element primary color (background-color or text-color if label)
glm::vec4 color {1.0f}; glm::vec4 color {1.0f};
/// @brief element color when mouse is over it
glm::vec4 hoverColor {1.0f}; glm::vec4 hoverColor {1.0f};
/// @brief element margin (only supported for Panel sub-nodes)
glm::vec4 margin {1.0f}; glm::vec4 margin {1.0f};
/// @brief is element visible
bool visible = true; bool visible = true;
/// @brief is mouse over the element
bool hover = false; bool hover = false;
/// @brief is mouse has been pressed over the element and not released yet
bool pressed = false; bool pressed = false;
/// @brief is element focused
bool focused = false; bool focused = false;
/// @brief is element opaque for cursor interaction
bool interactive = true; bool interactive = true;
/// @brief does the element support resizing by parent elements
bool resizing = true; bool resizing = true;
/// @brief z-index property specifies the stack order of an element
int zindex = 0; int zindex = 0;
/// @brief element content alignment (supported by Label only)
Align align = Align::left; Align align = Align::left;
/// @brief parent element
UINode* parent = nullptr; UINode* parent = nullptr;
/// @brief position supplier for the element (called on parent element size update)
vec2supplier positionfunc = nullptr; vec2supplier positionfunc = nullptr;
UINode(glm::vec2 size); UINode(glm::vec2 size);
public: public:
virtual ~UINode(); 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 act(float delta) {};
virtual void draw(const GfxContext* pctx, Assets* assets) = 0; virtual void draw(const GfxContext* pctx, Assets* assets) = 0;
@@ -67,11 +83,12 @@ namespace gui {
virtual void setParent(UINode* node); virtual void setParent(UINode* node);
UINode* getParent() const; UINode* getParent() const;
/** Set element color (doesn't affect inner elements). /// @brief Set element color (doesn't affect inner elements).
Also replaces hover color to avoid adding extra properties. */ /// Also replaces hover color to avoid adding extra properties
virtual void setColor(glm::vec4 newColor); 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; glm::vec4 getColor() const;
virtual void setHoverColor(glm::vec4 newColor); virtual void setHoverColor(glm::vec4 newColor);
@@ -80,12 +97,14 @@ namespace gui {
virtual void setMargin(glm::vec4 margin); virtual void setMargin(glm::vec4 margin);
glm::vec4 getMargin() const; glm::vec4 getMargin() const;
/** Influences container elements sort order /// @brief Specifies the stack order of an element
Doesn't work in Panel */ /// @attention Is not supported by Panel
virtual void setZIndex(int idx); virtual void setZIndex(int idx);
/// @brief Get element z-index
int getZIndex() const; 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 click(GUI*, int x, int y);
virtual void clicked(GUI*, mousecode button) {} virtual void clicked(GUI*, mousecode button) {}
virtual void mouseMove(GUI*, int x, int y) {}; virtual void mouseMove(GUI*, int x, int y) {};
+2 -2
View File
@@ -585,8 +585,8 @@ void TextBox::setOnEditStart(runnable oneditstart) {
onEditStart = oneditstart; onEditStart = oneditstart;
} }
void TextBox::focus(GUI* gui) { void TextBox::onFocus(GUI* gui) {
Panel::focus(gui); Panel::onFocus(gui);
if (onEditStart){ if (onEditStart){
setCaret(input.size()); setCaret(input.size());
onEditStart(); onEditStart();
+1 -1
View File
@@ -272,7 +272,7 @@ namespace gui {
/// @brief Set runnable called on textbox focus /// @brief Set runnable called on textbox focus
virtual void setOnEditStart(runnable oneditstart); virtual void setOnEditStart(runnable oneditstart);
virtual void focus(GUI*) override; virtual void onFocus(GUI*) override;
virtual void refresh() override; virtual void refresh() override;
virtual void click(GUI*, int, int) override; virtual void click(GUI*, int, int) override;
virtual void mouseMove(GUI*, int x, int y) override; virtual void mouseMove(GUI*, int x, int y) override;