mirror of
https://github.com/enduro2d/enduro2d.git
synced 2025-12-16 14:08:59 +07:00
dummy layout mode property
This commit is contained in:
@@ -11,8 +11,17 @@
|
|||||||
namespace e2d
|
namespace e2d
|
||||||
{
|
{
|
||||||
class layout final {
|
class layout final {
|
||||||
|
public:
|
||||||
|
ENUM_HPP_CLASS_DECL(modes, u8,
|
||||||
|
(vertical)
|
||||||
|
(horizontal))
|
||||||
public:
|
public:
|
||||||
layout() = default;
|
layout() = default;
|
||||||
|
|
||||||
|
layout& mode(modes value) noexcept;
|
||||||
|
[[nodiscard]] modes mode() const noexcept;
|
||||||
|
private:
|
||||||
|
modes mode_ = modes::vertical;
|
||||||
};
|
};
|
||||||
|
|
||||||
class layout_item final {
|
class layout_item final {
|
||||||
@@ -21,6 +30,8 @@ namespace e2d
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ENUM_HPP_REGISTER_TRAITS(e2d::layout::modes)
|
||||||
|
|
||||||
namespace e2d
|
namespace e2d
|
||||||
{
|
{
|
||||||
template <>
|
template <>
|
||||||
@@ -73,4 +84,12 @@ namespace e2d
|
|||||||
|
|
||||||
namespace e2d
|
namespace e2d
|
||||||
{
|
{
|
||||||
|
inline layout& layout::mode(modes value) noexcept {
|
||||||
|
mode_ = value;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline layout::modes layout::mode() const noexcept {
|
||||||
|
return mode_;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,11 +1,64 @@
|
|||||||
|
-- -----------------------------------------------------------------------------
|
||||||
|
--
|
||||||
|
-- layout
|
||||||
|
--
|
||||||
|
-- -----------------------------------------------------------------------------
|
||||||
|
|
||||||
---@class layout
|
---@class layout
|
||||||
local layout = {
|
local layout = {
|
||||||
|
---@type boolean
|
||||||
|
enabled = true,
|
||||||
|
|
||||||
|
---@type boolean
|
||||||
|
disabled = false,
|
||||||
|
|
||||||
|
---@type layout_modes
|
||||||
|
mode = layout.modes.vertical,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
---@class layout_modes
|
||||||
|
layout.modes = {
|
||||||
|
vertical = "vertical",
|
||||||
|
horizontal = "horizontal"
|
||||||
|
}
|
||||||
|
|
||||||
|
---@overload fun(self: layout)
|
||||||
|
---@param self layout
|
||||||
|
function layout.enable(self) end
|
||||||
|
|
||||||
|
---@overload fun(self: layout)
|
||||||
|
---@param self layout
|
||||||
|
function layout.disable(self) end
|
||||||
|
|
||||||
|
-- -----------------------------------------------------------------------------
|
||||||
|
--
|
||||||
|
-- layout_item
|
||||||
|
--
|
||||||
|
-- -----------------------------------------------------------------------------
|
||||||
|
|
||||||
---@class layout_item
|
---@class layout_item
|
||||||
local layout_item = {
|
local layout_item = {
|
||||||
|
---@type boolean
|
||||||
|
enabled = true,
|
||||||
|
|
||||||
|
---@type boolean
|
||||||
|
disabled = false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
---@overload fun(self: layout_item)
|
||||||
|
---@param self layout_item
|
||||||
|
function layout_item.enable(self) end
|
||||||
|
|
||||||
|
---@overload fun(self: layout_item)
|
||||||
|
---@param self layout_item
|
||||||
|
function layout_item.disable(self) end
|
||||||
|
|
||||||
|
-- -----------------------------------------------------------------------------
|
||||||
|
--
|
||||||
|
-- global
|
||||||
|
--
|
||||||
|
-- -----------------------------------------------------------------------------
|
||||||
|
|
||||||
---@type layout
|
---@type layout
|
||||||
_G.layout = _G.layout or layout
|
_G.layout = _G.layout or layout
|
||||||
|
|
||||||
|
|||||||
@@ -7,17 +7,102 @@
|
|||||||
#include "../_high_binds.hpp"
|
#include "../_high_binds.hpp"
|
||||||
|
|
||||||
#include <enduro2d/high/gobject.hpp>
|
#include <enduro2d/high/gobject.hpp>
|
||||||
|
#include <enduro2d/high/components/disabled.hpp>
|
||||||
#include <enduro2d/high/components/layout.hpp>
|
#include <enduro2d/high/components/layout.hpp>
|
||||||
|
|
||||||
namespace e2d::bindings::high
|
namespace e2d::bindings::high
|
||||||
{
|
{
|
||||||
void bind_layout(sol::state& l) {
|
void bind_layout(sol::state& l) {
|
||||||
l.new_usertype<gcomponent<layout>>("layout",
|
l.new_usertype<gcomponent<layout>>("layout",
|
||||||
sol::no_constructor
|
sol::no_constructor,
|
||||||
|
|
||||||
|
"enable", [](gcomponent<layout>& c){
|
||||||
|
c.owner().component<disabled<layout>>().remove();
|
||||||
|
},
|
||||||
|
|
||||||
|
"disable", [](gcomponent<layout>& c){
|
||||||
|
c.owner().component<disabled<layout>>().ensure();
|
||||||
|
},
|
||||||
|
|
||||||
|
"enabled", sol::property(
|
||||||
|
[](const gcomponent<layout>& c) -> bool {
|
||||||
|
return !c.owner().component<disabled<layout>>().exists();
|
||||||
|
},
|
||||||
|
[](gcomponent<layout>& c, bool yesno){
|
||||||
|
if ( yesno ) {
|
||||||
|
c.owner().component<disabled<layout>>().remove();
|
||||||
|
} else {
|
||||||
|
c.owner().component<disabled<layout>>().ensure();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
),
|
||||||
|
|
||||||
|
"disabled", sol::property(
|
||||||
|
[](const gcomponent<layout>& c) -> bool {
|
||||||
|
return c.owner().component<disabled<layout>>().exists();
|
||||||
|
},
|
||||||
|
[](gcomponent<layout>& c, bool yesno){
|
||||||
|
if ( yesno ) {
|
||||||
|
c.owner().component<disabled<layout>>().ensure();
|
||||||
|
} else {
|
||||||
|
c.owner().component<disabled<layout>>().remove();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
),
|
||||||
|
|
||||||
|
"mode", sol::property(
|
||||||
|
[](const gcomponent<layout>& c) -> layout::modes {
|
||||||
|
return c->mode();
|
||||||
|
},
|
||||||
|
[](gcomponent<layout>& c, layout::modes v){
|
||||||
|
c->mode(v);
|
||||||
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
|
#define LAYOUT_MODE_PAIR(x) {#x, layout::modes::x},
|
||||||
|
l["layout"].get_or_create<sol::table>()
|
||||||
|
.new_enum<layout::modes>("modes", {
|
||||||
|
LAYOUT_MODE_PAIR(vertical)
|
||||||
|
LAYOUT_MODE_PAIR(horizontal)
|
||||||
|
});
|
||||||
|
#undef LAYOUT_MODE_PAIR
|
||||||
|
|
||||||
l.new_usertype<gcomponent<layout_item>>("layout_item",
|
l.new_usertype<gcomponent<layout_item>>("layout_item",
|
||||||
sol::no_constructor
|
sol::no_constructor,
|
||||||
|
|
||||||
|
"enable", [](gcomponent<layout_item>& c){
|
||||||
|
c.owner().component<disabled<layout_item>>().remove();
|
||||||
|
},
|
||||||
|
|
||||||
|
"disable", [](gcomponent<layout_item>& c){
|
||||||
|
c.owner().component<disabled<layout_item>>().ensure();
|
||||||
|
},
|
||||||
|
|
||||||
|
"enabled", sol::property(
|
||||||
|
[](const gcomponent<layout_item>& c) -> bool {
|
||||||
|
return !c.owner().component<disabled<layout_item>>().exists();
|
||||||
|
},
|
||||||
|
[](gcomponent<layout_item>& c, bool yesno){
|
||||||
|
if ( yesno ) {
|
||||||
|
c.owner().component<disabled<layout_item>>().remove();
|
||||||
|
} else {
|
||||||
|
c.owner().component<disabled<layout_item>>().ensure();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
),
|
||||||
|
|
||||||
|
"disabled", sol::property(
|
||||||
|
[](const gcomponent<layout_item>& c) -> bool {
|
||||||
|
return c.owner().component<disabled<layout_item>>().exists();
|
||||||
|
},
|
||||||
|
[](gcomponent<layout_item>& c, bool yesno){
|
||||||
|
if ( yesno ) {
|
||||||
|
c.owner().component<disabled<layout_item>>().ensure();
|
||||||
|
} else {
|
||||||
|
c.owner().component<disabled<layout_item>>().remove();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,14 +12,33 @@ namespace e2d
|
|||||||
"type" : "object",
|
"type" : "object",
|
||||||
"required" : [],
|
"required" : [],
|
||||||
"additionalProperties" : false,
|
"additionalProperties" : false,
|
||||||
"properties" : {}
|
"properties" : {
|
||||||
|
"mode" : { "$ref": "#/definitions/modes" }
|
||||||
|
},
|
||||||
|
"definitions" : {
|
||||||
|
"modes" : {
|
||||||
|
"type" : "string",
|
||||||
|
"enum" : [
|
||||||
|
"vertical",
|
||||||
|
"horizontal"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
})json";
|
})json";
|
||||||
|
|
||||||
bool factory_loader<layout>::operator()(
|
bool factory_loader<layout>::operator()(
|
||||||
layout& component,
|
layout& component,
|
||||||
const fill_context& ctx) const
|
const fill_context& ctx) const
|
||||||
{
|
{
|
||||||
E2D_UNUSED(component, ctx);
|
if ( ctx.root.HasMember("mode") ) {
|
||||||
|
layout::modes mode = component.mode();
|
||||||
|
if ( !json_utils::try_parse_value(ctx.root["mode"], mode) ) {
|
||||||
|
the<debug>().error("LAYOUT: Incorrect formatting of 'mode' property");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
component.mode(mode);
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -63,7 +82,11 @@ namespace e2d
|
|||||||
const char* component_inspector<layout>::title = ICON_FA_BARS " layout";
|
const char* component_inspector<layout>::title = ICON_FA_BARS " layout";
|
||||||
|
|
||||||
void component_inspector<layout>::operator()(gcomponent<layout>& c) const {
|
void component_inspector<layout>::operator()(gcomponent<layout>& c) const {
|
||||||
E2D_UNUSED(c);
|
if ( layout::modes mode = c->mode();
|
||||||
|
imgui_utils::show_enum_combo_box("mode", &mode) )
|
||||||
|
{
|
||||||
|
c->mode(mode);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user