dummy layout_item size property

This commit is contained in:
BlackMATov
2020-02-07 05:49:40 +07:00
parent fd8405d32a
commit 039a11d704
4 changed files with 47 additions and 5 deletions

View File

@@ -49,6 +49,11 @@ namespace e2d
class layout_item final {
public:
layout_item() = default;
layout_item& size(const v2f& value) noexcept;
[[nodiscard]] const v2f& size() const noexcept;
private:
v2f size_ = v2f::unit();
};
}
@@ -144,3 +149,15 @@ namespace e2d
return spacing_;
}
}
namespace e2d
{
inline layout_item& layout_item::size(const v2f& value) noexcept {
size_ = value;
return *this;
}
inline const v2f& layout_item::size() const noexcept {
return size_;
}
}

View File

@@ -65,7 +65,10 @@ local layout_item = {
enabled = true,
---@type boolean
disabled = false
disabled = false,
---@type v2f
size = v2f.unit()
}
---@overload fun(self: layout_item)

View File

@@ -144,7 +144,15 @@ namespace e2d::bindings::high
c.owner().component<disabled<layout_item>>().remove();
}
}
)
),
"size", sol::property(
[](const gcomponent<layout_item>& c) -> v2f {
return c->size();
},
[](gcomponent<layout_item>& c, const v2f& v){
c->size(v);
})
);
}
}

View File

@@ -103,14 +103,24 @@ namespace e2d
"type" : "object",
"required" : [],
"additionalProperties" : false,
"properties" : {}
"properties" : {
"size" : { "$ref": "#/common_definitions/v2" }
}
})json";
bool factory_loader<layout_item>::operator()(
layout_item& component,
const fill_context& ctx) const
{
E2D_UNUSED(component, ctx);
if ( ctx.root.HasMember("size") ) {
v2f size = component.size();
if ( !json_utils::try_parse_value(ctx.root["size"], size) ) {
the<debug>().error("LAYOUT_ITEM: Incorrect formatting of 'size' property");
return false;
}
component.size(size);
}
return true;
}
@@ -159,6 +169,10 @@ namespace e2d
const char* component_inspector<layout_item>::title = ICON_FA_GRIP_LINES " layout_item";
void component_inspector<layout_item>::operator()(gcomponent<layout_item>& c) const {
E2D_UNUSED(c);
if ( v2f size = c->size();
ImGui::DragFloat2("size", size.data(), 1.f) )
{
c->size(size);
}
}
}