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

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);
}

View File

@ -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,

View File

@ -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<UINode> node) {
}
focus = node;
if (focus) {
focus->focus(this);
focus->onFocus(this);
}
}

View File

@ -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) {};

View File

@ -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();

View File

@ -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;