mirror of
https://github.com/enduro2d/enduro2d.git
synced 2025-12-15 00:11:55 +07:00
more align types for layouts
This commit is contained in:
@@ -21,12 +21,16 @@ namespace e2d
|
||||
ENUM_HPP_CLASS_DECL(haligns, u8,
|
||||
(left)
|
||||
(center)
|
||||
(right))
|
||||
(right)
|
||||
(space_around)
|
||||
(space_between))
|
||||
|
||||
ENUM_HPP_CLASS_DECL(valigns, u8,
|
||||
(top)
|
||||
(center)
|
||||
(bottom))
|
||||
(bottom)
|
||||
(space_around)
|
||||
(space_between))
|
||||
public:
|
||||
layout() = default;
|
||||
|
||||
@@ -38,14 +42,10 @@ namespace e2d
|
||||
|
||||
layout& valign(valigns value) noexcept;
|
||||
[[nodiscard]] valigns valign() const noexcept;
|
||||
|
||||
layout& spacing(f32 value) noexcept;
|
||||
[[nodiscard]] f32 spacing() const noexcept;
|
||||
private:
|
||||
modes mode_ = modes::horizontal;
|
||||
haligns halign_ = haligns::center;
|
||||
valigns valign_ = valigns::center;
|
||||
f32 spacing_ = 0.f;
|
||||
};
|
||||
|
||||
class layout_item final {
|
||||
@@ -54,8 +54,12 @@ namespace e2d
|
||||
|
||||
layout_item& size(const v2f& value) noexcept;
|
||||
[[nodiscard]] const v2f& size() const noexcept;
|
||||
|
||||
layout_item& padding(const v2f& value) noexcept;
|
||||
[[nodiscard]] const v2f& padding() const noexcept;
|
||||
private:
|
||||
v2f size_ = v2f::unit();
|
||||
v2f padding_ = v2f::zero();
|
||||
};
|
||||
}
|
||||
|
||||
@@ -156,15 +160,6 @@ namespace e2d
|
||||
inline layout::valigns layout::valign() const noexcept {
|
||||
return valign_;
|
||||
}
|
||||
|
||||
inline layout& layout::spacing(f32 value) noexcept {
|
||||
spacing_ = value;
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline f32 layout::spacing() const noexcept {
|
||||
return spacing_;
|
||||
}
|
||||
}
|
||||
|
||||
namespace e2d
|
||||
@@ -177,6 +172,15 @@ namespace e2d
|
||||
inline const v2f& layout_item::size() const noexcept {
|
||||
return size_;
|
||||
}
|
||||
|
||||
inline layout_item& layout_item::padding(const v2f& value) noexcept {
|
||||
padding_ = value;
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline const v2f& layout_item::padding() const noexcept {
|
||||
return padding_;
|
||||
}
|
||||
}
|
||||
|
||||
namespace e2d::layouts
|
||||
@@ -188,7 +192,6 @@ namespace e2d::layouts
|
||||
gcomponent<layout> change_mode(gcomponent<layout> self, layout::modes value);
|
||||
gcomponent<layout> change_halign(gcomponent<layout> self, layout::haligns value);
|
||||
gcomponent<layout> change_valign(gcomponent<layout> self, layout::valigns value);
|
||||
gcomponent<layout> change_spacing(gcomponent<layout> self, f32 value);
|
||||
}
|
||||
|
||||
namespace e2d::layout_items
|
||||
@@ -198,6 +201,7 @@ namespace e2d::layout_items
|
||||
bool is_dirty(const const_gcomponent<layout_item>& self) noexcept;
|
||||
|
||||
gcomponent<layout_item> change_size(gcomponent<layout_item> self, const v2f& value);
|
||||
gcomponent<layout_item> change_padding(gcomponent<layout_item> self, const v2f& value);
|
||||
|
||||
gcomponent<layout> find_parent_layout(const_gcomponent<layout_item> self) noexcept;
|
||||
}
|
||||
|
||||
@@ -22,10 +22,7 @@ local layout = {
|
||||
halign = layout.haligns.center,
|
||||
|
||||
---@type layout_valigns
|
||||
valign = layout.valigns.center,
|
||||
|
||||
---@type number
|
||||
spacing = 0.0
|
||||
valign = layout.valigns.center
|
||||
}
|
||||
|
||||
---@class layout_modes
|
||||
@@ -38,14 +35,18 @@ layout.modes = {
|
||||
layout.haligns = {
|
||||
left = "left",
|
||||
center = "center",
|
||||
right = "right"
|
||||
right = "right",
|
||||
space_around = "space_around",
|
||||
space_between = "space_between"
|
||||
}
|
||||
|
||||
---@class layout_valigns
|
||||
layout.valigns = {
|
||||
top = "top",
|
||||
center = "center",
|
||||
bottom = "bottom"
|
||||
bottom = "bottom",
|
||||
space_around = "space_around",
|
||||
space_between = "space_between"
|
||||
}
|
||||
|
||||
---@overload fun(self: layout)
|
||||
@@ -74,7 +75,10 @@ local layout_item = {
|
||||
dirty = false,
|
||||
|
||||
---@type v2f
|
||||
size = v2f.unit()
|
||||
size = v2f.unit(),
|
||||
|
||||
---@type v2f
|
||||
padding = v2f.zero()
|
||||
}
|
||||
|
||||
---@overload fun(self: layout_item)
|
||||
|
||||
@@ -89,14 +89,6 @@ namespace e2d::bindings::high
|
||||
},
|
||||
[](gcomponent<layout>& c, layout::valigns v){
|
||||
layouts::change_valign(c, v);
|
||||
}),
|
||||
|
||||
"spacing", sol::property(
|
||||
[](const gcomponent<layout>& c) -> f32 {
|
||||
return c->spacing();
|
||||
},
|
||||
[](gcomponent<layout>& c, f32 v){
|
||||
layouts::change_spacing(c, v);
|
||||
})
|
||||
);
|
||||
|
||||
@@ -114,6 +106,8 @@ namespace e2d::bindings::high
|
||||
LAYOUT_HALIGN_PAIR(left)
|
||||
LAYOUT_HALIGN_PAIR(center)
|
||||
LAYOUT_HALIGN_PAIR(right)
|
||||
LAYOUT_HALIGN_PAIR(space_around)
|
||||
LAYOUT_HALIGN_PAIR(space_between)
|
||||
});
|
||||
#undef LAYOUT_HALIGN_PAIR
|
||||
|
||||
@@ -123,6 +117,8 @@ namespace e2d::bindings::high
|
||||
LAYOUT_VALIGN_PAIR(top)
|
||||
LAYOUT_VALIGN_PAIR(center)
|
||||
LAYOUT_VALIGN_PAIR(bottom)
|
||||
LAYOUT_VALIGN_PAIR(space_around)
|
||||
LAYOUT_VALIGN_PAIR(space_between)
|
||||
});
|
||||
#undef LAYOUT_VALIGN_PAIR
|
||||
|
||||
@@ -186,6 +182,14 @@ namespace e2d::bindings::high
|
||||
},
|
||||
[](gcomponent<layout_item>& c, const v2f& v){
|
||||
layout_items::change_size(c, v);
|
||||
}),
|
||||
|
||||
"padding", sol::property(
|
||||
[](const gcomponent<layout_item>& c) -> v2f {
|
||||
return c->padding();
|
||||
},
|
||||
[](gcomponent<layout_item>& c, const v2f& v){
|
||||
layout_items::change_padding(c, v);
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
@@ -17,8 +17,7 @@ namespace e2d
|
||||
"properties" : {
|
||||
"mode" : { "$ref": "#/definitions/modes" },
|
||||
"halign" : { "$ref": "#/definitions/haligns" },
|
||||
"valign" : { "$ref": "#/definitions/valigns" },
|
||||
"spacing" : { "type" : "number" }
|
||||
"valign" : { "$ref": "#/definitions/valigns" }
|
||||
},
|
||||
"definitions" : {
|
||||
"modes" : {
|
||||
@@ -33,7 +32,9 @@ namespace e2d
|
||||
"enum" : [
|
||||
"left",
|
||||
"center",
|
||||
"right"
|
||||
"right",
|
||||
"space_around",
|
||||
"space_between"
|
||||
]
|
||||
},
|
||||
"valigns" : {
|
||||
@@ -41,7 +42,9 @@ namespace e2d
|
||||
"enum" : [
|
||||
"top",
|
||||
"center",
|
||||
"bottom"
|
||||
"bottom",
|
||||
"space_around",
|
||||
"space_between"
|
||||
]
|
||||
}
|
||||
}
|
||||
@@ -78,15 +81,6 @@ namespace e2d
|
||||
component.valign(valign);
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -132,7 +126,8 @@ namespace e2d
|
||||
"required" : [],
|
||||
"additionalProperties" : false,
|
||||
"properties" : {
|
||||
"size" : { "$ref": "#/common_definitions/v2" }
|
||||
"size" : { "$ref": "#/common_definitions/v2" },
|
||||
"padding" : { "$ref": "#/common_definitions/v2" }
|
||||
}
|
||||
})json";
|
||||
|
||||
@@ -149,6 +144,15 @@ namespace e2d
|
||||
component.size(size);
|
||||
}
|
||||
|
||||
if ( ctx.root.HasMember("padding") ) {
|
||||
v2f padding = component.padding();
|
||||
if ( !json_utils::try_parse_value(ctx.root["padding"], padding) ) {
|
||||
the<debug>().error("LAYOUT_ITEM: Incorrect formatting of 'padding' property");
|
||||
return false;
|
||||
}
|
||||
component.padding(padding);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -183,12 +187,6 @@ namespace e2d
|
||||
{
|
||||
layouts::change_valign(c, valign);
|
||||
}
|
||||
|
||||
if ( f32 spacing = c->spacing();
|
||||
ImGui::DragFloat("spacing", &spacing, 1.f) )
|
||||
{
|
||||
layouts::change_spacing(c, spacing);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -202,6 +200,12 @@ namespace e2d
|
||||
{
|
||||
layout_items::change_size(c, size);
|
||||
}
|
||||
|
||||
if ( v2f padding = c->padding();
|
||||
ImGui::DragFloat2("padding", padding.data(), 1.f) )
|
||||
{
|
||||
layout_items::change_padding(c, padding);
|
||||
}
|
||||
}
|
||||
|
||||
void component_inspector<layout_item>::operator()(
|
||||
@@ -212,6 +216,13 @@ namespace e2d
|
||||
c->size() * 0.5f,
|
||||
c->size(),
|
||||
ctx.selected() ? color32(255,255,255) : color32(127,127,127));
|
||||
|
||||
if ( ctx.selected() && c->padding() != v2f::zero() ) {
|
||||
ctx.draw_wire_rect(
|
||||
c->size() * 0.5f,
|
||||
c->size() - c->padding() * 2.f,
|
||||
ctx.selected() ? color32(255,255,255) : color32(127,127,127));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -255,13 +266,6 @@ namespace e2d::layouts
|
||||
}
|
||||
return mark_dirty(self);
|
||||
}
|
||||
|
||||
gcomponent<layout> change_spacing(gcomponent<layout> self, f32 value) {
|
||||
if ( self ) {
|
||||
self->spacing(value);
|
||||
}
|
||||
return mark_dirty(self);
|
||||
}
|
||||
}
|
||||
|
||||
namespace e2d::layout_items
|
||||
@@ -287,6 +291,13 @@ namespace e2d::layout_items
|
||||
return mark_dirty(self);
|
||||
}
|
||||
|
||||
gcomponent<layout_item> change_padding(gcomponent<layout_item> self, const v2f& value) {
|
||||
if ( self ) {
|
||||
self->padding(value);
|
||||
}
|
||||
return mark_dirty(self);
|
||||
}
|
||||
|
||||
gcomponent<layout> find_parent_layout(const_gcomponent<layout_item> self) noexcept {
|
||||
const_gcomponent<actor> self_actor = self.owner().component<actor>();
|
||||
return self_actor
|
||||
|
||||
Reference in New Issue
Block a user