mirror of
https://github.com/enduro2d/enduro2d.git
synced 2025-12-14 16:09:06 +07:00
more layout direction types
This commit is contained in:
@@ -14,10 +14,6 @@ namespace e2d
|
|||||||
public:
|
public:
|
||||||
class dirty final {};
|
class dirty final {};
|
||||||
public:
|
public:
|
||||||
ENUM_HPP_CLASS_DECL(modes, u8,
|
|
||||||
(horizontal)
|
|
||||||
(vertical))
|
|
||||||
|
|
||||||
ENUM_HPP_CLASS_DECL(haligns, u8,
|
ENUM_HPP_CLASS_DECL(haligns, u8,
|
||||||
(left)
|
(left)
|
||||||
(center)
|
(center)
|
||||||
@@ -33,17 +29,23 @@ namespace e2d
|
|||||||
(space_around)
|
(space_around)
|
||||||
(space_evenly)
|
(space_evenly)
|
||||||
(space_between))
|
(space_between))
|
||||||
|
|
||||||
|
ENUM_HPP_CLASS_DECL(directions, u8,
|
||||||
|
(row)
|
||||||
|
(row_reversed)
|
||||||
|
(column)
|
||||||
|
(column_reversed))
|
||||||
public:
|
public:
|
||||||
layout() = default;
|
layout() = default;
|
||||||
|
|
||||||
layout& mode(modes value) noexcept;
|
|
||||||
[[nodiscard]] modes mode() const noexcept;
|
|
||||||
|
|
||||||
layout& halign(haligns value) noexcept;
|
layout& halign(haligns value) noexcept;
|
||||||
[[nodiscard]] haligns halign() const noexcept;
|
[[nodiscard]] haligns halign() const noexcept;
|
||||||
|
|
||||||
layout& valign(valigns value) noexcept;
|
layout& valign(valigns value) noexcept;
|
||||||
[[nodiscard]] valigns valign() const noexcept;
|
[[nodiscard]] valigns valign() const noexcept;
|
||||||
|
|
||||||
|
layout& direction(directions value) noexcept;
|
||||||
|
[[nodiscard]] directions direction() const noexcept;
|
||||||
public:
|
public:
|
||||||
layout& size(const v2f& value) noexcept;
|
layout& size(const v2f& value) noexcept;
|
||||||
[[nodiscard]] const v2f& size() const noexcept;
|
[[nodiscard]] const v2f& size() const noexcept;
|
||||||
@@ -54,9 +56,9 @@ namespace e2d
|
|||||||
layout& padding(const v2f& value) noexcept;
|
layout& padding(const v2f& value) noexcept;
|
||||||
[[nodiscard]] const v2f& padding() const noexcept;
|
[[nodiscard]] const v2f& padding() const noexcept;
|
||||||
private:
|
private:
|
||||||
modes mode_ = modes::horizontal;
|
|
||||||
haligns halign_ = haligns::center;
|
haligns halign_ = haligns::center;
|
||||||
valigns valign_ = valigns::center;
|
valigns valign_ = valigns::center;
|
||||||
|
directions direction_ = directions::row;
|
||||||
private:
|
private:
|
||||||
v2f size_ = v2f::zero();
|
v2f size_ = v2f::zero();
|
||||||
v2f margin_ = v2f::zero();
|
v2f margin_ = v2f::zero();
|
||||||
@@ -64,9 +66,9 @@ namespace e2d
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
ENUM_HPP_REGISTER_TRAITS(e2d::layout::modes)
|
|
||||||
ENUM_HPP_REGISTER_TRAITS(e2d::layout::haligns)
|
ENUM_HPP_REGISTER_TRAITS(e2d::layout::haligns)
|
||||||
ENUM_HPP_REGISTER_TRAITS(e2d::layout::valigns)
|
ENUM_HPP_REGISTER_TRAITS(e2d::layout::valigns)
|
||||||
|
ENUM_HPP_REGISTER_TRAITS(e2d::layout::directions)
|
||||||
|
|
||||||
namespace e2d
|
namespace e2d
|
||||||
{
|
{
|
||||||
@@ -113,15 +115,6 @@ 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_;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline layout& layout::halign(haligns value) noexcept {
|
inline layout& layout::halign(haligns value) noexcept {
|
||||||
halign_ = value;
|
halign_ = value;
|
||||||
return *this;
|
return *this;
|
||||||
@@ -140,6 +133,15 @@ namespace e2d
|
|||||||
return valign_;
|
return valign_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline layout& layout::direction(directions value) noexcept {
|
||||||
|
direction_ = value;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline layout::directions layout::direction() const noexcept {
|
||||||
|
return direction_;
|
||||||
|
}
|
||||||
|
|
||||||
inline layout& layout::size(const v2f& value) noexcept {
|
inline layout& layout::size(const v2f& value) noexcept {
|
||||||
size_ = value;
|
size_ = value;
|
||||||
return *this;
|
return *this;
|
||||||
@@ -174,9 +176,9 @@ namespace e2d::layouts
|
|||||||
gcomponent<layout> unmark_dirty(gcomponent<layout> self);
|
gcomponent<layout> unmark_dirty(gcomponent<layout> self);
|
||||||
bool is_dirty(const const_gcomponent<layout>& self) noexcept;
|
bool is_dirty(const const_gcomponent<layout>& self) noexcept;
|
||||||
|
|
||||||
gcomponent<layout> change_mode(gcomponent<layout> self, layout::modes value);
|
|
||||||
gcomponent<layout> change_halign(gcomponent<layout> self, layout::haligns value);
|
gcomponent<layout> change_halign(gcomponent<layout> self, layout::haligns value);
|
||||||
gcomponent<layout> change_valign(gcomponent<layout> self, layout::valigns value);
|
gcomponent<layout> change_valign(gcomponent<layout> self, layout::valigns value);
|
||||||
|
gcomponent<layout> change_direction(gcomponent<layout> self, layout::directions value);
|
||||||
|
|
||||||
gcomponent<layout> change_size(gcomponent<layout> self, const v2f& value);
|
gcomponent<layout> change_size(gcomponent<layout> self, const v2f& value);
|
||||||
gcomponent<layout> change_margin(gcomponent<layout> self, const v2f& value);
|
gcomponent<layout> change_margin(gcomponent<layout> self, const v2f& value);
|
||||||
|
|||||||
@@ -9,15 +9,15 @@ local layout = {
|
|||||||
---@type boolean
|
---@type boolean
|
||||||
dirty = false,
|
dirty = false,
|
||||||
|
|
||||||
---@type layout_modes
|
|
||||||
mode = layout.modes.horizontal,
|
|
||||||
|
|
||||||
---@type layout_haligns
|
---@type layout_haligns
|
||||||
halign = layout.haligns.center,
|
halign = layout.haligns.center,
|
||||||
|
|
||||||
---@type layout_valigns
|
---@type layout_valigns
|
||||||
valign = layout.valigns.center,
|
valign = layout.valigns.center,
|
||||||
|
|
||||||
|
---@type layout_directions
|
||||||
|
direction = layout.directions.row,
|
||||||
|
|
||||||
---@type v2f
|
---@type v2f
|
||||||
size = v2f.zero(),
|
size = v2f.zero(),
|
||||||
|
|
||||||
@@ -28,12 +28,6 @@ local layout = {
|
|||||||
padding = v2f.zero()
|
padding = v2f.zero()
|
||||||
}
|
}
|
||||||
|
|
||||||
---@class layout_modes
|
|
||||||
layout.modes = {
|
|
||||||
horizontal = "horizontal",
|
|
||||||
vertical = "vertical"
|
|
||||||
}
|
|
||||||
|
|
||||||
---@class layout_haligns
|
---@class layout_haligns
|
||||||
layout.haligns = {
|
layout.haligns = {
|
||||||
left = "left",
|
left = "left",
|
||||||
@@ -54,6 +48,14 @@ layout.valigns = {
|
|||||||
space_between = "space_between"
|
space_between = "space_between"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
---@class layout_directions
|
||||||
|
layout.directions = {
|
||||||
|
row = "row",
|
||||||
|
row_reversed = "row_reversed",
|
||||||
|
column = "column",
|
||||||
|
column_reversed = "column_reversed"
|
||||||
|
}
|
||||||
|
|
||||||
---@overload fun(self: layout)
|
---@overload fun(self: layout)
|
||||||
---@param self layout
|
---@param self layout
|
||||||
function layout.enable(self) end
|
function layout.enable(self) end
|
||||||
|
|||||||
@@ -67,14 +67,6 @@ namespace e2d::bindings::high
|
|||||||
}
|
}
|
||||||
),
|
),
|
||||||
|
|
||||||
"mode", sol::property(
|
|
||||||
[](const gcomponent<layout>& c) -> layout::modes {
|
|
||||||
return c->mode();
|
|
||||||
},
|
|
||||||
[](gcomponent<layout>& c, layout::modes v){
|
|
||||||
layouts::change_mode(c, v);
|
|
||||||
}),
|
|
||||||
|
|
||||||
"halign", sol::property(
|
"halign", sol::property(
|
||||||
[](const gcomponent<layout>& c) -> layout::haligns {
|
[](const gcomponent<layout>& c) -> layout::haligns {
|
||||||
return c->halign();
|
return c->halign();
|
||||||
@@ -91,6 +83,14 @@ namespace e2d::bindings::high
|
|||||||
layouts::change_valign(c, v);
|
layouts::change_valign(c, v);
|
||||||
}),
|
}),
|
||||||
|
|
||||||
|
"direction", sol::property(
|
||||||
|
[](const gcomponent<layout>& c) -> layout::directions {
|
||||||
|
return c->direction();
|
||||||
|
},
|
||||||
|
[](gcomponent<layout>& c, layout::directions v){
|
||||||
|
layouts::change_direction(c, v);
|
||||||
|
}),
|
||||||
|
|
||||||
"size", sol::property(
|
"size", sol::property(
|
||||||
[](const gcomponent<layout>& c) -> v2f {
|
[](const gcomponent<layout>& c) -> v2f {
|
||||||
return c->size();
|
return c->size();
|
||||||
@@ -116,14 +116,6 @@ namespace e2d::bindings::high
|
|||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
#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
|
|
||||||
|
|
||||||
#define LAYOUT_HALIGN_PAIR(x) {#x, layout::haligns::x},
|
#define LAYOUT_HALIGN_PAIR(x) {#x, layout::haligns::x},
|
||||||
l["layout"].get_or_create<sol::table>()
|
l["layout"].get_or_create<sol::table>()
|
||||||
.new_enum<layout::haligns>("haligns", {
|
.new_enum<layout::haligns>("haligns", {
|
||||||
@@ -147,5 +139,15 @@ namespace e2d::bindings::high
|
|||||||
LAYOUT_VALIGN_PAIR(space_between)
|
LAYOUT_VALIGN_PAIR(space_between)
|
||||||
});
|
});
|
||||||
#undef LAYOUT_VALIGN_PAIR
|
#undef LAYOUT_VALIGN_PAIR
|
||||||
|
|
||||||
|
#define LAYOUT_DIRECTION_PAIR(x) {#x, layout::directions::x},
|
||||||
|
l["layout"].get_or_create<sol::table>()
|
||||||
|
.new_enum<layout::directions>("directions", {
|
||||||
|
LAYOUT_DIRECTION_PAIR(row)
|
||||||
|
LAYOUT_DIRECTION_PAIR(row_reversed)
|
||||||
|
LAYOUT_DIRECTION_PAIR(column)
|
||||||
|
LAYOUT_DIRECTION_PAIR(column_reversed)
|
||||||
|
});
|
||||||
|
#undef LAYOUT_DIRECTION_PAIR
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,21 +15,14 @@ namespace e2d
|
|||||||
"required" : [],
|
"required" : [],
|
||||||
"additionalProperties" : false,
|
"additionalProperties" : false,
|
||||||
"properties" : {
|
"properties" : {
|
||||||
"mode" : { "$ref": "#/definitions/modes" },
|
|
||||||
"halign" : { "$ref": "#/definitions/haligns" },
|
"halign" : { "$ref": "#/definitions/haligns" },
|
||||||
"valign" : { "$ref": "#/definitions/valigns" },
|
"valign" : { "$ref": "#/definitions/valigns" },
|
||||||
|
"direction" : { "$ref": "#/definitions/directions" },
|
||||||
"size" : { "$ref": "#/common_definitions/v2" },
|
"size" : { "$ref": "#/common_definitions/v2" },
|
||||||
"margin" : { "$ref": "#/common_definitions/v2" },
|
"margin" : { "$ref": "#/common_definitions/v2" },
|
||||||
"padding" : { "$ref": "#/common_definitions/v2" }
|
"padding" : { "$ref": "#/common_definitions/v2" }
|
||||||
},
|
},
|
||||||
"definitions" : {
|
"definitions" : {
|
||||||
"modes" : {
|
|
||||||
"type" : "string",
|
|
||||||
"enum" : [
|
|
||||||
"horizontal",
|
|
||||||
"vertical"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"haligns" : {
|
"haligns" : {
|
||||||
"type" : "string",
|
"type" : "string",
|
||||||
"enum" : [
|
"enum" : [
|
||||||
@@ -51,6 +44,15 @@ namespace e2d
|
|||||||
"space_evenly",
|
"space_evenly",
|
||||||
"space_between"
|
"space_between"
|
||||||
]
|
]
|
||||||
|
},
|
||||||
|
"directions" : {
|
||||||
|
"type" : "string",
|
||||||
|
"enum" : [
|
||||||
|
"row",
|
||||||
|
"row_reversed",
|
||||||
|
"column",
|
||||||
|
"column_reversed"
|
||||||
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})json";
|
})json";
|
||||||
@@ -59,15 +61,6 @@ namespace e2d
|
|||||||
layout& component,
|
layout& component,
|
||||||
const fill_context& ctx) const
|
const fill_context& ctx) const
|
||||||
{
|
{
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( ctx.root.HasMember("halign") ) {
|
if ( ctx.root.HasMember("halign") ) {
|
||||||
layout::haligns halign = component.halign();
|
layout::haligns halign = component.halign();
|
||||||
if ( !json_utils::try_parse_value(ctx.root["halign"], halign) ) {
|
if ( !json_utils::try_parse_value(ctx.root["halign"], halign) ) {
|
||||||
@@ -86,6 +79,15 @@ namespace e2d
|
|||||||
component.valign(valign);
|
component.valign(valign);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ( ctx.root.HasMember("direction") ) {
|
||||||
|
layout::directions direction = component.direction();
|
||||||
|
if ( !json_utils::try_parse_value(ctx.root["direction"], direction) ) {
|
||||||
|
the<debug>().error("LAYOUT: Incorrect formatting of 'direction' property");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
component.direction(direction);
|
||||||
|
}
|
||||||
|
|
||||||
if ( ctx.root.HasMember("size") ) {
|
if ( ctx.root.HasMember("size") ) {
|
||||||
v2f size = component.size();
|
v2f size = component.size();
|
||||||
if ( !json_utils::try_parse_value(ctx.root["size"], size) ) {
|
if ( !json_utils::try_parse_value(ctx.root["size"], size) ) {
|
||||||
@@ -168,12 +170,6 @@ namespace e2d
|
|||||||
|
|
||||||
ImGui::Separator();
|
ImGui::Separator();
|
||||||
|
|
||||||
if ( layout::modes mode = c->mode();
|
|
||||||
imgui_utils::show_enum_combo_box("mode", &mode) )
|
|
||||||
{
|
|
||||||
layouts::change_mode(c, mode);
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( layout::haligns halign = c->halign();
|
if ( layout::haligns halign = c->halign();
|
||||||
imgui_utils::show_enum_combo_box("halign", &halign) )
|
imgui_utils::show_enum_combo_box("halign", &halign) )
|
||||||
{
|
{
|
||||||
@@ -186,6 +182,12 @@ namespace e2d
|
|||||||
layouts::change_valign(c, valign);
|
layouts::change_valign(c, valign);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ( layout::directions direction = c->direction();
|
||||||
|
imgui_utils::show_enum_combo_box("direction", &direction) )
|
||||||
|
{
|
||||||
|
layouts::change_direction(c, direction);
|
||||||
|
}
|
||||||
|
|
||||||
if ( v2f size = c->size();
|
if ( v2f size = c->size();
|
||||||
ImGui::DragFloat2("size", size.data(), 1.f) )
|
ImGui::DragFloat2("size", size.data(), 1.f) )
|
||||||
{
|
{
|
||||||
@@ -252,13 +254,6 @@ namespace e2d::layouts
|
|||||||
return self.owner().component<layout::dirty>().exists();
|
return self.owner().component<layout::dirty>().exists();
|
||||||
}
|
}
|
||||||
|
|
||||||
gcomponent<layout> change_mode(gcomponent<layout> self, layout::modes value) {
|
|
||||||
if ( self ) {
|
|
||||||
self->mode(value);
|
|
||||||
}
|
|
||||||
return mark_dirty(self);
|
|
||||||
}
|
|
||||||
|
|
||||||
gcomponent<layout> change_halign(gcomponent<layout> self, layout::haligns value) {
|
gcomponent<layout> change_halign(gcomponent<layout> self, layout::haligns value) {
|
||||||
if ( self ) {
|
if ( self ) {
|
||||||
self->halign(value);
|
self->halign(value);
|
||||||
@@ -273,6 +268,13 @@ namespace e2d::layouts
|
|||||||
return mark_dirty(self);
|
return mark_dirty(self);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
gcomponent<layout> change_direction(gcomponent<layout> self, layout::directions value) {
|
||||||
|
if ( self ) {
|
||||||
|
self->direction(value);
|
||||||
|
}
|
||||||
|
return mark_dirty(self);
|
||||||
|
}
|
||||||
|
|
||||||
gcomponent<layout> change_size(gcomponent<layout> self, const v2f& value) {
|
gcomponent<layout> change_size(gcomponent<layout> self, const v2f& value) {
|
||||||
if ( self ) {
|
if ( self ) {
|
||||||
self->size(value);
|
self->size(value);
|
||||||
|
|||||||
@@ -28,10 +28,27 @@ namespace
|
|||||||
using namespace e2d;
|
using namespace e2d;
|
||||||
|
|
||||||
void update_yogo_node(const yogo_node& yn, const layout& l, const actor& a) {
|
void update_yogo_node(const yogo_node& yn, const layout& l, const actor& a) {
|
||||||
switch ( l.mode() ) {
|
switch ( l.direction() ) {
|
||||||
case layout::modes::horizontal:
|
case layout::directions::row:
|
||||||
YGNodeStyleSetFlexDirection(yn.as_root.get(), YGFlexDirectionRow);
|
YGNodeStyleSetFlexDirection(yn.as_root.get(), YGFlexDirectionRow);
|
||||||
|
break;
|
||||||
|
case layout::directions::row_reversed:
|
||||||
|
YGNodeStyleSetFlexDirection(yn.as_root.get(), YGFlexDirectionRowReverse);
|
||||||
|
break;
|
||||||
|
case layout::directions::column:
|
||||||
|
YGNodeStyleSetFlexDirection(yn.as_root.get(), YGFlexDirectionColumn);
|
||||||
|
break;
|
||||||
|
case layout::directions::column_reversed:
|
||||||
|
YGNodeStyleSetFlexDirection(yn.as_root.get(), YGFlexDirectionColumnReverse);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
E2D_ASSERT_MSG(false, "unexpected layout direction");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
switch ( l.direction() ) {
|
||||||
|
case layout::directions::row:
|
||||||
|
case layout::directions::row_reversed:
|
||||||
switch ( l.halign() ) {
|
switch ( l.halign() ) {
|
||||||
case layout::haligns::left:
|
case layout::haligns::left:
|
||||||
YGNodeStyleSetJustifyContent(yn.as_root.get(), YGJustifyFlexStart);
|
YGNodeStyleSetJustifyContent(yn.as_root.get(), YGJustifyFlexStart);
|
||||||
@@ -75,9 +92,8 @@ namespace
|
|||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case layout::modes::vertical:
|
case layout::directions::column:
|
||||||
YGNodeStyleSetFlexDirection(yn.as_root.get(), YGFlexDirectionColumn);
|
case layout::directions::column_reversed:
|
||||||
|
|
||||||
switch ( l.valign() ) {
|
switch ( l.valign() ) {
|
||||||
case layout::valigns::top:
|
case layout::valigns::top:
|
||||||
YGNodeStyleSetJustifyContent(yn.as_root.get(), YGJustifyFlexEnd);
|
YGNodeStyleSetJustifyContent(yn.as_root.get(), YGJustifyFlexEnd);
|
||||||
|
|||||||
Reference in New Issue
Block a user