mirror of
https://github.com/enduro2d/enduro2d.git
synced 2025-12-14 16:09:06 +07:00
more layout dummy properties
This commit is contained in:
@@ -15,13 +15,35 @@ namespace e2d
|
||||
ENUM_HPP_CLASS_DECL(modes, u8,
|
||||
(vertical)
|
||||
(horizontal))
|
||||
|
||||
ENUM_HPP_CLASS_DECL(valigns, u8,
|
||||
(top)
|
||||
(center)
|
||||
(bottom))
|
||||
|
||||
ENUM_HPP_CLASS_DECL(haligns, u8,
|
||||
(left)
|
||||
(center)
|
||||
(right))
|
||||
public:
|
||||
layout() = default;
|
||||
|
||||
layout& mode(modes value) noexcept;
|
||||
[[nodiscard]] modes mode() const noexcept;
|
||||
|
||||
layout& valign(valigns value) noexcept;
|
||||
[[nodiscard]] valigns valign() const noexcept;
|
||||
|
||||
layout& halign(haligns value) noexcept;
|
||||
[[nodiscard]] haligns halign() const noexcept;
|
||||
|
||||
layout& spacing(f32 value) noexcept;
|
||||
[[nodiscard]] f32 spacing() const noexcept;
|
||||
private:
|
||||
modes mode_ = modes::vertical;
|
||||
valigns valign_ = valigns::center;
|
||||
haligns halign_ = haligns::center;
|
||||
f32 spacing_ = 0.f;
|
||||
};
|
||||
|
||||
class layout_item final {
|
||||
@@ -31,6 +53,8 @@ namespace e2d
|
||||
}
|
||||
|
||||
ENUM_HPP_REGISTER_TRAITS(e2d::layout::modes)
|
||||
ENUM_HPP_REGISTER_TRAITS(e2d::layout::haligns)
|
||||
ENUM_HPP_REGISTER_TRAITS(e2d::layout::valigns)
|
||||
|
||||
namespace e2d
|
||||
{
|
||||
@@ -92,4 +116,31 @@ namespace e2d
|
||||
inline layout::modes layout::mode() const noexcept {
|
||||
return mode_;
|
||||
}
|
||||
|
||||
inline layout& layout::valign(valigns value) noexcept {
|
||||
valign_ = value;
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline layout::valigns layout::valign() const noexcept {
|
||||
return valign_;
|
||||
}
|
||||
|
||||
inline layout& layout::halign(haligns value) noexcept {
|
||||
halign_ = value;
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline layout::haligns layout::halign() const noexcept {
|
||||
return halign_;
|
||||
}
|
||||
|
||||
inline layout& layout::spacing(f32 value) noexcept {
|
||||
spacing_ = value;
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline f32 layout::spacing() const noexcept {
|
||||
return spacing_;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,6 +14,15 @@ local layout = {
|
||||
|
||||
---@type layout_modes
|
||||
mode = layout.modes.vertical,
|
||||
|
||||
---@type layout_valigns
|
||||
valign = layout.valigns.center,
|
||||
|
||||
---@type layout_haligns
|
||||
halign = layout.haligns.center,
|
||||
|
||||
---@type number
|
||||
spacing = 0.0
|
||||
}
|
||||
|
||||
---@class layout_modes
|
||||
@@ -22,6 +31,20 @@ layout.modes = {
|
||||
horizontal = "horizontal"
|
||||
}
|
||||
|
||||
---@class layout_valigns
|
||||
layout.valigns = {
|
||||
top = "top",
|
||||
center = "center",
|
||||
bottom = "bottom"
|
||||
}
|
||||
|
||||
---@class layout_haligns
|
||||
layout.haligns = {
|
||||
left = "left",
|
||||
center = "center",
|
||||
right = "right"
|
||||
}
|
||||
|
||||
---@overload fun(self: layout)
|
||||
---@param self layout
|
||||
function layout.enable(self) end
|
||||
|
||||
@@ -56,6 +56,30 @@ namespace e2d::bindings::high
|
||||
},
|
||||
[](gcomponent<layout>& c, layout::modes v){
|
||||
c->mode(v);
|
||||
}),
|
||||
|
||||
"valign", sol::property(
|
||||
[](const gcomponent<layout>& c) -> layout::valigns {
|
||||
return c->valign();
|
||||
},
|
||||
[](gcomponent<layout>& c, layout::valigns v){
|
||||
c->valign(v);
|
||||
}),
|
||||
|
||||
"halign", sol::property(
|
||||
[](const gcomponent<layout>& c) -> layout::haligns {
|
||||
return c->halign();
|
||||
},
|
||||
[](gcomponent<layout>& c, layout::haligns v){
|
||||
c->halign(v);
|
||||
}),
|
||||
|
||||
"spacing", sol::property(
|
||||
[](const gcomponent<layout>& c) -> f32 {
|
||||
return c->spacing();
|
||||
},
|
||||
[](gcomponent<layout>& c, f32 v){
|
||||
c->spacing(v);
|
||||
})
|
||||
);
|
||||
|
||||
@@ -67,6 +91,24 @@ namespace e2d::bindings::high
|
||||
});
|
||||
#undef LAYOUT_MODE_PAIR
|
||||
|
||||
#define LAYOUT_HALIGN_PAIR(x) {#x, layout::haligns::x},
|
||||
l["layout"].get_or_create<sol::table>()
|
||||
.new_enum<layout::haligns>("haligns", {
|
||||
LAYOUT_HALIGN_PAIR(left)
|
||||
LAYOUT_HALIGN_PAIR(center)
|
||||
LAYOUT_HALIGN_PAIR(right)
|
||||
});
|
||||
#undef LAYOUT_HALIGN_PAIR
|
||||
|
||||
#define LAYOUT_VALIGN_PAIR(x) {#x, layout::valigns::x},
|
||||
l["layout"].get_or_create<sol::table>()
|
||||
.new_enum<layout::valigns>("valigns", {
|
||||
LAYOUT_VALIGN_PAIR(top)
|
||||
LAYOUT_VALIGN_PAIR(center)
|
||||
LAYOUT_VALIGN_PAIR(bottom)
|
||||
});
|
||||
#undef LAYOUT_VALIGN_PAIR
|
||||
|
||||
l.new_usertype<gcomponent<layout_item>>("layout_item",
|
||||
sol::no_constructor,
|
||||
|
||||
|
||||
@@ -13,7 +13,10 @@ namespace e2d
|
||||
"required" : [],
|
||||
"additionalProperties" : false,
|
||||
"properties" : {
|
||||
"mode" : { "$ref": "#/definitions/modes" }
|
||||
"mode" : { "$ref": "#/definitions/modes" },
|
||||
"valign" : { "$ref": "#/definitions/valigns" },
|
||||
"halign" : { "$ref": "#/definitions/haligns" },
|
||||
"spacing" : { "type" : "number" }
|
||||
},
|
||||
"definitions" : {
|
||||
"modes" : {
|
||||
@@ -22,6 +25,22 @@ namespace e2d
|
||||
"vertical",
|
||||
"horizontal"
|
||||
]
|
||||
},
|
||||
"valigns" : {
|
||||
"type" : "string",
|
||||
"enum" : [
|
||||
"top",
|
||||
"center",
|
||||
"bottom"
|
||||
]
|
||||
},
|
||||
"haligns" : {
|
||||
"type" : "string",
|
||||
"enum" : [
|
||||
"left",
|
||||
"center",
|
||||
"right"
|
||||
]
|
||||
}
|
||||
}
|
||||
})json";
|
||||
@@ -39,6 +58,33 @@ namespace e2d
|
||||
component.mode(mode);
|
||||
}
|
||||
|
||||
if ( ctx.root.HasMember("valign") ) {
|
||||
layout::valigns valign = component.valign();
|
||||
if ( !json_utils::try_parse_value(ctx.root["valign"], valign) ) {
|
||||
the<debug>().error("LAYOUT: Incorrect formatting of 'valign' property");
|
||||
return false;
|
||||
}
|
||||
component.valign(valign);
|
||||
}
|
||||
|
||||
if ( ctx.root.HasMember("halign") ) {
|
||||
layout::haligns halign = component.halign();
|
||||
if ( !json_utils::try_parse_value(ctx.root["halign"], halign) ) {
|
||||
the<debug>().error("LAYOUT: Incorrect formatting of 'halign' property");
|
||||
return false;
|
||||
}
|
||||
component.halign(halign);
|
||||
}
|
||||
|
||||
if ( ctx.root.HasMember("spacing") ) {
|
||||
f32 spacing = component.spacing();
|
||||
if ( !json_utils::try_parse_value(ctx.root["spacing"], spacing) ) {
|
||||
the<debug>().error("LAYOUT: Incorrect formatting of 'spacing' property");
|
||||
return false;
|
||||
}
|
||||
component.spacing(spacing);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -87,6 +133,24 @@ namespace e2d
|
||||
{
|
||||
c->mode(mode);
|
||||
}
|
||||
|
||||
if ( layout::valigns valign = c->valign();
|
||||
imgui_utils::show_enum_combo_box("valign", &valign) )
|
||||
{
|
||||
c->valign(valign);
|
||||
}
|
||||
|
||||
if ( layout::haligns halign = c->halign();
|
||||
imgui_utils::show_enum_combo_box("halign", &halign) )
|
||||
{
|
||||
c->halign(halign);
|
||||
}
|
||||
|
||||
if ( f32 spacing = c->spacing();
|
||||
ImGui::DragFloat("spacing", &spacing, 1.f) )
|
||||
{
|
||||
c->spacing(spacing);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user