UINode size-func
This commit is contained in:
@@ -233,6 +233,14 @@ void UINode::setPositionFunc(vec2supplier func) {
|
|||||||
positionfunc = func;
|
positionfunc = func;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
vec2supplier UINode::getSizeFunc() const {
|
||||||
|
return sizefunc;
|
||||||
|
}
|
||||||
|
|
||||||
|
void UINode::setSizeFunc(vec2supplier func) {
|
||||||
|
sizefunc = func;
|
||||||
|
}
|
||||||
|
|
||||||
void UINode::setId(const std::string& id) {
|
void UINode::setId(const std::string& id) {
|
||||||
this->id = id;
|
this->id = id;
|
||||||
}
|
}
|
||||||
@@ -245,6 +253,9 @@ void UINode::reposition() {
|
|||||||
if (positionfunc) {
|
if (positionfunc) {
|
||||||
setPos(positionfunc());
|
setPos(positionfunc());
|
||||||
}
|
}
|
||||||
|
if (sizefunc) {
|
||||||
|
setSize(sizefunc());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void UINode::setGravity(Gravity gravity) {
|
void UINode::setGravity(Gravity gravity) {
|
||||||
|
|||||||
@@ -84,6 +84,8 @@ namespace gui {
|
|||||||
UINode* parent = nullptr;
|
UINode* parent = nullptr;
|
||||||
/// @brief position supplier for the element (called on parent element size update)
|
/// @brief position supplier for the element (called on parent element size update)
|
||||||
vec2supplier positionfunc = nullptr;
|
vec2supplier positionfunc = nullptr;
|
||||||
|
/// @brief size supplier for the element (called on parent element size update)
|
||||||
|
vec2supplier sizefunc = nullptr;
|
||||||
/// @brief 'onclick' callbacks
|
/// @brief 'onclick' callbacks
|
||||||
std::vector<onaction> actions;
|
std::vector<onaction> actions;
|
||||||
|
|
||||||
@@ -148,25 +150,25 @@ namespace gui {
|
|||||||
void defocus();
|
void defocus();
|
||||||
bool isFocused() const;
|
bool isFocused() const;
|
||||||
|
|
||||||
/** Check if element catches all user input when focused */
|
/// @brief Check if element catches all user input when focused
|
||||||
virtual bool isFocuskeeper() const {return false;}
|
virtual bool isFocuskeeper() const {return false;}
|
||||||
|
|
||||||
virtual void typed(unsigned int codepoint) {};
|
virtual void typed(unsigned int codepoint) {};
|
||||||
virtual void keyPressed(keycode key) {};
|
virtual void keyPressed(keycode key) {};
|
||||||
|
|
||||||
/** Check if screen position is inside of the element
|
/// @brief Check if screen position is inside of the element
|
||||||
* @param pos screen position */
|
/// @param pos screen position
|
||||||
virtual bool isInside(glm::vec2 pos);
|
virtual bool isInside(glm::vec2 pos);
|
||||||
|
|
||||||
/** Get element under the cursor.
|
/// @brief Get element under the cursor.
|
||||||
* @param pos cursor screen position
|
/// @param pos cursor screen position
|
||||||
* @param self shared pointer to element
|
/// @param self shared pointer to element
|
||||||
* @return self, sub-element or nullptr if element is not interractive */
|
/// @return self, sub-element or nullptr if element is not interractive
|
||||||
virtual std::shared_ptr<UINode> getAt(glm::vec2 pos, std::shared_ptr<UINode> self);
|
virtual std::shared_ptr<UINode> getAt(glm::vec2 pos, std::shared_ptr<UINode> self);
|
||||||
|
|
||||||
/* Check if element is opaque for cursor */
|
/// @brief Check if element is opaque for cursor
|
||||||
virtual bool isInteractive() const;
|
virtual bool isInteractive() const;
|
||||||
/* Make the element opaque (true) or transparent (false) for cursor */
|
/// @brief Make the element opaque (true) or transparent (false) for cursor
|
||||||
virtual void setInteractive(bool flag);
|
virtual void setInteractive(bool flag);
|
||||||
|
|
||||||
virtual void setResizing(bool flag);
|
virtual void setResizing(bool flag);
|
||||||
@@ -174,9 +176,9 @@ namespace gui {
|
|||||||
|
|
||||||
virtual glm::vec4 calcColor() const;
|
virtual glm::vec4 calcColor() const;
|
||||||
|
|
||||||
/* Get inner content offset. Used for scroll */
|
/// @brief Get inner content offset. Used for scroll
|
||||||
virtual glm::vec2 contentOffset() {return glm::vec2(0.0f);};
|
virtual glm::vec2 contentOffset() {return glm::vec2(0.0f);};
|
||||||
/* Calculate screen position of the element */
|
/// @brief Calculate screen position of the element
|
||||||
virtual glm::vec2 calcPos() const;
|
virtual glm::vec2 calcPos() const;
|
||||||
virtual void setPos(glm::vec2 pos);
|
virtual void setPos(glm::vec2 pos);
|
||||||
virtual glm::vec2 getPos() const;
|
virtual glm::vec2 getPos() const;
|
||||||
@@ -184,7 +186,7 @@ namespace gui {
|
|||||||
virtual void setSize(glm::vec2 size);
|
virtual void setSize(glm::vec2 size);
|
||||||
virtual glm::vec2 getMinSize() const;
|
virtual glm::vec2 getMinSize() const;
|
||||||
virtual void setMinSize(glm::vec2 size);
|
virtual void setMinSize(glm::vec2 size);
|
||||||
/* Called in containers when new element added */
|
/// @brief Called in containers when new element added
|
||||||
virtual void refresh() {};
|
virtual void refresh() {};
|
||||||
virtual void fullRefresh() {
|
virtual void fullRefresh() {
|
||||||
if (parent) {
|
if (parent) {
|
||||||
@@ -199,15 +201,18 @@ namespace gui {
|
|||||||
virtual vec2supplier getPositionFunc() const;
|
virtual vec2supplier getPositionFunc() const;
|
||||||
virtual void setPositionFunc(vec2supplier);
|
virtual void setPositionFunc(vec2supplier);
|
||||||
|
|
||||||
|
virtual vec2supplier getSizeFunc() const;
|
||||||
|
virtual void setSizeFunc(vec2supplier);
|
||||||
|
|
||||||
void setId(const std::string& id);
|
void setId(const std::string& id);
|
||||||
const std::string& getId() const;
|
const std::string& getId() const;
|
||||||
|
|
||||||
/* Fetch pos from positionfunc if assigned */
|
/// @brief Fetch pos from positionfunc if assigned
|
||||||
void reposition();
|
void reposition();
|
||||||
|
|
||||||
virtual void setGravity(Gravity gravity);
|
virtual void setGravity(Gravity gravity);
|
||||||
|
|
||||||
// @brief collect all nodes having id
|
/// @brief collect all nodes having id
|
||||||
static void getIndices(
|
static void getIndices(
|
||||||
std::shared_ptr<UINode> node,
|
std::shared_ptr<UINode> node,
|
||||||
std::unordered_map<std::string, std::shared_ptr<UINode>>& map
|
std::unordered_map<std::string, std::shared_ptr<UINode>>& map
|
||||||
|
|||||||
@@ -94,7 +94,14 @@ static void _readUINode(UiXmlReader& reader, xml::xmlelement element, UINode& no
|
|||||||
node.setPositionFunc(scripting::create_vec2_supplier(
|
node.setPositionFunc(scripting::create_vec2_supplier(
|
||||||
reader.getEnvironment(),
|
reader.getEnvironment(),
|
||||||
element->attr("position-func").getText(),
|
element->attr("position-func").getText(),
|
||||||
reader.getFilename()+".lua"
|
reader.getFilename()
|
||||||
|
));
|
||||||
|
}
|
||||||
|
if (element->has("size-func")) {
|
||||||
|
node.setSizeFunc(scripting::create_vec2_supplier(
|
||||||
|
reader.getEnvironment(),
|
||||||
|
element->attr("size-func").getText(),
|
||||||
|
reader.getFilename()
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
if (element->has("hover-color")) {
|
if (element->has("hover-color")) {
|
||||||
|
|||||||
Reference in New Issue
Block a user