Formatting
publish / publish (push) Successful in 15m37s

This commit is contained in:
khodowany
2026-09-14 23:56:06 -05:00
parent 86cf029ad7
commit bb96aaf95d
30 changed files with 1030 additions and 950 deletions
+43 -37
View File
@@ -17,13 +17,14 @@
#include <luma/render.hpp>
#include <luma/theme.hpp>
namespace {
class scope_exit {
public:
explicit scope_exit(std::function<void()> action);
scope_exit(scope_exit const&) = delete;
auto operator=(scope_exit const&) -> scope_exit& = delete;
scope_exit(scope_exit const &) = delete;
auto operator=(scope_exit const &) -> scope_exit & = delete;
~scope_exit();
private:
std::function<void()> action_{};
@@ -53,11 +54,11 @@ auto dialog_bounds(luma::rect bounds) -> luma::rect {
auto dialog_body_bounds(luma::rect bounds) -> luma::rect {
return luma::inset(dialog_bounds(bounds), {
16.0F,
56.0F,
16.0F,
72.0F,
});
16.0F,
56.0F,
16.0F,
72.0F,
});
}
auto accept_bounds(luma::rect bounds, std::bool_t has_cancel) -> luma::rect {
@@ -82,18 +83,19 @@ auto cancel_bounds(luma::rect bounds) -> luma::rect {
};
}
auto draw_button(luma::draw_context& context, luma::theme const& theme, luma::rect bounds, std::string const& text, luma::color fill) -> void {
auto draw_button(luma::draw_context &context, luma::theme const &theme, luma::rect bounds, std::string const &text, luma::color fill) -> void {
context.fill_rect(bounds, fill);
context.stroke_rect(bounds, 1.0F, theme.border);
auto measured = context.measure_text(text, theme.body);
context.draw_text(text, {
.x = bounds.x + (bounds.width - measured.width) * 0.5F,
.y = bounds.y + (bounds.height - measured.height) * 0.5F,
}, theme.body, theme.text);
.x = bounds.x + (bounds.width - measured.width) * 0.5F,
.y = bounds.y + (bounds.height - measured.height) * 0.5F,
},
theme.body, theme.text);
}
auto first_point_inside(luma::touch_event const& event, luma::rect bounds, luma::touch_phase phase) -> luma::touch_point const* {
for (auto const& point : event.points) {
auto first_point_inside(luma::touch_event const &event, luma::rect bounds, luma::touch_phase phase) -> luma::touch_point const * {
for (auto const &point : event.points) {
if (point.phase == phase && luma::contains(bounds, point.position)) {
return &point;
}
@@ -101,8 +103,8 @@ auto first_point_inside(luma::touch_event const& event, luma::rect bounds, luma:
return nullptr;
}
auto any_point_inside(luma::touch_event const& event, luma::rect bounds) -> std::bool_t {
for (auto const& point : event.points) {
auto any_point_inside(luma::touch_event const &event, luma::rect bounds) -> std::bool_t {
for (auto const &point : event.points) {
if (luma::contains(bounds, point.position)) {
return true;
}
@@ -110,13 +112,14 @@ auto any_point_inside(luma::touch_event const& event, luma::rect bounds) -> std:
return false;
}
auto throw_if_failed(std::expected<void, modulus::error> const& status) -> void {
auto throw_if_failed(std::expected<void, modulus::error> const &status) -> void {
if (!status) {
throw std::runtime_error(status.error().describe());
}
}
scope_exit::scope_exit(std::function<void()> action) : action_{std::move(action)} {}
scope_exit::scope_exit(std::function<void()> action)
: action_{std::move(action)} {}
scope_exit::~scope_exit() {
if (action_) {
@@ -126,7 +129,8 @@ scope_exit::~scope_exit() {
}
luma::overlay_host::overlay_host(std::unique_ptr<luma::control> content) : content_{std::move(content)} {
luma::overlay_host::overlay_host(std::unique_ptr<luma::control> content)
: content_{std::move(content)} {
assert(content_ != nullptr);
}
@@ -163,7 +167,7 @@ auto luma::overlay_host::close_dialog(luma::dialog_result result) -> std::expect
if (callback) {
try {
callback(result);
} catch (std::exception const& error) {
} catch (std::exception const &error) {
return luma::detail::fail<void>(luma::detail::error_internal, std::string{"dialog close callback failed: "} + error.what());
} catch (...) {
return luma::detail::fail<void>(luma::detail::error_internal, "dialog close callback failed with an unknown exception");
@@ -226,7 +230,7 @@ auto luma::overlay_host::tick(std::chrono::steady_clock::duration delta) -> std:
return false;
}
auto luma::overlay_host::measure(luma::draw_context& context, luma::theme const& theme, luma::constraints limits) -> luma::size {
auto luma::overlay_host::measure(luma::draw_context &context, luma::theme const &theme, luma::constraints limits) -> luma::size {
assert(content_ != nullptr);
begin_traversal();
auto guard = scope_exit{[this] {
@@ -234,14 +238,14 @@ auto luma::overlay_host::measure(luma::draw_context& context, luma::theme const&
}};
auto measured = content_->measure(context, theme, limits);
if (dialog_ && dialog_->body) {
auto* body = dialog_->body.get();
auto *body = dialog_->body.get();
body->measure(context, theme, {
.min = {},
.max = {
.width = limits.max.width * 0.8F,
.height = limits.max.height * 0.8F,
},
});
.min = {},
.max = {
.width = limits.max.width * 0.8F,
.height = limits.max.height * 0.8F,
},
});
}
return measured;
}
@@ -255,12 +259,12 @@ auto luma::overlay_host::arrange(luma::rect bounds) -> void {
luma::control::arrange(bounds);
content_->arrange(bounds);
if (dialog_ && dialog_->body) {
auto* body = dialog_->body.get();
auto *body = dialog_->body.get();
body->arrange(dialog_body_bounds(bounds));
}
}
auto luma::overlay_host::draw(luma::draw_context& context, luma::theme const& theme) const -> void {
auto luma::overlay_host::draw(luma::draw_context &context, luma::theme const &theme) const -> void {
assert(content_ != nullptr);
begin_traversal();
auto guard = scope_exit{[this] {
@@ -272,13 +276,14 @@ auto luma::overlay_host::draw(luma::draw_context& context, luma::theme const& th
auto title = dialog_->title;
auto accept_text = dialog_->accept_text;
auto cancel_text = dialog_->cancel_text;
auto* body = dialog_->body.get();
auto *body = dialog_->body.get();
context.fill_rect(dialog, theme.surface);
context.stroke_rect(dialog, 2.0F, theme.accent);
context.draw_text(title, {
.x = dialog.x + 16.0F,
.y = dialog.y + 16.0F,
}, theme.title, theme.text);
.x = dialog.x + 16.0F,
.y = dialog.y + 16.0F,
},
theme.title, theme.text);
body->draw(context, theme);
auto has_cancel = !cancel_text.empty();
if (has_cancel) {
@@ -295,13 +300,14 @@ auto luma::overlay_host::draw(luma::draw_context& context, luma::theme const& th
};
context.fill_rect(toast_bounds, theme.surface_active);
context.draw_text(toasts_.front().message, {
.x = toast_bounds.x + 16.0F,
.y = toast_bounds.y + 10.0F,
}, theme.body, theme.text);
.x = toast_bounds.x + 16.0F,
.y = toast_bounds.y + 10.0F,
},
theme.body, theme.text);
}
}
auto luma::overlay_host::handle_touch(luma::touch_event const& event) -> std::bool_t {
auto luma::overlay_host::handle_touch(luma::touch_event const &event) -> std::bool_t {
assert(content_ != nullptr);
begin_traversal();
auto guard = scope_exit{[this] {