Skip to content

Commit

Permalink
refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
igagis committed Aug 30, 2024
1 parent 8b264c4 commit d9de517
Show file tree
Hide file tree
Showing 13 changed files with 37 additions and 45 deletions.
4 changes: 2 additions & 2 deletions src/ruis/layout/layout_parameters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.

using namespace ruis;

lp lp::make(const tml::forest& desc, const ruis::units& units)
layout_parameters layout_parameters::make(const tml::forest& desc, const ruis::units& units)
{
lp ret;
layout_parameters ret;
for (const auto& p : desc) {
if (!is_property(p)) {
continue;
Expand Down
6 changes: 0 additions & 6 deletions src/ruis/layout/layout_parameters.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,6 @@ namespace ruis {
* @brief Layout parameters.
*/
struct layout_parameters {
constexpr const static dimension min = dim::min;
constexpr const static dimension max = dim::max;
constexpr const static dimension fill = dim::fill;

/**
* @brief desired dimensions.
*/
Expand All @@ -61,6 +57,4 @@ struct layout_parameters {
static layout_parameters make(const tml::forest& desc, const ruis::units& units);
};

using lp = layout_parameters;

}; // namespace ruis
6 changes: 3 additions & 3 deletions src/ruis/util/util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,11 @@ length ruis::parse_dimension_value(const tml::leaf& l, const ruis::units& units)
dimension ruis::parse_layout_dimension_value(const tml::leaf& l, const ruis::units& units)
{
if (l == "min") {
return lp::min;
return dim::min;
} else if (l == "fill") {
return lp::fill;
return dim::fill;
} else if (l == "max") {
return lp::max;
return dim::max;
}
return parse_dimension_value(l, units);
}
Expand Down
2 changes: 1 addition & 1 deletion src/ruis/widget/group/book.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ void book::push(const utki::shared_ref<page>& pg)
}

auto& lp = pg.get().get_layout_params();
lp.dims.set(lp::fill);
lp.dims.set(dim::fill);

pg.get().parent_book = this;
this->pages.push_back(pg);
Expand Down
2 changes: 1 addition & 1 deletion src/ruis/widget/group/collapse_area.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ collapse_area::collapse_area(const utki::shared_ref<ruis::context>& c, const tml
using namespace length_literals;
lp.dims.y() = 0_px;
} else {
lp.dims.y() = lp::min;
lp.dims.y() = dim::min;
}
};
}
Expand Down
4 changes: 2 additions & 2 deletions src/ruis/widget/group/margins.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ margins::margins(
{//
.layout_params =
{//
.dims = {lp::max, lp::max},
.dims = {dim::max, dim::max},
.weight = 1
},
.container_params = {.layout = layout::column}
Expand All @@ -65,7 +65,7 @@ margins::margins(
{//
.layout_params =
{//
.dims = {lp::max, lp::max},
.dims = {dim::max, dim::max},
.weight = 1
},
.widget_params =
Expand Down
2 changes: 1 addition & 1 deletion src/ruis/widget/group/scroll_area.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ void scroll_area::update_scroll_factor()
// it wants 'max' children to be bigger than scroll_area in case their minimal dimensions are bigger.
vector2 scroll_area::dims_for_widget(const widget& w) const
{
const lp& lp = w.get_layout_params_const();
const layout_parameters& lp = w.get_layout_params_const();
vector2 d;
for (unsigned i = 0; i != 2; ++i) {
switch (lp.dims[i].get_type()) {
Expand Down
6 changes: 3 additions & 3 deletions src/ruis/widget/group/tree_view.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ tree_view::tree_view( //
ruis::make::list(this->context,
{
.layout_params = {
.dims = {ruis::lp::min, ruis::lp::max}
.dims = {ruis::dim::min, ruis::dim::max}
},
.oriented_params = {
.vertical = true
Expand Down Expand Up @@ -77,8 +77,8 @@ tree_view::tree_view(const utki::shared_ref<ruis::context>& c, const tml::forest

auto& lp = this->item_list.get().get_layout_params();

lp.dims.y() = lp::max;
lp.dims.x() = lp::min;
lp.dims.y() = dim::max;
lp.dims.x() = dim::min;

this->item_list.get().data_set_change_handler = [this](list&) {
this->notify_view_change();
Expand Down
21 changes: 10 additions & 11 deletions src/ruis/widget/label/nine_patch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,13 @@ std::vector<utki::shared_ref<ruis::widget>> build_layout(
)
{
namespace m = ruis::make;
using ruis::lp;

// clang-format off
return {
m::container(c,
{
.layout_params = {
.dims = {lp::fill, lp::min}
.dims = {dim::fill, dim::min}
},
.container_params = {
.layout = layout::row
Expand All @@ -64,7 +63,7 @@ std::vector<utki::shared_ref<ruis::widget>> build_layout(
m::image(c,
{
.layout_params = {
.dims = {lp::fill, lp::min},
.dims = {dim::fill, dim::min},
.weight = 1
},
.widget_params = {
Expand All @@ -84,7 +83,7 @@ std::vector<utki::shared_ref<ruis::widget>> build_layout(
m::container(c,
{
.layout_params = {
.dims = {lp::max, lp::max},
.dims = {dim::max, dim::max},
.weight = 1
},
.container_params = {
Expand All @@ -95,7 +94,7 @@ std::vector<utki::shared_ref<ruis::widget>> build_layout(
m::image(c,
{
.layout_params = {
.dims = {lp::min, lp::fill}
.dims = {dim::min, dim::fill}
},
.widget_params = {
.id = "ruis_l"s
Expand All @@ -105,15 +104,15 @@ std::vector<utki::shared_ref<ruis::widget>> build_layout(
m::pile(c,
{
.layout_params = {
.dims = {lp::max, lp::max},
.dims = {dim::max, dim::max},
.weight = 1
}
},
{
m::image(c,
{
.layout_params = {
.dims = {lp::fill, lp::fill}
.dims = {dim::fill, dim::fill}
},
.widget_params = {
.id = "ruis_m"s
Expand All @@ -123,7 +122,7 @@ std::vector<utki::shared_ref<ruis::widget>> build_layout(
m::container(c,
{
.layout_params = {
.dims = {lp::max, lp::max}
.dims = {dim::max, dim::max}
},
.widget_params = {
.id = "ruis_content"s
Expand All @@ -136,7 +135,7 @@ std::vector<utki::shared_ref<ruis::widget>> build_layout(
m::image(c,
{
.layout_params = {
.dims = {lp::min, lp::fill}
.dims = {dim::min, dim::fill}
},
.widget_params = {
.id = "ruis_r"s
Expand All @@ -148,7 +147,7 @@ std::vector<utki::shared_ref<ruis::widget>> build_layout(
m::container(c,
{
.layout_params = {
.dims = {lp::fill, lp::min}
.dims = {dim::fill, dim::min}
},
.container_params = {
.layout = layout::row
Expand All @@ -165,7 +164,7 @@ std::vector<utki::shared_ref<ruis::widget>> build_layout(
m::image(c,
{
.layout_params = {
.dims = {lp::fill, lp::min},
.dims = {dim::fill, dim::min},
.weight = 1
},
.widget_params = {
Expand Down
12 changes: 6 additions & 6 deletions src/ruis/widget/widget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ widget::widget(const utki::shared_ref<ruis::context>& c, const tml::forest& desc

try {
if (p.value == "lp") {
this->layout_params = lp::make(p.children, this->context.get().units);
this->layout_params = layout_parameters::make(p.children, this->context.get().units);
} else if (p.value == "x") {
this->params.rectangle.p.x() =
parse_dimension_value(get_property_value(p), this->context.get().units).get(this->context);
Expand Down Expand Up @@ -76,7 +76,7 @@ widget::widget(const utki::shared_ref<ruis::context>& c, const tml::forest& desc

for (auto& d : this->layout_params.dims) {
if (d.is_undefined()) {
d = lp::min;
d = dim::min;
}
}

Expand All @@ -93,7 +93,7 @@ widget::widget(utki::shared_ref<ruis::context> context, layout_parameters layout
{
for (auto& d : this->layout_params.dims) {
if (d.is_undefined()) {
d = lp::min;
d = dim::min;
}
}

Expand Down Expand Up @@ -437,14 +437,14 @@ vector2 widget::pos_in_ancestor(vector2 pos, const widget* ancestor)
return this->parent()->pos_in_ancestor(this->rect().p + pos, ancestor);
}

lp& widget::get_layout_params()
layout_parameters& widget::get_layout_params()
{
if (this->parent()) {
this->parent()->invalidate_layout();
}

// NOLINTNEXTLINE(cppcoreguidelines-pro-type-const-cast)
return const_cast<lp&>(this->get_layout_params_const());
return const_cast<layout_parameters&>(this->get_layout_params_const());
}

widget& widget::get_widget(std::string_view id, bool allow_itself)
Expand Down Expand Up @@ -521,7 +521,7 @@ void widget::reload()

vector2 ruis::dims_for_widget(const widget& w, const vector2& parent_dims)
{
const lp& lp = w.get_layout_params_const();
const layout_parameters& lp = w.get_layout_params_const();
vector2 d;
for (unsigned i = 0; i != 2; ++i) {
switch (lp.dims[i].get_type()) {
Expand Down
4 changes: 2 additions & 2 deletions src/ruis/widget/widget.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,13 +144,13 @@ class widget : virtual public utki::shared
* This method invalidates layout.
* @return Layout parameters of the widget.
*/
lp& get_layout_params();
layout_parameters& get_layout_params();

/**
* @brief Get constant layout parameters of the widget.
* @return Constant layout parameters of the widget.
*/
const lp& get_layout_params_const() const
const layout_parameters& get_layout_params_const() const
{
return this->layout_params;
}
Expand Down
11 changes: 5 additions & 6 deletions tests/easing/src/gui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ using namespace std::string_view_literals;
using namespace ruis::length_literals;

namespace m = ruis::make;
using lp = ruis::layout_parameters;

namespace {
constexpr uint32_t animation_duration_ms = 1000;
Expand All @@ -33,7 +32,7 @@ utki::shared_ref<ruis::widget> make_eased_animation_sample( //
auto ret = m::margins(c,
{
.layout_params = {
.dims = {lp::fill, lp::min}
.dims = {ruis::dim::fill, ruis::dim::min}
},
.container_params = {
.layout = ruis::layout::column
Expand All @@ -46,7 +45,7 @@ utki::shared_ref<ruis::widget> make_eased_animation_sample( //
m::slider(c,
{
.layout_params = {
.dims = {lp::fill, lp::min}
.dims = {ruis::dim::fill, ruis::dim::min}
},
.widget_params = {
.id = "slider"s
Expand Down Expand Up @@ -109,7 +108,7 @@ utki::shared_ref<ruis::widget> make_left_column(utki::shared_ref<ruis::context>
return m::column(c,
{
.layout_params = {
.dims = {lp::fill, lp::fill},
.dims = {ruis::dim::fill, ruis::dim::fill},
.weight = 1
}
},
Expand Down Expand Up @@ -196,7 +195,7 @@ utki::shared_ref<ruis::widget> make_right_column(utki::shared_ref<ruis::context>
return m::column(c,
{
.layout_params = {
.dims = {lp::fill, lp::fill},
.dims = {ruis::dim::fill, ruis::dim::fill},
.weight = 1
}
},
Expand Down Expand Up @@ -278,7 +277,7 @@ utki::shared_ref<ruis::widget> make_gui(utki::shared_ref<ruis::context> c)
return m::row(c,
{
.layout_params = {
.dims = {lp::fill, lp::fill}
.dims = {ruis::dim::fill, ruis::dim::fill}
}
},
{
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/src/make.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const tst::set set("make", [](tst::suite& suite){
gui.context,
{
.layout_params = {
.dims = {ruis::lp::min, ruis::lp::fill}
.dims = {ruis::dim::min, ruis::dim::fill}
},
.container_params = {
.layout = ruis::layout::pile
Expand Down

0 comments on commit d9de517

Please sign in to comment.