Skip to content

Commit 2276523

Browse files
committed
fix: fix settings menu layout, make it more readable
also add some asserts in static layout generation
1 parent d4c0bb7 commit 2276523

File tree

3 files changed

+22
-9
lines changed

3 files changed

+22
-9
lines changed

src/scenes/settings_menu/settings_menu.cpp

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -86,16 +86,24 @@ namespace scenes {
8686
}
8787
);
8888

89-
auto text_input_index = scroll_layout->add<ui::TextInput>(
89+
90+
scroll_layout->add<ui::Label>(
91+
ui::RelativeItemSize{ scroll_layout->layout(), 0.2 }, service_provider, "Lobby",
92+
service_provider->font_manager().get(FontId::Default), Color::white(),
93+
std::pair<double, double>{ 0.1, 0.3 },
94+
ui::Alignment{ ui::AlignmentHorizontal::Middle, ui::AlignmentVertical::Bottom }
95+
);
96+
97+
auto api_url_input_index = scroll_layout->add<ui::TextInput>(
9098
ui::RelativeItemSize{ scroll_layout->layout(), 0.2 }, service_provider,
9199
service_provider->font_manager().get(FontId::Default), Color::white(), focus_helper.focus_id(),
92-
std::pair<double, double>{ 0.9, 0.9 },
100+
std::pair<double, double>{ 0.8, 0.6 },
93101
ui::Alignment{ ui::AlignmentHorizontal::Middle, ui::AlignmentVertical::Center },
94102
ui::TextInputMode::Scale
95103
);
96104

97105
if (auto api_url = m_settings.api_url; api_url.has_value()) {
98-
scroll_layout->get<ui::TextInput>(text_input_index)->set_text(api_url.value());
106+
scroll_layout->get<ui::TextInput>(api_url_input_index)->set_text(api_url.value());
99107
}
100108

101109

@@ -122,20 +130,21 @@ namespace scenes {
122130

123131
auto return_layout_index = m_main_layout.add<ui::GridLayout>(
124132
focus_helper.focus_id(), 2, ui::Direction::Horizontal, ui::AbsolutMargin{ 0 },
125-
std::pair<double, double>{ 0.0, 0.1 }
133+
std::pair<double, double>{ 0.2, 0.1 }
126134

127135
);
128136

129137
auto* return_layout = m_main_layout.get<ui::GridLayout>(return_layout_index);
130138

139+
131140
return_layout->add<ui::TextButton>(
132-
service_provider, "Return asn Save", service_provider->font_manager().get(FontId::Default),
141+
service_provider, "Return and Save", service_provider->font_manager().get(FontId::Default),
133142
Color::white(), focus_helper.focus_id(),
134143
[this](const ui::TextButton&) -> bool {
135144
m_next_command = Command{ Return{ ReturnType::Save } };
136145
return false;
137146
},
138-
std::pair<double, double>{ 0.15, 0.85 },
147+
std::pair<double, double>{ 0.8, 0.85 },
139148
ui::Alignment{ ui::AlignmentHorizontal::Middle, ui::AlignmentVertical::Center },
140149
std::pair<double, double>{ 0.1, 0.1 }
141150
);
@@ -147,7 +156,7 @@ namespace scenes {
147156
m_next_command = Command{ Return{ ReturnType::Cancel } };
148157
return false;
149158
},
150-
std::pair<double, double>{ 0.15, 0.85 },
159+
std::pair<double, double>{ 0.8, 0.85 },
151160
ui::Alignment{ ui::AlignmentHorizontal::Middle, ui::AlignmentVertical::Center },
152161
std::pair<double, double>{ 0.1, 0.1 }
153162
);

src/ui/components/text_button.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ ui::TextButton::TextButton(
1919
text, font,
2020
text_color, { fill_rect.top_left.x + static_cast<int>(margin.first),
2121
fill_rect.top_left.y + static_cast<int>(margin.second),
22-
fill_rect.width() - 2 * static_cast<int>(margin.first),
23-
fill_rect.height() - 2 * static_cast<int>(margin.second) } },
22+
fill_rect.width() - (2 * static_cast<int>(margin.first)),
23+
fill_rect.height() - (2 * static_cast<int>(margin.second)) } },
2424
focus_id,
2525
std::move(callback),
2626
fill_rect,

src/ui/layouts/grid_layout.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,17 @@ void ui::GridLayout::render(const ServiceProvider& service_provider) const {
4444

4545
if (direction == Direction::Horizontal) {
4646
const u32 total_margin = this->size <= 1 ? 0 : (this->size - 1) * gap.get_margin();
47+
assert(layout().get_rect().width() > (total_margin + (margin.first * 2))
48+
&& "width has to be greater than the margins");
4749
width = (layout().get_rect().width() - total_margin - (margin.first * 2)) / this->size;
4850

4951
const u32 margin_x = index * gap.get_margin();
5052
const u32 total_width = width * index;
5153
x_pos += margin_x + total_width;
5254
} else {
5355
const u32 total_margin = this->size <= 1 ? 0 : (this->size - 1) * gap.get_margin();
56+
assert(layout().get_rect().height() > (total_margin - (margin.second * 2))
57+
&& "height has to be greater than the margins");
5458
height = (layout().get_rect().height() - total_margin - (margin.second * 2)) / this->size;
5559

5660
const u32 margin_y = index * gap.get_margin();

0 commit comments

Comments
 (0)