From bb96aaf95d1b436dd3fdad1b732e21d4061f1bf3 Mon Sep 17 00:00:00 2001 From: khodowany Date: Mon, 14 Sep 2026 23:56:06 -0500 Subject: [PATCH] Formatting --- .gitea/workflows/ci.yml | 4 + README.md | 2 + conanfile.py | 8 - include/luma/animation.hpp | 1 + include/luma/application.hpp | 14 +- include/luma/assets.hpp | 9 +- include/luma/config.hpp | 21 +- include/luma/control.hpp | 9 +- include/luma/controls.hpp | 16 +- include/luma/detail/errors.hpp | 1 + include/luma/geometry.hpp | 1 + include/luma/input.hpp | 1 + include/luma/overlays.hpp | 7 +- include/luma/render.hpp | 7 +- include/luma/routing.hpp | 11 +- include/luma/theme.hpp | 15 +- include/luma/window.hpp | 23 +- modulus.py | 8 +- src/animation.cpp | 19 +- src/application.cpp | 198 ++++--- src/assets.cpp | 8 +- src/config.cpp | 54 +- src/control.cpp | 3 +- src/controls.cpp | 338 ++++++------ src/detail/errors.cpp | 1 + src/overlays.cpp | 80 +-- src/routing.cpp | 13 +- src/theme.cpp | 103 ++-- src/window.cpp | 91 ++-- tests/test.cpp | 914 +++++++++++++++++---------------- 30 files changed, 1030 insertions(+), 950 deletions(-) diff --git a/.gitea/workflows/ci.yml b/.gitea/workflows/ci.yml index 24b1552..ebe6f23 100644 --- a/.gitea/workflows/ci.yml +++ b/.gitea/workflows/ci.yml @@ -91,6 +91,10 @@ jobs: restore-keys: conan-${{ runner.os }}- - name: Configure native release run: python3 modulus.py configure --target x86_64_gcc12_release + - name: Check code style + run: | + python3 -m pip install --no-cache-dir -r build/build_tools/docker/format-requirements.txt + python3 modulus.py format --check - name: Build native release run: python3 modulus.py build --target x86_64_gcc12_release - name: Test native release diff --git a/README.md b/README.md index e0d7c2e..ab70335 100644 --- a/README.md +++ b/README.md @@ -6,6 +6,8 @@ Luma uses Modulus for shared build tooling, Boost.JSON, and raylib integration. ## Build +Code style is managed by Modulus: run `./modulus.py format` or `./modulus.py format --check`. The generated Neovim integration uses the same pinned container formatter for C++ and Python, including existing format-on-save toggles. Configure first to prepare tooling; customize `tooling.editor.clang_format` and `tooling.format.exclude` in `modulus.json`, not generated editor files. See the shared Modulus README for the compact layout and no-alias policy. + Configure, build, and test the default target: ```sh diff --git a/conanfile.py b/conanfile.py index bb6d2c4..dbd16d0 100644 --- a/conanfile.py +++ b/conanfile.py @@ -40,15 +40,12 @@ class luma_conan(conan.ConanFile): "tests/*.cpp", "tests/*.hpp", ) - def config_options(self): if self.settings.os == "Windows": del self.options.fPIC - def configure(self): if self.options.shared: del self.options.fPIC - def requirements(self): self.requires( "modulus/latest", @@ -58,7 +55,6 @@ class luma_conan(conan.ConanFile): "with_raylib": True, }, ) - def generate(self): deps = conan.tools.cmake.CMakeDeps(self) deps.generate() @@ -68,14 +64,12 @@ class luma_conan(conan.ConanFile): toolchain.variables["BUILD_SHARED_LIBS"] = bool(self.options.shared) toolchain.variables["BUILD_TESTING"] = bool(self.options.with_tests) toolchain.generate() - def build(self): cmake = conan.tools.cmake.CMake(self) cmake.configure() cmake.build() if self.options.with_tests and conan.tools.build.can_run(self): cmake.test(target="check") - def package_id(self): self.info.options.rm_safe("with_tests") for requirement in ( @@ -85,11 +79,9 @@ class luma_conan(conan.ConanFile): ): if requirement in self.info.requires.pkg_names: self.info.requires.remove(requirement) - def package(self): cmake = conan.tools.cmake.CMake(self) cmake.install() - def package_info(self): self.cpp_info.set_property( "cmake_file_name", diff --git a/include/luma/animation.hpp b/include/luma/animation.hpp index 15dac17..fbf2ab1 100644 --- a/include/luma/animation.hpp +++ b/include/luma/animation.hpp @@ -7,6 +7,7 @@ #include + namespace luma { enum class easing { diff --git a/include/luma/application.hpp b/include/luma/application.hpp index b4e5af2..cc5b31e 100644 --- a/include/luma/application.hpp +++ b/include/luma/application.hpp @@ -23,7 +23,9 @@ namespace luma { namespace detail { + struct application_core; + } struct frame_stats { @@ -34,11 +36,11 @@ struct frame_stats { class application { public: explicit application(luma::application_config config = {}); - application(luma::application const&) = delete; - application(luma::application&&) noexcept; + application(luma::application const &) = delete; + application(luma::application &&) noexcept; ~application(); - auto operator=(luma::application const&) -> luma::application& = delete; - auto operator=(luma::application&&) noexcept -> luma::application&; + auto operator=(luma::application const &) -> luma::application & = delete; + auto operator=(luma::application &&) noexcept -> luma::application &; auto dispatch(std::function()> task) -> std::expected; auto register_route(std::string name, std::function, modulus::error>()> factory) -> std::expected; auto replace_route(std::string name) -> std::expected; @@ -58,7 +60,7 @@ public: auto set_root(std::expected, modulus::error> root) -> std::expected; auto set_root(std::unique_ptr root) -> std::expected; template - requires (std::is_base_of_v && !std::is_same_v) + requires(std::is_base_of_v && !std::is_same_v) auto set_root(std::unique_ptr root) -> std::expected; auto show_dialog(luma::dialog_options options) -> std::expected; auto close_dialog(luma::dialog_result result) -> std::expected; @@ -73,7 +75,7 @@ private: }; template - requires (std::is_base_of_v && !std::is_same_v) + requires(std::is_base_of_v && !std::is_same_v) auto application::set_root(std::unique_ptr root) -> std::expected { return set_root(std::unique_ptr{std::move(root)}); } diff --git a/include/luma/assets.hpp b/include/luma/assets.hpp index fc4be87..f68ea18 100644 --- a/include/luma/assets.hpp +++ b/include/luma/assets.hpp @@ -11,22 +11,23 @@ #include + namespace luma { class renderer_resources { public: virtual ~renderer_resources() = default; - virtual auto load_texture(std::string const& path) -> std::expected, modulus::error> = 0; + virtual auto load_texture(std::string const &path) -> std::expected, modulus::error> = 0; }; class asset_cache { public: - explicit asset_cache(luma::renderer_resources& resources); - auto texture(std::string const& path) -> std::expected, modulus::error>; + explicit asset_cache(luma::renderer_resources &resources); + auto texture(std::string const &path) -> std::expected, modulus::error>; auto clear() -> void; private: struct in_flight_load; - luma::renderer_resources* resources_{}; + luma::renderer_resources *resources_{}; mutable std::mutex mutex_{}; std::uint64_t generation_{}; std::unordered_map> textures_{}; diff --git a/include/luma/config.hpp b/include/luma/config.hpp index 56c0c09..9ecca29 100644 --- a/include/luma/config.hpp +++ b/include/luma/config.hpp @@ -10,6 +10,7 @@ #include + namespace luma { struct display_config { @@ -31,15 +32,15 @@ struct application_config { luma::theme theme{luma::default_theme()}; }; -auto validate(luma::display_config const& config) -> std::expected; -auto validate(luma::touch_config const& config) -> std::expected; -auto validate(luma::application_config const& config) -> std::expected; -auto parse_display_config(boost::json::value const& value) -> std::expected; -auto parse_touch_config(boost::json::value const& value) -> std::expected; -auto parse_application_config(boost::json::value const& value) -> std::expected; -auto load_application_config(std::string const& path) -> std::expected; -auto to_json(luma::display_config const& config) -> boost::json::value; -auto to_json(luma::touch_config const& config) -> boost::json::value; -auto to_json(luma::application_config const& config) -> boost::json::value; +auto validate(luma::display_config const &config) -> std::expected; +auto validate(luma::touch_config const &config) -> std::expected; +auto validate(luma::application_config const &config) -> std::expected; +auto parse_display_config(boost::json::value const &value) -> std::expected; +auto parse_touch_config(boost::json::value const &value) -> std::expected; +auto parse_application_config(boost::json::value const &value) -> std::expected; +auto load_application_config(std::string const &path) -> std::expected; +auto to_json(luma::display_config const &config) -> boost::json::value; +auto to_json(luma::touch_config const &config) -> boost::json::value; +auto to_json(luma::application_config const &config) -> boost::json::value; } diff --git a/include/luma/control.hpp b/include/luma/control.hpp index 9ed819f..9404f47 100644 --- a/include/luma/control.hpp +++ b/include/luma/control.hpp @@ -6,19 +6,22 @@ #include + namespace luma { class draw_context; + struct theme; + struct touch_event; class control { public: virtual ~control(); - virtual auto measure(luma::draw_context& context, luma::theme const& theme, luma::constraints limits) -> luma::size = 0; + virtual auto measure(luma::draw_context &context, luma::theme const &theme, luma::constraints limits) -> luma::size = 0; virtual auto arrange(luma::rect bounds) -> void; - virtual auto draw(luma::draw_context& context, luma::theme const& theme) const -> void = 0; - virtual auto handle_touch(luma::touch_event const& event) -> std::bool_t; + virtual auto draw(luma::draw_context &context, luma::theme const &theme) const -> void = 0; + virtual auto handle_touch(luma::touch_event const &event) -> std::bool_t; virtual auto invalidate_layout() -> void; virtual auto bind_layout_invalidator(std::function invalidator) -> void; virtual auto focusable() const -> std::bool_t; diff --git a/include/luma/controls.hpp b/include/luma/controls.hpp index 7a27e54..46fd12d 100644 --- a/include/luma/controls.hpp +++ b/include/luma/controls.hpp @@ -76,7 +76,6 @@ public: std::weak_ptr lifetime{}; std::function callback{}; }; - text_input_state(luma::text_field_options options, std::function on_change); auto snapshot() const -> luma::text_field_options; auto text() const -> std::string; @@ -101,7 +100,7 @@ auto numeric_keyboard() -> luma::keyboard_layout; auto make_text_input(luma::text_field_options options, std::function on_change) -> std::expected, modulus::error>; template -auto children(CONTROLS&&... controls) -> std::expected>, modulus::error>; +auto children(CONTROLS &&...controls) -> std::expected>, modulus::error>; auto label(std::string text) -> std::expected, modulus::error>; auto button(std::string text, std::function on_click) -> std::expected, modulus::error>; @@ -123,7 +122,7 @@ auto stack(std::vector> children) -> std::expecte auto scroll_view(std::expected, modulus::error> child, std::bool_t vertical = true, std::bool_t horizontal = false) -> std::expected, modulus::error>; auto scroll_view(std::unique_ptr child, std::bool_t vertical = true, std::bool_t horizontal = false) -> std::expected, modulus::error>; template - requires (std::is_base_of_v && !std::is_same_v) + requires(std::is_base_of_v && !std::is_same_v) auto scroll_view(std::unique_ptr child, std::bool_t vertical = true, std::bool_t horizontal = false) -> std::expected, modulus::error>; auto list(std::expected>, modulus::error> children, std::float32_t gap = 4.0F) -> std::expected, modulus::error>; auto list(std::vector> children, std::float32_t gap = 4.0F) -> std::expected, modulus::error>; @@ -153,17 +152,16 @@ auto normalize_child(std::expected, modulus::error> chi } template - requires (std::is_base_of_v && !std::is_same_v) + requires(std::is_base_of_v && !std::is_same_v) auto luma::scroll_view(std::unique_ptr child, std::bool_t vertical, std::bool_t horizontal) -> std::expected, modulus::error> { return luma::scroll_view(std::unique_ptr{std::move(child)}, vertical, horizontal); } template -auto luma::children(CONTROLS&&... controls) -> std::expected>, modulus::error> { +auto luma::children(CONTROLS &&...controls) -> std::expected>, modulus::error> { auto result = std::vector>{}; result.reserve(sizeof...(controls)); - - auto append = [&result](auto&& input) -> std::expected { + auto append = [&result](auto &&input) -> std::expected { auto child = luma::detail::normalize_child(std::forward(input)); if (!child) { return modulus::fail(child.error()); @@ -171,13 +169,13 @@ auto luma::children(CONTROLS&&... controls) -> std::expected{}; ([&] { if (status) { status = append(std::forward(controls)); } - }(), ...); + }(), + ...); if (!status) { return modulus::fail>>(status.error()); } diff --git a/include/luma/detail/errors.hpp b/include/luma/detail/errors.hpp index 5191419..cbb327a 100644 --- a/include/luma/detail/errors.hpp +++ b/include/luma/detail/errors.hpp @@ -7,6 +7,7 @@ #include + namespace luma::detail { constexpr std::int32_t error_invalid_argument{1}; diff --git a/include/luma/geometry.hpp b/include/luma/geometry.hpp index d0fe2f0..374139c 100644 --- a/include/luma/geometry.hpp +++ b/include/luma/geometry.hpp @@ -5,6 +5,7 @@ #include + namespace luma { struct point { diff --git a/include/luma/input.hpp b/include/luma/input.hpp index 9a3e46d..58265f5 100644 --- a/include/luma/input.hpp +++ b/include/luma/input.hpp @@ -6,6 +6,7 @@ #include + namespace luma { enum class touch_phase { diff --git a/include/luma/overlays.hpp b/include/luma/overlays.hpp index a1afa25..bd7bdda 100644 --- a/include/luma/overlays.hpp +++ b/include/luma/overlays.hpp @@ -14,6 +14,7 @@ #include + namespace luma { enum class dialog_result { @@ -41,10 +42,10 @@ public: auto close_dialog(luma::dialog_result result) -> std::expected; auto show_toast(luma::toast toast) -> std::expected; auto tick(std::chrono::steady_clock::duration delta) -> std::bool_t; - auto measure(luma::draw_context& context, luma::theme const& theme, luma::constraints limits) -> luma::size override; + auto measure(luma::draw_context &context, luma::theme const &theme, luma::constraints limits) -> luma::size override; auto arrange(luma::rect bounds) -> void override; - auto draw(luma::draw_context& context, luma::theme const& theme) const -> void override; - auto handle_touch(luma::touch_event const& event) -> std::bool_t override; + auto draw(luma::draw_context &context, luma::theme const &theme) const -> void override; + auto handle_touch(luma::touch_event const &event) -> std::bool_t override; auto invalidate_layout() -> void override; auto bind_layout_invalidator(std::function invalidator) -> void override; private: diff --git a/include/luma/render.hpp b/include/luma/render.hpp index 8203443..e70cb30 100644 --- a/include/luma/render.hpp +++ b/include/luma/render.hpp @@ -8,6 +8,7 @@ #include #include + namespace luma { struct texture_info { @@ -29,11 +30,11 @@ public: virtual auto stroke_line(luma::point from, luma::point to, std::float32_t thickness, luma::color color) -> void = 0; virtual auto fill_ellipse(luma::rect bounds, luma::color color) -> void = 0; virtual auto stroke_ellipse(luma::rect bounds, std::float32_t thickness, luma::color color) -> void = 0; - virtual auto draw_text(std::string_view text, luma::point origin, luma::text_style const& style, luma::color color) -> void = 0; - virtual auto draw_texture(luma::texture const& texture, luma::rect source, luma::rect destination, luma::color tint) -> void = 0; + virtual auto draw_text(std::string_view text, luma::point origin, luma::text_style const &style, luma::color color) -> void = 0; + virtual auto draw_texture(luma::texture const &texture, luma::rect source, luma::rect destination, luma::color tint) -> void = 0; virtual auto push_clip(luma::rect bounds) -> void = 0; virtual auto pop_clip() -> void = 0; - virtual auto measure_text(std::string_view text, luma::text_style const& style) const -> luma::size = 0; + virtual auto measure_text(std::string_view text, luma::text_style const &style) const -> luma::size = 0; }; } diff --git a/include/luma/routing.hpp b/include/luma/routing.hpp index 9bfc625..db485f6 100644 --- a/include/luma/routing.hpp +++ b/include/luma/routing.hpp @@ -11,19 +11,20 @@ #include + namespace luma { class router { public: auto register_route(std::string name, std::function, modulus::error>()> factory) -> std::expected; auto set_retire_handler(std::function)> handler) -> void; - auto replace(std::string const& name) -> std::expected; - auto push(std::string const& name) -> std::expected; + auto replace(std::string const &name) -> std::expected; + auto push(std::string const &name) -> std::expected; auto pop() -> std::expected; auto clear_stack() -> void; - auto current() -> luma::control*; - auto current() const -> luma::control const*; - auto current_route() const -> std::string const&; + auto current() -> luma::control *; + auto current() const -> luma::control const *; + auto current_route() const -> std::string const &; private: struct entry { std::string name{}; diff --git a/include/luma/theme.hpp b/include/luma/theme.hpp index eb10fe7..23b118e 100644 --- a/include/luma/theme.hpp +++ b/include/luma/theme.hpp @@ -8,6 +8,7 @@ #include + namespace luma { struct color { @@ -38,12 +39,12 @@ struct theme { }; auto default_theme() -> luma::theme; -auto validate(luma::text_style const& style) -> std::expected; -auto validate(luma::theme const& theme) -> std::expected; -auto parse_color(boost::json::value const& value) -> std::expected; -auto parse_theme(boost::json::value const& value) -> std::expected; -auto to_json(luma::color const& color) -> boost::json::value; -auto to_json(luma::text_style const& style) -> boost::json::value; -auto to_json(luma::theme const& theme) -> boost::json::value; +auto validate(luma::text_style const &style) -> std::expected; +auto validate(luma::theme const &theme) -> std::expected; +auto parse_color(boost::json::value const &value) -> std::expected; +auto parse_theme(boost::json::value const &value) -> std::expected; +auto to_json(luma::color const &color) -> boost::json::value; +auto to_json(luma::text_style const &style) -> boost::json::value; +auto to_json(luma::theme const &theme) -> boost::json::value; } diff --git a/include/luma/window.hpp b/include/luma/window.hpp index b6b0dac..dde03c9 100644 --- a/include/luma/window.hpp +++ b/include/luma/window.hpp @@ -13,6 +13,7 @@ #include #include + namespace luma { class window_manager; @@ -27,17 +28,17 @@ struct window_options { class window { public: - window(luma::window const&) = delete; - window(luma::window&&) noexcept = default; - auto operator=(luma::window const&) -> luma::window& = delete; - auto operator=(luma::window&&) noexcept -> luma::window& = default; + window(luma::window const &) = delete; + window(luma::window &&) noexcept = default; + auto operator=(luma::window const &) -> luma::window & = delete; + auto operator=(luma::window &&) noexcept -> luma::window & = default; auto id() const -> std::uint64_t; - auto options() const -> luma::window_options const&; + auto options() const -> luma::window_options const &; auto set_bounds(luma::rect bounds) -> std::expected; auto set_visible(std::bool_t value) -> void; auto visible() const -> std::bool_t; - auto content() -> luma::control*; - auto content() const -> luma::control const*; + auto content() -> luma::control *; + auto content() const -> luma::control const *; private: friend class luma::window_manager; window(std::uint64_t id, luma::window_options options, std::unique_ptr content); @@ -53,12 +54,12 @@ public: auto bring_to_front(std::uint64_t id) -> std::expected; auto set_bounds(std::uint64_t id, luma::rect bounds) -> std::expected; auto set_visible(std::uint64_t id, std::bool_t visible) -> std::expected; - auto find(std::uint64_t id) -> luma::window*; + auto find(std::uint64_t id) -> luma::window *; auto clear() -> void; - auto measure(luma::draw_context& context, luma::theme const& theme, luma::constraints limits) -> luma::size override; + auto measure(luma::draw_context &context, luma::theme const &theme, luma::constraints limits) -> luma::size override; auto arrange(luma::rect bounds) -> void override; - auto draw(luma::draw_context& context, luma::theme const& theme) const -> void override; - auto handle_touch(luma::touch_event const& event) -> std::bool_t override; + auto draw(luma::draw_context &context, luma::theme const &theme) const -> void override; + auto handle_touch(luma::touch_event const &event) -> std::bool_t override; auto invalidate_layout() -> void override; auto bind_layout_invalidator(std::function invalidator) -> void override; private: diff --git a/modulus.py b/modulus.py index b27d44c..1b69392 100755 --- a/modulus.py +++ b/modulus.py @@ -16,6 +16,7 @@ COMMANDS = ( "package", "lsp", "clangd", + "format", ) COMMON_DIR = pathlib.Path("build") / "build_common" TOOLS_DIR = pathlib.Path("build") / "build_tools" @@ -60,6 +61,9 @@ def runtime_ready(root): and (root / TOOLS_DIR / "clangd.py").is_file() and (root / RUNTIME_DIR / "modulus" / "cli.py").is_file() and (root / RUNTIME_DIR / "modulus" / "export.py").is_file() + and (root / TOOLS_DIR / "format.py").is_file() + and (root / RUNTIME_DIR / "modulus" / "formatting.py").is_file() + and (root / RUNTIME_DIR / "modulus" / "format_layout.py").is_file() ) def optional_credentials(): @@ -340,9 +344,9 @@ def ensure_runtime(root): def delegate(command, argv): root = repo_root() - if command == "clangd": + if command in {"clangd", "format"}: if not runtime_ready(root): - print("Modulus clangd tooling is missing; run ./modulus.py configure first", file=sys.stderr) + print(f"Modulus {command} tooling is missing; run ./modulus.py configure first", file=sys.stderr) return 1 else: ensure_runtime(root) diff --git a/src/animation.cpp b/src/animation.cpp index 39f4f65..23e99ad 100644 --- a/src/animation.cpp +++ b/src/animation.cpp @@ -11,6 +11,7 @@ #include + namespace { auto invalid(std::string message) -> std::expected { @@ -26,7 +27,7 @@ auto internal(std::string message) -> std::expected { return luma::detail::fail(luma::detail::error_internal, std::move(message)); } -auto validate(luma::animation const& animation) -> std::expected { +auto validate(luma::animation const &animation) -> std::expected { if (!std::isfinite(animation.from)) { return invalid("animation from value must be finite"); } @@ -42,11 +43,11 @@ auto validate(luma::animation const& animation) -> std::expected std::expected { +auto callback_error(std::char_t const *action, std::exception const &error) -> std::expected { return internal(std::string{"animation "} + action + " callback failed: " + error.what()); } -auto callback_error(std::char_t const* action) -> std::expected { +auto callback_error(std::char_t const *action) -> std::expected { return internal(std::string{"animation "} + action + " callback failed with an unknown exception"); } @@ -104,12 +105,10 @@ auto luma::animation_graph::tick(std::chrono::steady_clock::duration delta) -> s if (ticking_) { return internal("animation graph is already ticking"); } - auto active = std::move(animations_); animations_.clear(); ticking_ = true; clear_requested_ = false; - auto fail_tick = [this](std::expected status) { ticking_ = false; clear_requested_ = false; @@ -117,8 +116,7 @@ auto luma::animation_graph::tick(std::chrono::steady_clock::duration delta) -> s pending_.clear(); return status; }; - - for (auto& running : active) { + for (auto &running : active) { running.elapsed += delta; auto duration = std::chrono::duration_cast(running.animation.duration); if (duration.count() <= 0) { @@ -135,7 +133,7 @@ auto luma::animation_graph::tick(std::chrono::steady_clock::duration delta) -> s } try { running.animation.apply(*interpolated); - } catch (std::exception const& error) { + } catch (std::exception const &error) { return fail_tick(callback_error("apply", error)); } catch (...) { return fail_tick(callback_error("apply")); @@ -147,7 +145,7 @@ auto luma::animation_graph::tick(std::chrono::steady_clock::duration delta) -> s if (running.animation.finished) { try { running.animation.finished(); - } catch (std::exception const& error) { + } catch (std::exception const &error) { return fail_tick(callback_error("finished", error)); } catch (...) { return fail_tick(callback_error("finished")); @@ -160,9 +158,8 @@ auto luma::animation_graph::tick(std::chrono::steady_clock::duration delta) -> s } animations_.push_back(std::move(running)); } - ticking_ = false; - for (auto& operation : pending_) { + for (auto &operation : pending_) { if (operation.kind == luma::animation_graph::pending_kind::CLEAR) { animations_.clear(); } else { diff --git a/src/application.cpp b/src/application.cpp index f4eca45..9494a4b 100644 --- a/src/application.cpp +++ b/src/application.cpp @@ -38,6 +38,7 @@ #include #include + namespace luma::detail { struct application_core { @@ -59,7 +60,7 @@ struct application_core { luma::window_manager windows{}; std::unique_ptr assets{}; std::unique_ptr resources{}; - luma::overlay_host* overlays{}; + luma::overlay_host *overlays{}; std::atomic_bool layout_dirty{true}; std::atomic_bool redraw_dirty{true}; std::bool_t layout_ready{false}; @@ -75,12 +76,11 @@ namespace { struct font_key { std::string path{}; std::int32_t size{}; - - auto operator==(font_key const& other) const -> std::bool_t; + auto operator==(font_key const &other) const -> std::bool_t; }; struct font_key_hash { - auto operator()(font_key const& key) const noexcept -> std::size_t; + auto operator()(font_key const &key) const noexcept -> std::size_t; }; struct raylib_resource_state { @@ -111,7 +111,7 @@ private: class raylib_resources final : public luma::renderer_resources { public: explicit raylib_resources(std::shared_ptr state); - auto load_texture(std::string const& path) -> std::expected, modulus::error> override; + auto load_texture(std::string const &path) -> std::expected, modulus::error> override; auto state() const -> std::shared_ptr; private: std::shared_ptr state_{}; @@ -125,11 +125,11 @@ public: auto stroke_line(luma::point from, luma::point to, std::float32_t thickness, luma::color color) -> void override; auto fill_ellipse(luma::rect bounds, luma::color color) -> void override; auto stroke_ellipse(luma::rect bounds, std::float32_t thickness, luma::color color) -> void override; - auto draw_text(std::string_view text, luma::point origin, luma::text_style const& style, luma::color color) -> void override; - auto draw_texture(luma::texture const& texture, luma::rect source, luma::rect destination, luma::color tint) -> void override; + auto draw_text(std::string_view text, luma::point origin, luma::text_style const &style, luma::color color) -> void override; + auto draw_texture(luma::texture const &texture, luma::rect source, luma::rect destination, luma::color tint) -> void override; auto push_clip(luma::rect bounds) -> void override; auto pop_clip() -> void override; - auto measure_text(std::string_view text, luma::text_style const& style) const -> luma::size override; + auto measure_text(std::string_view text, luma::text_style const &style) const -> luma::size override; private: std::shared_ptr state_{}; std::vector clip_stack_{}; @@ -138,8 +138,8 @@ private: class scope_exit { public: explicit scope_exit(std::function 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 action_{}; @@ -149,8 +149,8 @@ private: class drawing_scope { public: drawing_scope(); - drawing_scope(drawing_scope const&) = delete; - auto operator=(drawing_scope const&) -> drawing_scope& = delete; + drawing_scope(drawing_scope const &) = delete; + auto operator=(drawing_scope const &) -> drawing_scope & = delete; ~drawing_scope(); auto end() -> void; private: @@ -159,12 +159,12 @@ private: class ui_traversal_scope { public: - explicit ui_traversal_scope(luma::detail::application_core& core); - ui_traversal_scope(ui_traversal_scope const&) = delete; - auto operator=(ui_traversal_scope const&) -> ui_traversal_scope& = delete; + explicit ui_traversal_scope(luma::detail::application_core &core); + ui_traversal_scope(ui_traversal_scope const &) = delete; + auto operator=(ui_traversal_scope const &) -> ui_traversal_scope & = delete; ~ui_traversal_scope(); private: - luma::detail::application_core& core_; + luma::detail::application_core &core_; }; constexpr auto max_layout_passes = std::uint32_t{8}; @@ -200,25 +200,25 @@ auto same_rect(luma::rect left, luma::rect right) -> std::bool_t { return left.x == right.x && left.y == right.y && left.width == right.width && left.height == right.height; } -auto make_event(luma::touch_event const& event, luma::touch_point point) -> luma::touch_event { +auto make_event(luma::touch_event const &event, luma::touch_point point) -> luma::touch_event { return { .points = {point}, .time = event.time, }; } -auto invalidate_layout_cache(luma::detail::application_core& core) -> void; +auto invalidate_layout_cache(luma::detail::application_core &core) -> void; -auto mark_redraw_dirty(luma::detail::application_core& core) -> void { +auto mark_redraw_dirty(luma::detail::application_core &core) -> void { core.redraw_dirty.store(true, std::memory_order_release); } -auto mark_layout_dirty(luma::detail::application_core& core) -> void { +auto mark_layout_dirty(luma::detail::application_core &core) -> void { core.layout_dirty.store(true, std::memory_order_release); mark_redraw_dirty(core); } -auto make_layout_invalidator(std::shared_ptr const& core) -> std::function { +auto make_layout_invalidator(std::shared_ptr const &core) -> std::function { auto weak = std::weak_ptr{core}; return [weak] { if (auto locked = weak.lock()) { @@ -227,17 +227,17 @@ auto make_layout_invalidator(std::shared_ptr con }; } -auto bind_layout_invalidator(std::shared_ptr const& core, luma::control& control) -> void { +auto bind_layout_invalidator(std::shared_ptr const &core, luma::control &control) -> void { control.bind_layout_invalidator(make_layout_invalidator(core)); } -auto flush_retired_controls(luma::detail::application_core& core) -> void { +auto flush_retired_controls(luma::detail::application_core &core) -> void { if (core.traversal_depth == 0) { core.retired_controls.clear(); } } -auto retire_control(luma::detail::application_core& core, std::unique_ptr control) -> void { +auto retire_control(luma::detail::application_core &core, std::unique_ptr control) -> void { if (control == nullptr) { return; } @@ -248,7 +248,7 @@ auto retire_control(luma::detail::application_core& core, std::unique_ptr const& core) -> void { +auto install_retire_handlers(std::shared_ptr const &core) -> void { auto weak = std::weak_ptr{core}; core->router.set_retire_handler([weak](std::unique_ptr control) mutable { if (auto locked = weak.lock()) { @@ -257,27 +257,27 @@ auto install_retire_handlers(std::shared_ptr con }); } -auto active_control(luma::detail::application_core& core) -> luma::control* { - auto* active = core.root.get(); +auto active_control(luma::detail::application_core &core) -> luma::control * { + auto *active = core.root.get(); if (active == nullptr) { active = core.router.current(); } return active; } -auto invalidate_layout_cache(luma::detail::application_core& core) -> void { +auto invalidate_layout_cache(luma::detail::application_core &core) -> void { auto traversal = ui_traversal_scope{core}; - if (auto* active = active_control(core); active != nullptr) { + if (auto *active = active_control(core); active != nullptr) { active->invalidate_layout(); } core.windows.invalidate_layout(); } template -auto run_task(TASK& task) -> std::expected { +auto run_task(TASK &task) -> std::expected { try { return task(); - } catch (std::exception const& error) { + } catch (std::exception const &error) { return internal(error.what()); } catch (...) { return internal("UI task failed with an unknown exception"); @@ -285,7 +285,7 @@ auto run_task(TASK& task) -> std::expected { } template -auto run_ui_task(luma::detail::application_core& core, TASK& task, std::bool_t dirty_after) -> std::expected { +auto run_ui_task(luma::detail::application_core &core, TASK &task, std::bool_t dirty_after) -> std::expected { auto result = run_task(task); if (dirty_after) { mark_layout_dirty(core); @@ -294,15 +294,13 @@ auto run_ui_task(luma::detail::application_core& core, TASK& task, std::bool_t d } template -auto dispatch_to_ui(std::shared_ptr const& core, TASK&& input, std::bool_t dirty_after = true) -> std::expected { +auto dispatch_to_ui(std::shared_ptr const &core, TASK &&input, std::bool_t dirty_after = true) -> std::expected { if (!core) { return unavailable("application is not initialized"); } - auto task = std::decay_t{std::forward(input)}; auto should_post = false; auto wait_for_startup = false; - { auto lock = std::unique_lock{core->lifecycle_mutex}; if (core->stopping.load(std::memory_order_acquire)) { @@ -317,7 +315,6 @@ auto dispatch_to_ui(std::shared_ptr const& core, should_post = running && accepting; wait_for_startup = running && !accepting; } - if (!should_post || wait_for_startup) { auto immediate_lock = std::scoped_lock{core->immediate_mutex}; auto lock = std::unique_lock{core->lifecycle_mutex}; @@ -337,7 +334,6 @@ auto dispatch_to_ui(std::shared_ptr const& core, } should_post = true; } - auto future = std::future>{}; auto promise = std::make_shared>>(); future = promise->get_future(); @@ -359,21 +355,20 @@ auto dispatch_to_ui(std::shared_ptr const& core, } promise->set_value(run_ui_task(*core, queued, dirty_after)); }); - } catch (std::exception const& error) { + } catch (std::exception const &error) { return internal(error.what()); } catch (...) { return internal("failed to queue UI task"); } - return future.get(); } -auto drain_ui_tasks(luma::detail::application_core& core) -> std::size_t { +auto drain_ui_tasks(luma::detail::application_core &core) -> std::size_t { core.ui_context.restart(); return core.ui_context.poll(); } -auto finish_run(luma::detail::application_core& core) -> void { +auto finish_run(luma::detail::application_core &core) -> void { auto lock = std::scoped_lock{core.lifecycle_mutex}; core.accepting_tasks.store(false, std::memory_order_release); core.running.store(false, std::memory_order_release); @@ -382,7 +377,7 @@ auto finish_run(luma::detail::application_core& core) -> void { core.stop_requested.store(false, std::memory_order_release); } -auto cleanup_ui_state(luma::detail::application_core& core) -> void { +auto cleanup_ui_state(luma::detail::application_core &core) -> void { if (core.assets) { core.assets->clear(); } @@ -398,7 +393,7 @@ auto cleanup_ui_state(luma::detail::application_core& core) -> void { mark_layout_dirty(core); } -auto unload_record(raylib_resource_state::texture_record& record) -> void { +auto unload_record(raylib_resource_state::texture_record &record) -> void { if (!record.unloaded && record.texture.id != 0) { UnloadTexture(record.texture); record.unloaded = true; @@ -406,7 +401,7 @@ auto unload_record(raylib_resource_state::texture_record& record) -> void { } } -auto flush_pending_unloads(raylib_resource_state& state) -> std::bool_t { +auto flush_pending_unloads(raylib_resource_state &state) -> std::bool_t { assert(state.ui_thread == std::this_thread::get_id()); auto pending = std::vector>{}; { @@ -414,7 +409,7 @@ auto flush_pending_unloads(raylib_resource_state& state) -> std::bool_t { pending.swap(state.pending_unloads); } auto unloaded = false; - for (auto& record : pending) { + for (auto &record : pending) { if (record) { unload_record(*record); unloaded = true; @@ -423,7 +418,7 @@ auto flush_pending_unloads(raylib_resource_state& state) -> std::bool_t { return unloaded; } -auto unload_all_textures(raylib_resource_state& state) -> void { +auto unload_all_textures(raylib_resource_state &state) -> void { assert(state.ui_thread == std::this_thread::get_id()); static_cast(flush_pending_unloads(state)); auto records = std::vector>{}; @@ -439,14 +434,14 @@ auto unload_all_textures(raylib_resource_state& state) -> void { } state.records.erase(write, state.records.end()); } - for (auto& record : records) { + for (auto &record : records) { unload_record(*record); } } -auto unload_all_fonts(raylib_resource_state& state) -> void { +auto unload_all_fonts(raylib_resource_state &state) -> void { assert(state.ui_thread == std::this_thread::get_id()); - for (auto& [path, font] : state.fonts) { + for (auto &[path, font] : state.fonts) { static_cast(path); if (font.texture.id != 0) { UnloadFont(font); @@ -455,7 +450,7 @@ auto unload_all_fonts(raylib_resource_state& state) -> void { state.fonts.clear(); } -auto resolve_font(raylib_resource_state& state, luma::text_style const& style) -> Font { +auto resolve_font(raylib_resource_state &state, luma::text_style const &style) -> Font { assert(state.ui_thread == std::this_thread::get_id()); assert(IsWindowReady()); if (style.font.empty()) { @@ -496,7 +491,7 @@ auto begin_clip(luma::rect bounds) -> void { BeginScissorMode(static_cast(bounds.x), static_cast(bounds.y), static_cast(bounds.width), static_cast(bounds.height)); } -auto poll_touch(std::unordered_map& previous, std::int32_t max_points) -> luma::touch_event { +auto poll_touch(std::unordered_map &previous, std::int32_t max_points) -> luma::touch_event { assert(IsWindowReady()); assert(max_points > 0); auto current = std::unordered_map{}; @@ -517,7 +512,7 @@ auto poll_touch(std::unordered_map& previous, std::in .phase = phase, }); } - for (auto const& [id, position] : previous) { + for (auto const &[id, position] : previous) { if (!current.contains(id)) { points.push_back({ .id = id, @@ -533,17 +528,18 @@ auto poll_touch(std::unordered_map& previous, std::in }; } -auto font_key::operator==(font_key const& other) const -> std::bool_t { +auto font_key::operator==(font_key const &other) const -> std::bool_t { return path == other.path && size == other.size; } -auto font_key_hash::operator()(font_key const& key) const noexcept -> std::size_t { +auto font_key_hash::operator()(font_key const &key) const noexcept -> std::size_t { auto seed = std::hash{}(key.path); seed ^= std::hash{}(key.size) + 0x9e3779b9U + (seed << 6U) + (seed >> 2U); return seed; } -scope_exit::scope_exit(std::function action) : action_{std::move(action)} {} +scope_exit::scope_exit(std::function action) + : action_{std::move(action)} {} scope_exit::~scope_exit() { if (!active_ || !action_) { @@ -576,7 +572,8 @@ auto drawing_scope::end() -> void { } } -ui_traversal_scope::ui_traversal_scope(luma::detail::application_core& core) : core_{core} { +ui_traversal_scope::ui_traversal_scope(luma::detail::application_core &core) + : core_{core} { ++core_.traversal_depth; } @@ -586,7 +583,8 @@ ui_traversal_scope::~ui_traversal_scope() { flush_retired_controls(core_); } -raylib_texture::raylib_texture(std::shared_ptr record, std::shared_ptr state) : record_{std::move(record)}, state_{std::move(state)} { +raylib_texture::raylib_texture(std::shared_ptr record, std::shared_ptr state) + : record_{std::move(record)}, state_{std::move(state)} { assert(record_ != nullptr); assert(record_->texture.id != 0); assert(record_->texture.width > 0); @@ -623,11 +621,12 @@ auto raylib_texture::native() const -> Texture2D { return record_->texture; } -raylib_resources::raylib_resources(std::shared_ptr state) : state_{std::move(state)} { +raylib_resources::raylib_resources(std::shared_ptr state) + : state_{std::move(state)} { assert(state_ != nullptr); } -auto raylib_resources::load_texture(std::string const& path) -> std::expected, modulus::error> { +auto raylib_resources::load_texture(std::string const &path) -> std::expected, modulus::error> { assert(state_ != nullptr); assert(state_->active.load(std::memory_order_acquire)); assert(state_->ui_thread == std::this_thread::get_id()); @@ -652,29 +651,32 @@ auto raylib_resources::state() const -> std::shared_ptr { return state_; } -raylib_draw_context::raylib_draw_context(std::shared_ptr state) : state_{std::move(state)} { +raylib_draw_context::raylib_draw_context(std::shared_ptr state) + : state_{std::move(state)} { assert(state_ != nullptr); } auto raylib_draw_context::fill_rect(luma::rect bounds, luma::color color) -> void { assert(IsWindowReady()); DrawRectangleRec({ - .x = bounds.x, - .y = bounds.y, - .width = bounds.width, - .height = bounds.height, - }, to_raylib(color)); + .x = bounds.x, + .y = bounds.y, + .width = bounds.width, + .height = bounds.height, + }, + to_raylib(color)); } auto raylib_draw_context::stroke_rect(luma::rect bounds, std::float32_t thickness, luma::color color) -> void { assert(IsWindowReady()); assert(thickness >= 0.0F); DrawRectangleLinesEx({ - .x = bounds.x, - .y = bounds.y, - .width = bounds.width, - .height = bounds.height, - }, thickness, to_raylib(color)); + .x = bounds.x, + .y = bounds.y, + .width = bounds.width, + .height = bounds.height, + }, + thickness, to_raylib(color)); } auto raylib_draw_context::stroke_line(luma::point from, luma::point to, std::float32_t thickness, luma::color color) -> void { @@ -719,21 +721,22 @@ auto raylib_draw_context::stroke_ellipse(luma::rect bounds, std::float32_t thick } } -auto raylib_draw_context::draw_text(std::string_view text, luma::point origin, luma::text_style const& style, luma::color color) -> void { +auto raylib_draw_context::draw_text(std::string_view text, luma::point origin, luma::text_style const &style, luma::color color) -> void { assert(IsWindowReady()); assert(state_ != nullptr); assert(style.size > 0.0F); auto owned = std::string{text}; auto font = resolve_font(*state_, style); DrawTextEx(font, owned.c_str(), { - .x = origin.x, - .y = origin.y, - }, style.size, 1.0F, to_raylib(color)); + .x = origin.x, + .y = origin.y, + }, + style.size, 1.0F, to_raylib(color)); } -auto raylib_draw_context::draw_texture(luma::texture const& texture, luma::rect source, luma::rect destination, luma::color tint) -> void { +auto raylib_draw_context::draw_texture(luma::texture const &texture, luma::rect source, luma::rect destination, luma::color tint) -> void { assert(IsWindowReady()); - auto const* native = dynamic_cast(&texture); + auto const *native = dynamic_cast(&texture); if (native == nullptr || !native->valid()) { return; } @@ -776,7 +779,7 @@ auto raylib_draw_context::pop_clip() -> void { } } -auto raylib_draw_context::measure_text(std::string_view text, luma::text_style const& style) const -> luma::size { +auto raylib_draw_context::measure_text(std::string_view text, luma::text_style const &style) const -> luma::size { assert(IsWindowReady()); assert(state_ != nullptr); assert(style.size > 0.0F); @@ -791,15 +794,17 @@ auto raylib_draw_context::measure_text(std::string_view text, luma::text_style c } -luma::detail::application_core::application_core(luma::application_config value) : ui_strand{boost::asio::make_strand(ui_context)}, config{std::move(value)} {} +luma::detail::application_core::application_core(luma::application_config value) + : ui_strand{boost::asio::make_strand(ui_context)}, config{std::move(value)} {} -luma::application::application(luma::application_config config) : core_{std::make_shared(std::move(config))} { +luma::application::application(luma::application_config config) + : core_{std::make_shared(std::move(config))} { assert(core_ != nullptr); install_retire_handlers(core_); core_->windows.bind_layout_invalidator(make_layout_invalidator(core_)); } -luma::application::application(luma::application&& other) noexcept { +luma::application::application(luma::application &&other) noexcept { auto lock = std::scoped_lock{other.core_mutex_}; core_ = std::move(other.core_); } @@ -808,7 +813,7 @@ luma::application::~application() { request_stop(); } -auto luma::application::operator=(luma::application&& other) noexcept -> luma::application& { +auto luma::application::operator=(luma::application &&other) noexcept -> luma::application & { if (this != &other) { request_stop(); auto lock = std::scoped_lock{ @@ -851,7 +856,7 @@ auto luma::application::replace_route(std::string name) -> std::expected(core, [core, name = std::move(name)] { auto status = core->router.replace(name); if (status) { - if (auto* current = core->router.current(); current != nullptr) { + if (auto *current = core->router.current(); current != nullptr) { bind_layout_invalidator(core, *current); } } @@ -865,7 +870,7 @@ auto luma::application::push_route(std::string name) -> std::expected(core, [core, name = std::move(name)] { auto status = core->router.push(name); if (status) { - if (auto* current = core->router.current(); current != nullptr) { + if (auto *current = core->router.current(); current != nullptr) { bind_layout_invalidator(core, *current); } } @@ -878,7 +883,7 @@ auto luma::application::pop_route() -> std::expected { return dispatch_to_ui(core, [core] { auto status = core->router.pop(); if (status) { - if (auto* current = core->router.current(); current != nullptr) { + if (auto *current = core->router.current(); current != nullptr) { bind_layout_invalidator(core, *current); } } @@ -888,9 +893,7 @@ auto luma::application::pop_route() -> std::expected { auto luma::application::current_route() const -> std::expected { auto core = core_snapshot(); - return dispatch_to_ui(core, [core] { - return modulus::success(std::string{core->router.current_route()}); - }, false); + return dispatch_to_ui(core, [core] { return modulus::success(std::string{core->router.current_route()}); }, false); } auto luma::application::add_animation(luma::animation animation) -> std::expected { @@ -910,9 +913,7 @@ auto luma::application::clear_animations() -> std::expected std::expected { auto core = core_snapshot(); - return dispatch_to_ui(core, [core] { - return modulus::success(core->animations.empty()); - }, false); + return dispatch_to_ui(core, [core] { return modulus::success(core->animations.empty()); }, false); } auto luma::application::open_window(luma::window_options options, std::unique_ptr content) -> std::expected { @@ -981,8 +982,7 @@ auto luma::application::load_texture(std::string path) -> std::expectedrenderer_active.load(std::memory_order_acquire) || !core->assets) { return unavailable>("texture loading requires an active renderer"); } - return core->assets->texture(path); - }, false); + return core->assets->texture(path); }, false); } auto luma::application::request_layout() -> std::expected { @@ -1100,7 +1100,6 @@ auto luma::application::run() -> std::expected { core->running.store(true, std::memory_order_release); core->accepting_tasks.store(false, std::memory_order_release); } - auto resource_state = std::shared_ptr{}; auto window_ready = false; [[maybe_unused]] auto cleanup = scope_exit{[&core, &resource_state, &window_ready] { @@ -1123,7 +1122,6 @@ auto luma::application::run() -> std::expected { } finish_run(*core); }}; - InitWindow(core->config.display.width, core->config.display.height, core->config.title.c_str()); if (!IsWindowReady()) { return unavailable("failed to initialize raylib window"); @@ -1135,7 +1133,6 @@ auto luma::application::run() -> std::expected { auto current_target_fps = core->config.display.target_fps; auto const idle_fps = core->config.display.idle_fps; SetTargetFPS(current_target_fps); - resource_state = std::make_shared(); resource_state->ui_thread = std::this_thread::get_id(); resource_state->active.store(true, std::memory_order_release); @@ -1147,7 +1144,6 @@ auto luma::application::run() -> std::expected { core->accepting_tasks.store(true, std::memory_order_release); } startup_lock.unlock(); - auto context = raylib_draw_context{resource_state}; auto previous_touches = std::unordered_map{}; auto previous_frame = std::chrono::steady_clock::now(); @@ -1181,13 +1177,13 @@ auto luma::application::run() -> std::expected { } auto touch_requires_layout = false; if (!event.points.empty()) { - for (auto const& point : event.points) { + for (auto const &point : event.points) { auto single = make_event(event, point); if (core->windows.handle_touch(single)) { touch_requires_layout = touch_requires_layout || point.phase != luma::touch_phase::MOVE; continue; } - auto* active = active_control(*core); + auto *active = active_control(*core); if (active != nullptr && active->handle_touch(single)) { touch_requires_layout = touch_requires_layout || point.phase != luma::touch_phase::MOVE; } @@ -1223,7 +1219,7 @@ auto luma::application::run() -> std::expected { if (pass > max_layout_passes) { return modulus::fail(internal_error("application layout did not stabilize")); } - auto* active = active_control(*core); + auto *active = active_control(*core); if (active != nullptr) { active->measure(context, core->config.theme, limits); active->arrange(display); @@ -1244,7 +1240,7 @@ auto luma::application::run() -> std::expected { if (should_draw) { auto drawing = drawing_scope{}; ClearBackground(to_raylib(core->config.theme.background)); - auto* active = active_control(*core); + auto *active = active_control(*core); if (active != nullptr) { active->draw(context, core->config.theme); } @@ -1255,7 +1251,7 @@ auto luma::application::run() -> std::expected { PollInputEvents(); } } - } catch (std::exception const& error) { + } catch (std::exception const &error) { return modulus::fail(internal_error(std::string{"application frame failed: "} + error.what())); } catch (...) { return modulus::fail(internal_error("application frame failed with an unknown exception")); diff --git a/src/assets.cpp b/src/assets.cpp index f0396a3..50aaabf 100644 --- a/src/assets.cpp +++ b/src/assets.cpp @@ -16,6 +16,7 @@ #include + struct luma::asset_cache::in_flight_load { std::condition_variable ready{}; std::thread::id owner{}; @@ -23,11 +24,12 @@ struct luma::asset_cache::in_flight_load { std::bool_t done{false}; }; -luma::asset_cache::asset_cache(luma::renderer_resources& resources) : resources_{&resources} { +luma::asset_cache::asset_cache(luma::renderer_resources &resources) + : resources_{&resources} { assert(resources_ != nullptr); } -auto luma::asset_cache::texture(std::string const& path) -> std::expected, modulus::error> { +auto luma::asset_cache::texture(std::string const &path) -> std::expected, modulus::error> { assert(resources_ != nullptr); if (path.empty()) { return luma::detail::fail>(luma::detail::error_invalid_argument, "texture path must not be empty"); @@ -68,7 +70,7 @@ auto luma::asset_cache::texture(std::string const& path) -> std::expectedload_texture(path); - } catch (std::exception const& error) { + } catch (std::exception const &error) { loaded = luma::detail::fail>(luma::detail::error_internal, std::string{"texture load failed: "} + error.what()); } catch (...) { loaded = luma::detail::fail>(luma::detail::error_internal, "texture load failed with an unknown exception"); diff --git a/src/config.cpp b/src/config.cpp index e26e7db..6a3b9a4 100644 --- a/src/config.cpp +++ b/src/config.cpp @@ -15,13 +15,13 @@ #include #include + namespace { constexpr auto json_options = modulus::json_config::options{ .category = "luma", .invalid_argument_code = luma::detail::error_invalid_argument, - .not_found_code = luma::detail::error_not_found -}; + .not_found_code = luma::detail::error_not_found}; auto invalid_display(std::string message) -> std::expected { assert(!message.empty()); @@ -40,7 +40,7 @@ auto invalid_application(std::string message) -> std::expected std::expected { +auto luma::validate(luma::display_config const &config) -> std::expected { if (config.width <= 0) { return luma::detail::fail(luma::detail::error_invalid_argument, "display.width must be positive"); } @@ -59,14 +59,14 @@ auto luma::validate(luma::display_config const& config) -> std::expected std::expected { +auto luma::validate(luma::touch_config const &config) -> std::expected { if (config.max_points <= 0) { return luma::detail::fail(luma::detail::error_invalid_argument, "touch.max_points must be positive"); } return {}; } -auto luma::validate(luma::application_config const& config) -> std::expected { +auto luma::validate(luma::application_config const &config) -> std::expected { if (config.title.empty()) { return luma::detail::fail(luma::detail::error_invalid_argument, "title must not be empty"); } @@ -82,18 +82,19 @@ auto luma::validate(luma::application_config const& config) -> std::expected std::expected { +auto luma::parse_display_config(boost::json::value const &value) -> std::expected { auto object = modulus::json_config::require_object(value, "display", json_options); if (!object) { return invalid_display(std::string{object.error().message()}); } auto unknown = modulus::json_config::reject_unknown_fields(**object, { - "width", - "height", - "target_fps", - "idle_fps", - "fullscreen", - }, "display", json_options); + "width", + "height", + "target_fps", + "idle_fps", + "fullscreen", + }, + "display", json_options); if (!unknown) { return invalid_display(std::string{unknown.error().message()}); } @@ -129,7 +130,7 @@ auto luma::parse_display_config(boost::json::value const& value) -> std::expecte return modulus::success(config); } -auto luma::parse_touch_config(boost::json::value const& value) -> std::expected { +auto luma::parse_touch_config(boost::json::value const &value) -> std::expected { auto object = modulus::json_config::require_object(value, "touch", json_options); if (!object) { return invalid_touch(std::string{object.error().message()}); @@ -150,17 +151,18 @@ auto luma::parse_touch_config(boost::json::value const& value) -> std::expected< return modulus::success(config); } -auto luma::parse_application_config(boost::json::value const& value) -> std::expected { +auto luma::parse_application_config(boost::json::value const &value) -> std::expected { auto object = modulus::json_config::require_object(value, "application config", json_options); if (!object) { return invalid_application(std::string{object.error().message()}); } auto unknown = modulus::json_config::reject_unknown_fields(**object, { - "title", - "display", - "touch", - "theme", - }, "application config", json_options); + "title", + "display", + "touch", + "theme", + }, + "application config", json_options); if (!unknown) { return invalid_application(std::string{unknown.error().message()}); } @@ -170,21 +172,21 @@ auto luma::parse_application_config(boost::json::value const& value) -> std::exp return invalid_application(std::string{title.error().message()}); } config.title = *title; - if (auto const* display = (*object)->if_contains("display")) { + if (auto const *display = (*object)->if_contains("display")) { auto parsed = luma::parse_display_config(*display); if (!parsed) { return invalid_application(std::string{parsed.error().message()}); } config.display = *parsed; } - if (auto const* touch = (*object)->if_contains("touch")) { + if (auto const *touch = (*object)->if_contains("touch")) { auto parsed = luma::parse_touch_config(*touch); if (!parsed) { return invalid_application(std::string{parsed.error().message()}); } config.touch = *parsed; } - if (auto const* theme = (*object)->if_contains("theme")) { + if (auto const *theme = (*object)->if_contains("theme")) { auto parsed = luma::parse_theme(*theme); if (!parsed) { return invalid_application(std::string{parsed.error().message()}); @@ -197,7 +199,7 @@ auto luma::parse_application_config(boost::json::value const& value) -> std::exp return modulus::success(config); } -auto luma::load_application_config(std::string const& path) -> std::expected { +auto luma::load_application_config(std::string const &path) -> std::expected { auto value = modulus::json_config::load_value(path, json_options); if (!value) { return modulus::fail(value.error()); @@ -205,7 +207,7 @@ auto luma::load_application_config(std::string const& path) -> std::expected boost::json::value { +auto luma::to_json(luma::display_config const &config) -> boost::json::value { return boost::json::object{ { "width", @@ -230,7 +232,7 @@ auto luma::to_json(luma::display_config const& config) -> boost::json::value { }; } -auto luma::to_json(luma::touch_config const& config) -> boost::json::value { +auto luma::to_json(luma::touch_config const &config) -> boost::json::value { return boost::json::object{ { "max_points", @@ -239,7 +241,7 @@ auto luma::to_json(luma::touch_config const& config) -> boost::json::value { }; } -auto luma::to_json(luma::application_config const& config) -> boost::json::value { +auto luma::to_json(luma::application_config const &config) -> boost::json::value { return boost::json::object{ { "title", diff --git a/src/control.cpp b/src/control.cpp index 1b778a6..d7f0786 100644 --- a/src/control.cpp +++ b/src/control.cpp @@ -7,6 +7,7 @@ #include + namespace { auto valid_rect(luma::rect value) -> std::bool_t { @@ -22,7 +23,7 @@ auto luma::control::arrange(luma::rect bounds) -> void { bounds_ = bounds; } -auto luma::control::handle_touch(luma::touch_event const& event) -> std::bool_t { +auto luma::control::handle_touch(luma::touch_event const &event) -> std::bool_t { static_cast(event); return false; } diff --git a/src/controls.cpp b/src/controls.cpp index 7ddcd05..554d806 100644 --- a/src/controls.cpp +++ b/src/controls.cpp @@ -27,21 +27,21 @@ #include #include + namespace { constexpr auto panel_padding = luma::edge_insets{ .left = 8.0F, .top = 8.0F, .right = 8.0F, - .bottom = 8.0F -}; + .bottom = 8.0F}; constexpr auto scroll_drag_threshold = std::float32_t{6.0F}; class label_control final : public luma::control { public: explicit label_control(std::string text); - auto measure(luma::draw_context& context, luma::theme const& theme, luma::constraints limits) -> luma::size override; - auto draw(luma::draw_context& context, luma::theme const& theme) const -> void override; + auto measure(luma::draw_context &context, luma::theme const &theme, luma::constraints limits) -> luma::size override; + auto draw(luma::draw_context &context, luma::theme const &theme) const -> void override; private: std::string text_; }; @@ -49,9 +49,9 @@ private: class button_control final : public luma::control { public: button_control(std::string text, std::function on_click); - auto measure(luma::draw_context& context, luma::theme const& theme, luma::constraints limits) -> luma::size override; - auto draw(luma::draw_context& context, luma::theme const& theme) const -> void override; - auto handle_touch(luma::touch_event const& event) -> std::bool_t override; + auto measure(luma::draw_context &context, luma::theme const &theme, luma::constraints limits) -> luma::size override; + auto draw(luma::draw_context &context, luma::theme const &theme) const -> void override; + auto handle_touch(luma::touch_event const &event) -> std::bool_t override; auto focusable() const -> std::bool_t override; private: std::string text_; @@ -62,9 +62,9 @@ private: class text_field_control final : public luma::control { public: explicit text_field_control(std::shared_ptr input); - auto measure(luma::draw_context& context, luma::theme const& theme, luma::constraints limits) -> luma::size override; - auto draw(luma::draw_context& context, luma::theme const& theme) const -> void override; - auto handle_touch(luma::touch_event const& event) -> std::bool_t override; + auto measure(luma::draw_context &context, luma::theme const &theme, luma::constraints limits) -> luma::size override; + auto draw(luma::draw_context &context, luma::theme const &theme) const -> void override; + auto handle_touch(luma::touch_event const &event) -> std::bool_t override; auto invalidate_layout() -> void override; auto bind_layout_invalidator(std::function invalidator) -> void override; auto focusable() const -> std::bool_t override; @@ -81,9 +81,9 @@ class soft_keyboard_control final : public luma::control { public: soft_keyboard_control(luma::keyboard_layout layout, std::function on_text, std::function on_enter); soft_keyboard_control(luma::keyboard_layout layout, std::shared_ptr input, std::function on_enter); - auto measure(luma::draw_context&, luma::theme const&, luma::constraints limits) -> luma::size override; - auto draw(luma::draw_context& context, luma::theme const& theme) const -> void override; - auto handle_touch(luma::touch_event const& event) -> std::bool_t override; + auto measure(luma::draw_context &, luma::theme const &, luma::constraints limits) -> luma::size override; + auto draw(luma::draw_context &context, luma::theme const &theme) const -> void override; + auto handle_touch(luma::touch_event const &event) -> std::bool_t override; private: luma::keyboard_layout layout_; std::function on_text_; @@ -94,10 +94,10 @@ private: class panel_control final : public luma::control { public: explicit panel_control(std::vector> children); - auto measure(luma::draw_context& context, luma::theme const& theme, luma::constraints limits) -> luma::size override; + auto measure(luma::draw_context &context, luma::theme const &theme, luma::constraints limits) -> luma::size override; auto arrange(luma::rect bounds) -> void override; - auto draw(luma::draw_context& context, luma::theme const& theme) const -> void override; - auto handle_touch(luma::touch_event const& event) -> std::bool_t override; + auto draw(luma::draw_context &context, luma::theme const &theme) const -> void override; + auto handle_touch(luma::touch_event const &event) -> std::bool_t override; auto invalidate_layout() -> void override; auto bind_layout_invalidator(std::function invalidator) -> void override; private: @@ -107,8 +107,8 @@ private: class spacer_control final : public luma::control { public: explicit spacer_control(luma::size value); - auto measure(luma::draw_context&, luma::theme const&, luma::constraints limits) -> luma::size override; - auto draw(luma::draw_context&, luma::theme const&) const -> void override; + auto measure(luma::draw_context &, luma::theme const &, luma::constraints limits) -> luma::size override; + auto draw(luma::draw_context &, luma::theme const &) const -> void override; private: luma::size value_; }; @@ -116,8 +116,8 @@ private: class progress_bar_control final : public luma::control { public: explicit progress_bar_control(std::float32_t value); - auto measure(luma::draw_context&, luma::theme const&, luma::constraints limits) -> luma::size override; - auto draw(luma::draw_context& context, luma::theme const& theme) const -> void override; + auto measure(luma::draw_context &, luma::theme const &, luma::constraints limits) -> luma::size override; + auto draw(luma::draw_context &context, luma::theme const &theme) const -> void override; private: std::float32_t value_; }; @@ -125,8 +125,8 @@ private: class image_control final : public luma::control { public: image_control(std::shared_ptr texture, luma::image_fit fit); - auto measure(luma::draw_context&, luma::theme const&, luma::constraints limits) -> luma::size override; - auto draw(luma::draw_context& context, luma::theme const& theme) const -> void override; + auto measure(luma::draw_context &, luma::theme const &, luma::constraints limits) -> luma::size override; + auto draw(luma::draw_context &context, luma::theme const &theme) const -> void override; private: std::shared_ptr texture_; luma::image_fit fit_; @@ -135,10 +135,10 @@ private: class linear_control final : public luma::control { public: linear_control(luma::direction direction, std::vector> children, std::float32_t gap, luma::alignment align); - auto measure(luma::draw_context& context, luma::theme const& theme, luma::constraints limits) -> luma::size override; + auto measure(luma::draw_context &context, luma::theme const &theme, luma::constraints limits) -> luma::size override; auto arrange(luma::rect bounds) -> void override; - auto draw(luma::draw_context& context, luma::theme const& theme) const -> void override; - auto handle_touch(luma::touch_event const& event) -> std::bool_t override; + auto draw(luma::draw_context &context, luma::theme const &theme) const -> void override; + auto handle_touch(luma::touch_event const &event) -> std::bool_t override; auto invalidate_layout() -> void override; auto bind_layout_invalidator(std::function invalidator) -> void override; private: @@ -152,10 +152,10 @@ private: class stack_control final : public luma::control { public: explicit stack_control(std::vector> children); - auto measure(luma::draw_context& context, luma::theme const& theme, luma::constraints limits) -> luma::size override; + auto measure(luma::draw_context &context, luma::theme const &theme, luma::constraints limits) -> luma::size override; auto arrange(luma::rect bounds) -> void override; - auto draw(luma::draw_context& context, luma::theme const& theme) const -> void override; - auto handle_touch(luma::touch_event const& event) -> std::bool_t override; + auto draw(luma::draw_context &context, luma::theme const &theme) const -> void override; + auto handle_touch(luma::touch_event const &event) -> std::bool_t override; auto invalidate_layout() -> void override; auto bind_layout_invalidator(std::function invalidator) -> void override; private: @@ -165,10 +165,10 @@ private: class scroll_view_control final : public luma::control { public: scroll_view_control(std::unique_ptr child, std::bool_t vertical, std::bool_t horizontal); - auto measure(luma::draw_context& context, luma::theme const& theme, luma::constraints limits) -> luma::size override; + auto measure(luma::draw_context &context, luma::theme const &theme, luma::constraints limits) -> luma::size override; auto arrange(luma::rect bounds) -> void override; - auto draw(luma::draw_context& context, luma::theme const& theme) const -> void override; - auto handle_touch(luma::touch_event const& event) -> std::bool_t override; + auto draw(luma::draw_context &context, luma::theme const &theme) const -> void override; + auto handle_touch(luma::touch_event const &event) -> std::bool_t override; auto invalidate_layout() -> void override; auto bind_layout_invalidator(std::function invalidator) -> void override; private: @@ -177,7 +177,7 @@ private: luma::point last{}; std::bool_t child_active{false}; }; - auto handle_point(luma::touch_event const& event, luma::touch_point const& point) -> std::bool_t; + auto handle_point(luma::touch_event const &event, luma::touch_point const &point) -> std::bool_t; auto invalidate_child_measure() -> void; auto arrange_child() -> void; auto clamp_offset() -> void; @@ -202,9 +202,9 @@ auto finite_size(luma::size value) -> std::bool_t { auto finite_rect(luma::rect value) -> std::bool_t { return std::isfinite(value.x) && std::isfinite(value.y) && finite_size({ - .width = value.width, - .height = value.height, - }); + .width = value.width, + .height = value.height, + }); } auto finite_constraints(luma::constraints value) -> std::bool_t { @@ -219,11 +219,11 @@ auto same_constraints(luma::constraints left, luma::constraints right) -> std::b return same_size(left.min, right.min) && same_size(left.max, right.max); } -auto same_text_style(luma::text_style const& left, luma::text_style const& right) -> std::bool_t { +auto same_text_style(luma::text_style const &left, luma::text_style const &right) -> std::bool_t { return left.font == right.font && left.size == right.size && left.line_height == right.line_height; } -auto same_theme_metrics(luma::theme const& left, luma::theme const& right) -> std::bool_t { +auto same_theme_metrics(luma::theme const &left, luma::theme const &right) -> std::bool_t { return same_text_style(left.body, right.body) && same_text_style(left.title, right.title) && left.radius == right.radius && left.spacing == right.spacing; } @@ -232,26 +232,26 @@ auto invalid(std::string message) -> std::expected { return luma::detail::fail(luma::detail::error_invalid_argument, std::move(message)); } -auto throw_error(modulus::error const& error) -> void { +auto throw_error(modulus::error const &error) -> void { throw std::runtime_error(error.describe()); } -auto throw_if_failed(std::expected const& status) -> void { +auto throw_if_failed(std::expected const &status) -> void { if (!status) { throw_error(status.error()); } } -auto make_event(luma::touch_event const& event, luma::touch_point point) -> luma::touch_event { +auto make_event(luma::touch_event const &event, luma::touch_point point) -> luma::touch_event { return { .points = {point}, .time = event.time, }; } -auto dispatch_to_children(std::vector>& children, luma::touch_event const& event) -> std::bool_t { +auto dispatch_to_children(std::vector> &children, luma::touch_event const &event) -> std::bool_t { auto handled = false; - for (auto const& point : event.points) { + for (auto const &point : event.points) { auto single = make_event(event, point); for (auto current = children.rbegin(); current != children.rend(); ++current) { assert(*current != nullptr); @@ -264,8 +264,8 @@ auto dispatch_to_children(std::vector>& children, return handled; } -auto find_point(luma::touch_event const& event, std::int32_t id) -> luma::touch_point const* { - for (auto const& point : event.points) { +auto find_point(luma::touch_event const &event, std::int32_t id) -> luma::touch_point const * { + for (auto const &point : event.points) { if (point.id == id) { return &point; } @@ -273,8 +273,8 @@ auto find_point(luma::touch_event const& event, std::int32_t id) -> luma::touch_ return nullptr; } -auto first_point_with_phase(luma::touch_event const& event, luma::touch_phase phase) -> luma::touch_point const* { - for (auto const& point : event.points) { +auto first_point_with_phase(luma::touch_event const &event, luma::touch_phase phase) -> luma::touch_point const * { + for (auto const &point : event.points) { if (point.phase == phase) { return &point; } @@ -282,8 +282,8 @@ auto first_point_with_phase(luma::touch_event const& event, luma::touch_phase ph return nullptr; } -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; } @@ -291,13 +291,13 @@ auto first_point_inside(luma::touch_event const& event, luma::rect bounds, luma: return nullptr; } -auto valid_keyboard_layout(luma::keyboard_layout const& layout) -> std::expected { +auto valid_keyboard_layout(luma::keyboard_layout const &layout) -> std::expected { if (layout.rows.empty()) { return luma::detail::fail(luma::detail::error_invalid_argument, "keyboard layout must contain at least one row"); } auto has_key = false; - for (auto const& row : layout.rows) { - for (auto const& key : row) { + for (auto const &row : layout.rows) { + for (auto const &key : row) { has_key = true; if (key.label.empty()) { return luma::detail::fail(luma::detail::error_invalid_argument, "keyboard key label must not be empty"); @@ -310,8 +310,8 @@ auto valid_keyboard_layout(luma::keyboard_layout const& layout) -> std::expected return {}; } -auto validate_children(std::vector> const& children) -> std::expected { - for (auto const& child : children) { +auto validate_children(std::vector> const &children) -> std::expected { + for (auto const &child : children) { if (child == nullptr) { return luma::detail::fail(luma::detail::error_invalid_argument, "child control must not be null"); } @@ -319,7 +319,7 @@ auto validate_children(std::vector> const& childr return {}; } -auto centered_text_origin(luma::draw_context& context, std::string const& text, luma::rect bounds, luma::text_style const& style) -> luma::point { +auto centered_text_origin(luma::draw_context &context, std::string const &text, luma::rect bounds, luma::text_style const &style) -> luma::point { assert(finite_rect(bounds)); auto measured = context.measure_text(text, style); assert(finite_size(measured)); @@ -359,52 +359,56 @@ auto fit_rect(luma::rect bounds, luma::texture_info info, luma::image_fit fit) - }; } -label_control::label_control(std::string text) : text_{std::move(text)} { +label_control::label_control(std::string text) + : text_{std::move(text)} { assert(!text_.empty()); } -auto label_control::measure(luma::draw_context& context, luma::theme const& theme, luma::constraints limits) -> luma::size { +auto label_control::measure(luma::draw_context &context, luma::theme const &theme, luma::constraints limits) -> luma::size { assert(finite_constraints(limits)); auto measured = context.measure_text(text_, theme.body); assert(finite_size(measured)); return luma::clamp(measured, limits); } -auto label_control::draw(luma::draw_context& context, luma::theme const& theme) const -> void { +auto label_control::draw(luma::draw_context &context, luma::theme const &theme) const -> void { assert(!text_.empty()); context.draw_text(text_, { - .x = bounds().x, - .y = bounds().y, - }, theme.body, enabled() ? theme.text : theme.text_muted); + .x = bounds().x, + .y = bounds().y, + }, + theme.body, enabled() ? theme.text : theme.text_muted); } -button_control::button_control(std::string text, std::function on_click) : text_{std::move(text)}, on_click_{std::move(on_click)} { +button_control::button_control(std::string text, std::function on_click) + : text_{std::move(text)}, on_click_{std::move(on_click)} { assert(!text_.empty()); assert(on_click_); } -auto button_control::measure(luma::draw_context& context, luma::theme const& theme, luma::constraints limits) -> luma::size { +auto button_control::measure(luma::draw_context &context, luma::theme const &theme, luma::constraints limits) -> luma::size { assert(finite_constraints(limits)); auto text_size = context.measure_text(text_, theme.body); assert(finite_size(text_size)); return luma::clamp({ - .width = text_size.width + 32.0F, - .height = std::max(std::float32_t{48}, text_size.height + std::float32_t{16}), - }, limits); + .width = text_size.width + 32.0F, + .height = std::max(std::float32_t{48}, text_size.height + std::float32_t{16}), + }, + limits); } -auto button_control::draw(luma::draw_context& context, luma::theme const& theme) const -> void { +auto button_control::draw(luma::draw_context &context, luma::theme const &theme) const -> void { auto fill = pressed_id_.has_value() ? theme.surface_active : theme.surface; context.fill_rect(bounds(), fill); context.stroke_rect(bounds(), 1.0F, focused() ? theme.accent : theme.border); context.draw_text(text_, centered_text_origin(context, text_, bounds(), theme.body), theme.body, enabled() ? theme.text : theme.text_muted); } -auto button_control::handle_touch(luma::touch_event const& event) -> std::bool_t { +auto button_control::handle_touch(luma::touch_event const &event) -> std::bool_t { if (!enabled()) { return false; } - auto const* point = pressed_id_ ? find_point(event, *pressed_id_) : first_point_inside(event, bounds(), luma::touch_phase::DOWN); + auto const *point = pressed_id_ ? find_point(event, *pressed_id_) : first_point_inside(event, bounds(), luma::touch_phase::DOWN); if (point == nullptr) { return false; } @@ -434,11 +438,12 @@ auto button_control::focusable() const -> std::bool_t { return true; } -text_field_control::text_field_control(std::shared_ptr input) : input_{std::move(input)} { +text_field_control::text_field_control(std::shared_ptr input) + : input_{std::move(input)} { assert(input_ != nullptr); } -auto text_field_control::measure(luma::draw_context& context, luma::theme const& theme, luma::constraints limits) -> luma::size { +auto text_field_control::measure(luma::draw_context &context, luma::theme const &theme, luma::constraints limits) -> luma::size { assert(finite_constraints(limits)); auto version = input_->version(); if (cached_limits_ && cached_style_ && same_constraints(*cached_limits_, limits) && same_text_style(*cached_style_, theme.body) && cached_version_ == version) { @@ -451,13 +456,14 @@ auto text_field_control::measure(luma::draw_context& context, luma::theme const& cached_style_ = theme.body; cached_version_ = version; cached_size_ = luma::clamp({ - .width = std::max(std::float32_t{240}, measured.width + std::float32_t{24}), - .height = std::max(std::float32_t{48}, measured.height + std::float32_t{16}), - }, limits); + .width = std::max(std::float32_t{240}, measured.width + std::float32_t{24}), + .height = std::max(std::float32_t{48}, measured.height + std::float32_t{16}), + }, + limits); return cached_size_; } -auto text_field_control::draw(luma::draw_context& context, luma::theme const& theme) const -> void { +auto text_field_control::draw(luma::draw_context &context, luma::theme const &theme) const -> void { context.fill_rect(bounds(), theme.surface); context.stroke_rect(bounds(), 1.0F, input_->focused() ? theme.accent : theme.border); auto options = input_->snapshot(); @@ -468,16 +474,17 @@ auto text_field_control::draw(luma::draw_context& context, luma::theme const& th text = std::string(options.text.size(), '*'); } context.draw_text(text, { - .x = bounds().x + 12.0F, - .y = bounds().y + 8.0F, - }, theme.body, options.text.empty() ? theme.text_muted : theme.text); + .x = bounds().x + 12.0F, + .y = bounds().y + 8.0F, + }, + theme.body, options.text.empty() ? theme.text_muted : theme.text); } -auto text_field_control::handle_touch(luma::touch_event const& event) -> std::bool_t { +auto text_field_control::handle_touch(luma::touch_event const &event) -> std::bool_t { if (!enabled()) { return false; } - auto const* point = first_point_inside(event, bounds(), luma::touch_phase::DOWN); + auto const *point = first_point_inside(event, bounds(), luma::touch_phase::DOWN); if (point == nullptr) { point = first_point_with_phase(event, luma::touch_phase::DOWN); } @@ -513,28 +520,31 @@ auto text_field_control::focusable() const -> std::bool_t { return true; } -soft_keyboard_control::soft_keyboard_control(luma::keyboard_layout layout, std::function on_text, std::function on_enter) : layout_{std::move(layout)}, on_text_{std::move(on_text)}, on_enter_{std::move(on_enter)} { +soft_keyboard_control::soft_keyboard_control(luma::keyboard_layout layout, std::function on_text, std::function on_enter) + : layout_{std::move(layout)}, on_text_{std::move(on_text)}, on_enter_{std::move(on_enter)} { assert(!layout_.rows.empty()); assert(on_text_); } -soft_keyboard_control::soft_keyboard_control(luma::keyboard_layout layout, std::shared_ptr input, std::function on_enter) : layout_{std::move(layout)}, on_enter_{std::move(on_enter)}, input_{std::move(input)} { +soft_keyboard_control::soft_keyboard_control(luma::keyboard_layout layout, std::shared_ptr input, std::function on_enter) + : layout_{std::move(layout)}, on_enter_{std::move(on_enter)}, input_{std::move(input)} { assert(!layout_.rows.empty()); assert(input_ != nullptr); } -auto soft_keyboard_control::measure(luma::draw_context&, luma::theme const&, luma::constraints limits) -> luma::size { +auto soft_keyboard_control::measure(luma::draw_context &, luma::theme const &, luma::constraints limits) -> luma::size { assert(finite_constraints(limits)); return luma::clamp({ - .width = 640.0F, - .height = static_cast(layout_.rows.size()) * 56.0F, - }, limits); + .width = 640.0F, + .height = static_cast(layout_.rows.size()) * 56.0F, + }, + limits); } -auto soft_keyboard_control::draw(luma::draw_context& context, luma::theme const& theme) const -> void { +auto soft_keyboard_control::draw(luma::draw_context &context, luma::theme const &theme) const -> void { auto key_height = bounds().height / static_cast(layout_.rows.size()); for (auto row_index = std::size_t{}; row_index < layout_.rows.size(); ++row_index) { - auto const& row = layout_.rows[row_index]; + auto const &row = layout_.rows[row_index]; if (row.empty()) { continue; } @@ -549,27 +559,28 @@ auto soft_keyboard_control::draw(luma::draw_context& context, luma::theme const& context.fill_rect(rect, theme.surface); context.stroke_rect(rect, 1.0F, theme.border); context.draw_text(row[column_index].label, { - .x = rect.x + 12.0F, - .y = rect.y + 10.0F, - }, theme.body, theme.text); + .x = rect.x + 12.0F, + .y = rect.y + 10.0F, + }, + theme.body, theme.text); } } } -auto soft_keyboard_control::handle_touch(luma::touch_event const& event) -> std::bool_t { - auto const* point = first_point_inside(event, bounds(), luma::touch_phase::UP); +auto soft_keyboard_control::handle_touch(luma::touch_event const &event) -> std::bool_t { + auto const *point = first_point_inside(event, bounds(), luma::touch_phase::UP); if (point == nullptr) { return false; } auto row_count = layout_.rows.size(); assert(row_count > 0); auto row_index = std::min(row_count - 1, static_cast((point->position.y - bounds().y) / (bounds().height / static_cast(row_count)))); - auto const& row = layout_.rows[row_index]; + auto const &row = layout_.rows[row_index]; if (row.empty()) { return true; } auto column_index = std::min(row.size() - 1, static_cast((point->position.x - bounds().x) / (bounds().width / static_cast(row.size())))); - auto const& key = row[column_index]; + auto const &key = row[column_index]; switch (key.kind) { case luma::keyboard_key_kind::CHARACTER: if (input_) { @@ -604,13 +615,14 @@ auto soft_keyboard_control::handle_touch(luma::touch_event const& event) -> std: return true; } -panel_control::panel_control(std::vector> children) : children_{std::move(children)} {} +panel_control::panel_control(std::vector> children) + : children_{std::move(children)} {} -auto panel_control::measure(luma::draw_context& context, luma::theme const& theme, luma::constraints limits) -> luma::size { +auto panel_control::measure(luma::draw_context &context, luma::theme const &theme, luma::constraints limits) -> luma::size { assert(finite_constraints(limits)); auto child_limits = luma::deflate(limits, panel_padding); auto result = child_limits.min; - for (auto& child : children_) { + for (auto &child : children_) { assert(child != nullptr); auto measured = child->measure(context, theme, child_limits); result.width = std::max(result.width, measured.width); @@ -625,26 +637,26 @@ auto panel_control::arrange(luma::rect bounds) -> void { assert(finite_rect(bounds)); luma::control::arrange(bounds); auto content = luma::inset(bounds, panel_padding); - for (auto& child : children_) { + for (auto &child : children_) { assert(child != nullptr); child->arrange(content); } } -auto panel_control::draw(luma::draw_context& context, luma::theme const& theme) const -> void { +auto panel_control::draw(luma::draw_context &context, luma::theme const &theme) const -> void { context.fill_rect(bounds(), theme.surface); - for (auto const& child : children_) { + for (auto const &child : children_) { assert(child != nullptr); child->draw(context, theme); } } -auto panel_control::handle_touch(luma::touch_event const& event) -> std::bool_t { +auto panel_control::handle_touch(luma::touch_event const &event) -> std::bool_t { return dispatch_to_children(children_, event); } auto panel_control::invalidate_layout() -> void { - for (auto& child : children_) { + for (auto &child : children_) { assert(child != nullptr); child->invalidate_layout(); } @@ -652,62 +664,68 @@ auto panel_control::invalidate_layout() -> void { auto panel_control::bind_layout_invalidator(std::function invalidator) -> void { luma::control::bind_layout_invalidator(invalidator); - for (auto& child : children_) { + for (auto &child : children_) { assert(child != nullptr); child->bind_layout_invalidator(invalidator); } } -spacer_control::spacer_control(luma::size value) : value_{value} { +spacer_control::spacer_control(luma::size value) + : value_{value} { assert(finite_size(value_)); } -auto spacer_control::measure(luma::draw_context&, luma::theme const&, luma::constraints limits) -> luma::size { +auto spacer_control::measure(luma::draw_context &, luma::theme const &, luma::constraints limits) -> luma::size { assert(finite_constraints(limits)); return luma::clamp(value_, limits); } -auto spacer_control::draw(luma::draw_context&, luma::theme const&) const -> void {} +auto spacer_control::draw(luma::draw_context &, luma::theme const &) const -> void {} -progress_bar_control::progress_bar_control(std::float32_t value) : value_{std::clamp(value, std::float32_t{}, std::float32_t{1})} { +progress_bar_control::progress_bar_control(std::float32_t value) + : value_{std::clamp(value, std::float32_t{}, std::float32_t{1})} { assert(std::isfinite(value)); } -auto progress_bar_control::measure(luma::draw_context&, luma::theme const&, luma::constraints limits) -> luma::size { +auto progress_bar_control::measure(luma::draw_context &, luma::theme const &, luma::constraints limits) -> luma::size { assert(finite_constraints(limits)); return luma::clamp({ - .width = 160.0F, - .height = 16.0F, - }, limits); + .width = 160.0F, + .height = 16.0F, + }, + limits); } -auto progress_bar_control::draw(luma::draw_context& context, luma::theme const& theme) const -> void { +auto progress_bar_control::draw(luma::draw_context &context, luma::theme const &theme) const -> void { context.fill_rect(bounds(), theme.surface); context.fill_rect({ - .x = bounds().x, - .y = bounds().y, - .width = bounds().width * value_, - .height = bounds().height, - }, theme.accent); + .x = bounds().x, + .y = bounds().y, + .width = bounds().width * value_, + .height = bounds().height, + }, + theme.accent); } -image_control::image_control(std::shared_ptr texture, luma::image_fit fit) : texture_{std::move(texture)}, fit_{fit} { +image_control::image_control(std::shared_ptr texture, luma::image_fit fit) + : texture_{std::move(texture)}, fit_{fit} { assert(texture_ != nullptr); } -auto image_control::measure(luma::draw_context&, luma::theme const&, luma::constraints limits) -> luma::size { +auto image_control::measure(luma::draw_context &, luma::theme const &, luma::constraints limits) -> luma::size { assert(finite_constraints(limits)); auto info = texture_->info(); if (info.width <= 0 || info.height <= 0) { return luma::clamp({}, limits); } return luma::clamp({ - .width = static_cast(info.width), - .height = static_cast(info.height), - }, limits); + .width = static_cast(info.width), + .height = static_cast(info.height), + }, + limits); } -auto image_control::draw(luma::draw_context& context, luma::theme const& theme) const -> void { +auto image_control::draw(luma::draw_context &context, luma::theme const &theme) const -> void { auto info = texture_->info(); if (info.width <= 0 || info.height <= 0) { return; @@ -721,18 +739,19 @@ auto image_control::draw(luma::draw_context& context, luma::theme const& theme) context.draw_texture(*texture_, source, fit_rect(bounds(), info, fit_), theme.text); } -linear_control::linear_control(luma::direction direction, std::vector> children, std::float32_t gap, luma::alignment align) : direction_{direction}, children_{std::move(children)}, gap_{gap}, align_{align} { +linear_control::linear_control(luma::direction direction, std::vector> children, std::float32_t gap, luma::alignment align) + : direction_{direction}, children_{std::move(children)}, gap_{gap}, align_{align} { assert(std::isfinite(gap_)); assert(gap_ >= 0.0F); } -auto linear_control::measure(luma::draw_context& context, luma::theme const& theme, luma::constraints limits) -> luma::size { +auto linear_control::measure(luma::draw_context &context, luma::theme const &theme, luma::constraints limits) -> luma::size { assert(finite_constraints(limits)); measured_.clear(); measured_.reserve(children_.size()); auto result = luma::size{}; for (auto index = std::size_t{}; index < children_.size(); ++index) { - auto& child = children_[index]; + auto &child = children_[index]; assert(child != nullptr); auto child_limits = limits; if (direction_ == luma::direction::ROW) { @@ -762,7 +781,7 @@ auto linear_control::arrange(luma::rect bounds) -> void { luma::control::arrange(bounds); auto cursor = direction_ == luma::direction::ROW ? bounds.x : bounds.y; for (auto index = std::size_t{}; index < children_.size(); ++index) { - auto& child = children_[index]; + auto &child = children_[index]; assert(child != nullptr); auto measured = index < measured_.size() ? measured_[index] : luma::size{}; auto child_bounds = bounds; @@ -791,20 +810,20 @@ auto linear_control::arrange(luma::rect bounds) -> void { } } -auto linear_control::draw(luma::draw_context& context, luma::theme const& theme) const -> void { - for (auto const& child : children_) { +auto linear_control::draw(luma::draw_context &context, luma::theme const &theme) const -> void { + for (auto const &child : children_) { assert(child != nullptr); child->draw(context, theme); } } -auto linear_control::handle_touch(luma::touch_event const& event) -> std::bool_t { +auto linear_control::handle_touch(luma::touch_event const &event) -> std::bool_t { return dispatch_to_children(children_, event); } auto linear_control::invalidate_layout() -> void { measured_.clear(); - for (auto& child : children_) { + for (auto &child : children_) { assert(child != nullptr); child->invalidate_layout(); } @@ -812,19 +831,19 @@ auto linear_control::invalidate_layout() -> void { auto linear_control::bind_layout_invalidator(std::function invalidator) -> void { luma::control::bind_layout_invalidator(invalidator); - for (auto& child : children_) { + for (auto &child : children_) { assert(child != nullptr); child->bind_layout_invalidator(invalidator); } } +stack_control::stack_control(std::vector> children) + : children_{std::move(children)} {} -stack_control::stack_control(std::vector> children) : children_{std::move(children)} {} - -auto stack_control::measure(luma::draw_context& context, luma::theme const& theme, luma::constraints limits) -> luma::size { +auto stack_control::measure(luma::draw_context &context, luma::theme const &theme, luma::constraints limits) -> luma::size { assert(finite_constraints(limits)); auto result = limits.min; - for (auto& child : children_) { + for (auto &child : children_) { assert(child != nullptr); auto measured = child->measure(context, theme, limits); result.width = std::max(result.width, measured.width); @@ -836,25 +855,25 @@ auto stack_control::measure(luma::draw_context& context, luma::theme const& them auto stack_control::arrange(luma::rect bounds) -> void { assert(finite_rect(bounds)); luma::control::arrange(bounds); - for (auto& child : children_) { + for (auto &child : children_) { assert(child != nullptr); child->arrange(bounds); } } -auto stack_control::draw(luma::draw_context& context, luma::theme const& theme) const -> void { - for (auto const& child : children_) { +auto stack_control::draw(luma::draw_context &context, luma::theme const &theme) const -> void { + for (auto const &child : children_) { assert(child != nullptr); child->draw(context, theme); } } -auto stack_control::handle_touch(luma::touch_event const& event) -> std::bool_t { +auto stack_control::handle_touch(luma::touch_event const &event) -> std::bool_t { return dispatch_to_children(children_, event); } auto stack_control::invalidate_layout() -> void { - for (auto& child : children_) { + for (auto &child : children_) { assert(child != nullptr); child->invalidate_layout(); } @@ -862,19 +881,19 @@ auto stack_control::invalidate_layout() -> void { auto stack_control::bind_layout_invalidator(std::function invalidator) -> void { luma::control::bind_layout_invalidator(invalidator); - for (auto& child : children_) { + for (auto &child : children_) { assert(child != nullptr); child->bind_layout_invalidator(invalidator); } } - -scroll_view_control::scroll_view_control(std::unique_ptr child, std::bool_t vertical, std::bool_t horizontal) : child_{std::move(child)}, vertical_{vertical}, horizontal_{horizontal} { +scroll_view_control::scroll_view_control(std::unique_ptr child, std::bool_t vertical, std::bool_t horizontal) + : child_{std::move(child)}, vertical_{vertical}, horizontal_{horizontal} { assert(child_ != nullptr); assert(vertical_ || horizontal_); } -auto scroll_view_control::measure(luma::draw_context& context, luma::theme const& theme, luma::constraints limits) -> luma::size { +auto scroll_view_control::measure(luma::draw_context &context, luma::theme const &theme, luma::constraints limits) -> luma::size { assert(finite_constraints(limits)); auto max = std::numeric_limits::max(); auto child_limits = luma::constraints{ @@ -903,21 +922,21 @@ auto scroll_view_control::arrange(luma::rect bounds) -> void { arrange_child(); } -auto scroll_view_control::draw(luma::draw_context& context, luma::theme const& theme) const -> void { +auto scroll_view_control::draw(luma::draw_context &context, luma::theme const &theme) const -> void { context.push_clip(bounds()); child_->draw(context, theme); context.pop_clip(); } -auto scroll_view_control::handle_touch(luma::touch_event const& event) -> std::bool_t { +auto scroll_view_control::handle_touch(luma::touch_event const &event) -> std::bool_t { auto handled = false; - for (auto const& point : event.points) { + for (auto const &point : event.points) { handled = handle_point(event, point) || handled; } return handled; } -auto scroll_view_control::handle_point(luma::touch_event const& event, luma::touch_point const& point) -> std::bool_t { +auto scroll_view_control::handle_point(luma::touch_event const &event, luma::touch_point const &point) -> std::bool_t { if (point.phase == luma::touch_phase::DOWN) { if (!luma::contains(bounds(), point.position)) { return false; @@ -938,13 +957,11 @@ auto scroll_view_control::handle_point(luma::touch_event const& event, luma::tou } return true; } - auto found = touches_.find(point.id); if (found == touches_.end()) { return false; } - auto& state = found->second; - + auto &state = found->second; if (point.phase == luma::touch_phase::MOVE) { auto delta = luma::point{ .x = point.position.x - state.last.x, @@ -994,7 +1011,6 @@ auto scroll_view_control::handle_point(luma::touch_event const& event, luma::tou } return true; } - if (point.phase == luma::touch_phase::UP || point.phase == luma::touch_phase::CANCEL) { auto const scrolling = scroll_id_ == point.id && dragging_; if (state.child_active) { @@ -1015,7 +1031,6 @@ auto scroll_view_control::handle_point(luma::touch_event const& event, luma::tou touches_.erase(found); return true; } - return true; } @@ -1073,7 +1088,7 @@ auto accepts_text(luma::text_input_mode mode, std::string_view current, std::str return true; } -auto validate_text_options(luma::text_field_options const& options) -> std::expected { +auto validate_text_options(luma::text_field_options const &options) -> std::expected { if (options.max_length == 0) { return luma::detail::fail(luma::detail::error_invalid_argument, "text field max length must be positive"); } @@ -1090,13 +1105,13 @@ auto callback_failure(std::string message) -> std::expected(luma::detail::error_internal, std::move(message)); } -auto notify_text_changed(std::function const& callback, std::string value) -> std::expected { +auto notify_text_changed(std::function const &callback, std::string value) -> std::expected { if (!callback) { return {}; } try { callback(std::move(value)); - } catch (std::exception const& error) { + } catch (std::exception const &error) { return callback_failure(std::string{"text change callback failed: "} + error.what()); } catch (...) { return callback_failure("text change callback failed with an unknown exception"); @@ -1104,8 +1119,8 @@ auto notify_text_changed(std::function const& callback, std:: return {}; } -auto notify_layout_listeners(std::vector> const& listeners) -> void { - for (auto const& listener : listeners) { +auto notify_layout_listeners(std::vector> const &listeners) -> void { + for (auto const &listener : listeners) { if (!listener) { continue; } @@ -1116,7 +1131,7 @@ auto notify_layout_listeners(std::vector> const& listeners } } -auto collect_layout_listeners(std::vector& listeners) -> std::vector> { +auto collect_layout_listeners(std::vector &listeners) -> std::vector> { auto callbacks = std::vector>{}; auto write = listeners.begin(); for (auto read = listeners.begin(); read != listeners.end(); ++read) { @@ -1135,7 +1150,8 @@ auto collect_layout_listeners(std::vector on_change) : options_{std::move(options)}, on_change_{std::move(on_change)} { +luma::text_input_state::text_input_state(luma::text_field_options options, std::function on_change) + : options_{std::move(options)}, on_change_{std::move(on_change)} { assert(options_.max_length > 0); assert(on_change_); } diff --git a/src/detail/errors.cpp b/src/detail/errors.cpp index 930c07f..897d512 100644 --- a/src/detail/errors.cpp +++ b/src/detail/errors.cpp @@ -5,6 +5,7 @@ #include + auto luma::detail::make_error(std::int32_t code, std::string message, modulus::source_location location) -> modulus::error { return modulus::make_error("luma", code, std::move(message), location); } diff --git a/src/overlays.cpp b/src/overlays.cpp index 3413a94..06a2a76 100644 --- a/src/overlays.cpp +++ b/src/overlays.cpp @@ -17,13 +17,14 @@ #include #include + namespace { class scope_exit { public: explicit scope_exit(std::function 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 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 const& status) -> void { +auto throw_if_failed(std::expected const &status) -> void { if (!status) { throw std::runtime_error(status.error().describe()); } } -scope_exit::scope_exit(std::function action) : action_{std::move(action)} {} +scope_exit::scope_exit(std::function 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 content) : content_{std::move(content)} { +luma::overlay_host::overlay_host(std::unique_ptr 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(luma::detail::error_internal, std::string{"dialog close callback failed: "} + error.what()); } catch (...) { return luma::detail::fail(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] { diff --git a/src/routing.cpp b/src/routing.cpp index 0dfec3c..30e7b0c 100644 --- a/src/routing.cpp +++ b/src/routing.cpp @@ -10,6 +10,7 @@ #include + auto luma::router::register_route(std::string name, std::function, modulus::error>()> factory) -> std::expected { if (name.empty()) { return luma::detail::fail(luma::detail::error_invalid_argument, "route name must not be empty"); @@ -25,7 +26,7 @@ auto luma::router::set_retire_handler(std::function std::expected { +auto luma::router::replace(std::string const &name) -> std::expected { if (name.empty()) { return luma::detail::fail(luma::detail::error_invalid_argument, "route name must not be empty"); } @@ -50,7 +51,7 @@ auto luma::router::replace(std::string const& name) -> std::expected std::expected { +auto luma::router::push(std::string const &name) -> std::expected { if (name.empty()) { return luma::detail::fail(luma::detail::error_invalid_argument, "route name must not be empty"); } @@ -90,7 +91,7 @@ auto luma::router::clear_stack() -> void { retire_stack(); } -auto luma::router::current() -> luma::control* { +auto luma::router::current() -> luma::control * { if (stack_.empty()) { return nullptr; } @@ -98,7 +99,7 @@ auto luma::router::current() -> luma::control* { return stack_.back().view.get(); } -auto luma::router::current() const -> luma::control const* { +auto luma::router::current() const -> luma::control const * { if (stack_.empty()) { return nullptr; } @@ -106,7 +107,7 @@ auto luma::router::current() const -> luma::control const* { return stack_.back().view.get(); } -auto luma::router::current_route() const -> std::string const& { +auto luma::router::current_route() const -> std::string const & { if (stack_.empty()) { return empty_route_; } @@ -125,7 +126,7 @@ auto luma::router::retire(std::unique_ptr view) -> void { auto luma::router::retire_stack() -> void { auto removed = std::vector{}; removed.swap(stack_); - for (auto& entry : removed) { + for (auto &entry : removed) { retire(std::move(entry.view)); } } diff --git a/src/theme.cpp b/src/theme.cpp index c561f21..7e02118 100644 --- a/src/theme.cpp +++ b/src/theme.cpp @@ -16,13 +16,13 @@ #include + namespace { constexpr auto json_options = modulus::json_config::options{ .category = "luma", .invalid_argument_code = luma::detail::error_invalid_argument, - .not_found_code = luma::detail::error_not_found -}; + .not_found_code = luma::detail::error_not_found}; auto invalid_color(std::string message) -> std::expected { assert(!message.empty()); @@ -39,18 +39,18 @@ auto invalid_status(std::string message) -> std::expected return luma::detail::fail(luma::detail::error_invalid_argument, std::move(message)); } -auto byte_value(boost::json::value const& value, std::char_t const* name) -> std::expected { +auto byte_value(boost::json::value const &value, std::char_t const *name) -> std::expected { assert(name != nullptr); - auto const* integer = value.if_int64(); + auto const *integer = value.if_int64(); if (integer == nullptr || *integer < 0 || *integer > 255) { return luma::detail::fail(luma::detail::error_invalid_argument, std::string{name} + " must be an integer from 0 to 255"); } return modulus::success(static_cast(*integer)); } -auto apply_color(boost::json::object const& object, std::char_t const* name, luma::color& target) -> std::expected { +auto apply_color(boost::json::object const &object, std::char_t const *name, luma::color &target) -> std::expected { assert(name != nullptr); - if (auto const* value = object.if_contains(name)) { + if (auto const *value = object.if_contains(name)) { auto parsed = luma::parse_color(*value); if (!parsed) { return modulus::fail(parsed.error()); @@ -60,38 +60,39 @@ auto apply_color(boost::json::object const& object, std::char_t const* name, lum return {}; } -auto number_value(boost::json::value const& value) -> std::optional; +auto number_value(boost::json::value const &value) -> std::optional; -auto apply_text_style(boost::json::object const& object, std::char_t const* name, luma::text_style& target) -> std::expected { +auto apply_text_style(boost::json::object const &object, std::char_t const *name, luma::text_style &target) -> std::expected { assert(name != nullptr); - if (auto const* value = object.if_contains(name)) { + if (auto const *value = object.if_contains(name)) { auto style = modulus::json_config::require_object(*value, name, json_options); if (!style) { return modulus::fail(style.error()); } auto unknown = modulus::json_config::reject_unknown_fields(**style, { - "font", - "size", - "line_height", - }, name, json_options); + "font", + "size", + "line_height", + }, + name, json_options); if (!unknown) { return modulus::fail(unknown.error()); } - if (auto const* font = (*style)->if_contains("font")) { - auto const* text = font->if_string(); + if (auto const *font = (*style)->if_contains("font")) { + auto const *text = font->if_string(); if (text == nullptr) { return luma::detail::fail(luma::detail::error_invalid_argument, std::string{name} + ".font must be a string"); } target.font = std::string{text->c_str()}; } - if (auto const* size = (*style)->if_contains("size")) { + if (auto const *size = (*style)->if_contains("size")) { auto number = number_value(*size); if (!number || *number <= 0.0) { return luma::detail::fail(luma::detail::error_invalid_argument, std::string{name} + ".size must be positive"); } target.size = static_cast(*number); } - if (auto const* line_height = (*style)->if_contains("line_height")) { + if (auto const *line_height = (*style)->if_contains("line_height")) { auto number = number_value(*line_height); if (!number || *number <= 0.0) { return luma::detail::fail(luma::detail::error_invalid_argument, std::string{name} + ".line_height must be positive"); @@ -102,11 +103,11 @@ auto apply_text_style(boost::json::object const& object, std::char_t const* name return {}; } -auto number_value(boost::json::value const& value) -> std::optional { - if (auto const* number = value.if_double()) { +auto number_value(boost::json::value const &value) -> std::optional { + if (auto const *number = value.if_double()) { return *number; } - if (auto const* integer = value.if_int64()) { + if (auto const *integer = value.if_int64()) { return static_cast(*integer); } return std::nullopt; @@ -118,7 +119,7 @@ auto luma::default_theme() -> luma::theme { return {}; } -auto luma::validate(luma::text_style const& style) -> std::expected { +auto luma::validate(luma::text_style const &style) -> std::expected { if (style.font.empty()) { return invalid_status("text style font must not be empty"); } @@ -131,7 +132,7 @@ auto luma::validate(luma::text_style const& style) -> std::expected std::expected { +auto luma::validate(luma::theme const &theme) -> std::expected { if (auto status = luma::validate(theme.body); !status) { return modulus::fail(status.error()); } @@ -147,23 +148,24 @@ auto luma::validate(luma::theme const& theme) -> std::expected std::expected { +auto luma::parse_color(boost::json::value const &value) -> std::expected { auto object = modulus::json_config::require_object(value, "color", json_options); if (!object) { return invalid_color(std::string{object.error().message()}); } auto unknown = modulus::json_config::reject_unknown_fields(**object, { - "r", - "g", - "b", - "a", - }, "color", json_options); + "r", + "g", + "b", + "a", + }, + "color", json_options); if (!unknown) { return invalid_color(std::string{unknown.error().message()}); } - auto const* red_value = (*object)->if_contains("r"); - auto const* green_value = (*object)->if_contains("g"); - auto const* blue_value = (*object)->if_contains("b"); + auto const *red_value = (*object)->if_contains("r"); + auto const *green_value = (*object)->if_contains("g"); + auto const *blue_value = (*object)->if_contains("b"); if (red_value == nullptr || green_value == nullptr || blue_value == nullptr) { return invalid_color("color requires r, g, and b fields"); } @@ -180,7 +182,7 @@ auto luma::parse_color(boost::json::value const& value) -> std::expectedif_contains("a")) { + if (auto const *alpha_value = (*object)->if_contains("a")) { auto parsed = byte_value(*alpha_value, "a"); if (!parsed) { return invalid_color(std::string{parsed.error().message()}); @@ -195,24 +197,25 @@ auto luma::parse_color(boost::json::value const& value) -> std::expected std::expected { +auto luma::parse_theme(boost::json::value const &value) -> std::expected { auto object = modulus::json_config::require_object(value, "theme", json_options); if (!object) { return invalid_theme(std::string{object.error().message()}); } auto unknown = modulus::json_config::reject_unknown_fields(**object, { - "background", - "surface", - "surface_active", - "text", - "text_muted", - "border", - "accent", - "body", - "title", - "radius", - "spacing", - }, "theme", json_options); + "background", + "surface", + "surface_active", + "text", + "text_muted", + "border", + "accent", + "body", + "title", + "radius", + "spacing", + }, + "theme", json_options); if (!unknown) { return invalid_theme(std::string{unknown.error().message()}); } @@ -244,14 +247,14 @@ auto luma::parse_theme(boost::json::value const& value) -> std::expectedif_contains("radius")) { + if (auto const *radius = (*object)->if_contains("radius")) { auto number = number_value(*radius); if (!number || *number < 0.0) { return invalid_theme("theme.radius must be non-negative"); } parsed.radius = static_cast(*number); } - if (auto const* spacing = (*object)->if_contains("spacing")) { + if (auto const *spacing = (*object)->if_contains("spacing")) { auto number = number_value(*spacing); if (!number || *number < 0.0) { return invalid_theme("theme.spacing must be non-negative"); @@ -264,7 +267,7 @@ auto luma::parse_theme(boost::json::value const& value) -> std::expected boost::json::value { +auto luma::to_json(luma::color const &color) -> boost::json::value { return boost::json::object{ { "r", @@ -285,7 +288,7 @@ auto luma::to_json(luma::color const& color) -> boost::json::value { }; } -auto luma::to_json(luma::text_style const& style) -> boost::json::value { +auto luma::to_json(luma::text_style const &style) -> boost::json::value { return boost::json::object{ { "font", @@ -302,7 +305,7 @@ auto luma::to_json(luma::text_style const& style) -> boost::json::value { }; } -auto luma::to_json(luma::theme const& theme) -> boost::json::value { +auto luma::to_json(luma::theme const &theme) -> boost::json::value { return boost::json::object{ { "background", diff --git a/src/window.cpp b/src/window.cpp index a614eb5..e398583 100644 --- a/src/window.cpp +++ b/src/window.cpp @@ -19,13 +19,14 @@ #include #include + namespace { class scope_exit { public: explicit scope_exit(std::function 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 action_{}; @@ -37,7 +38,7 @@ auto finite_rect(luma::rect value) -> std::bool_t { return std::isfinite(value.x) && std::isfinite(value.y) && std::isfinite(value.width) && std::isfinite(value.height) && value.width >= 0.0F && value.height >= 0.0F; } -auto title_height(luma::window_options const& options, std::float32_t line_height) -> std::float32_t { +auto title_height(luma::window_options const &options, std::float32_t line_height) -> std::float32_t { if (!options.decorated) { return {}; } @@ -45,7 +46,7 @@ auto title_height(luma::window_options const& options, std::float32_t line_heigh return std::min(desired, options.bounds.height); } -auto title_bounds(luma::window_options const& options, std::float32_t line_height) -> luma::rect { +auto title_bounds(luma::window_options const &options, std::float32_t line_height) -> luma::rect { return { .x = options.bounds.x, .y = options.bounds.y, @@ -54,7 +55,7 @@ auto title_bounds(luma::window_options const& options, std::float32_t line_heigh }; } -auto client_bounds(luma::window_options const& options, std::float32_t line_height) -> luma::rect { +auto client_bounds(luma::window_options const &options, std::float32_t line_height) -> luma::rect { if (!options.decorated) { return options.bounds; } @@ -77,14 +78,15 @@ auto unavailable(std::string message) -> std::expected { return luma::detail::fail(luma::detail::error_unavailable, std::move(message)); } -auto make_event(luma::touch_event const& event, luma::touch_point point) -> luma::touch_event { +auto make_event(luma::touch_event const &event, luma::touch_point point) -> luma::touch_event { return { .points = {point}, .time = event.time, }; } -scope_exit::scope_exit(std::function action) : action_{std::move(action)} {} +scope_exit::scope_exit(std::function action) + : action_{std::move(action)} {} scope_exit::~scope_exit() { if (action_) { @@ -94,7 +96,8 @@ scope_exit::~scope_exit() { } -luma::window::window(std::uint64_t id, luma::window_options options, std::unique_ptr content) : id_{id}, options_{std::move(options)}, content_{std::move(content)} { +luma::window::window(std::uint64_t id, luma::window_options options, std::unique_ptr content) + : id_{id}, options_{std::move(options)}, content_{std::move(content)} { assert(id_ != 0); assert(finite_rect(options_.bounds)); assert(content_ != nullptr); @@ -105,7 +108,7 @@ auto luma::window::id() const -> std::uint64_t { return id_; } -auto luma::window::options() const -> luma::window_options const& { +auto luma::window::options() const -> luma::window_options const & { assert(finite_rect(options_.bounds)); return options_; } @@ -126,12 +129,12 @@ auto luma::window::visible() const -> std::bool_t { return options_.visible; } -auto luma::window::content() -> luma::control* { +auto luma::window::content() -> luma::control * { assert(content_ != nullptr); return content_.get(); } -auto luma::window::content() const -> luma::control const* { +auto luma::window::content() const -> luma::control const * { assert(content_ != nullptr); return content_.get(); } @@ -246,11 +249,11 @@ auto luma::window_manager::set_visible(std::uint64_t id, std::bool_t visible) -> return {}; } -auto luma::window_manager::find(std::uint64_t id) -> luma::window* { +auto luma::window_manager::find(std::uint64_t id) -> luma::window * { if (id == 0) { return nullptr; } - auto found = std::find_if(windows_.begin(), windows_.end(), [id](auto const& window) { return window && window->id() == id; }); + auto found = std::find_if(windows_.begin(), windows_.end(), [id](auto const &window) { return window && window->id() == id; }); return found == windows_.end() ? nullptr : found->get(); } @@ -265,7 +268,7 @@ auto luma::window_manager::clear() -> void { active_touches_.clear(); } -auto luma::window_manager::measure(luma::draw_context& context, luma::theme const& theme, luma::constraints limits) -> luma::size { +auto luma::window_manager::measure(luma::draw_context &context, luma::theme const &theme, luma::constraints limits) -> luma::size { title_line_height_ = theme.body.line_height; ++mutation_depth_; auto guard = scope_exit{[this] { @@ -273,7 +276,7 @@ auto luma::window_manager::measure(luma::draw_context& context, luma::theme cons --mutation_depth_; apply_pending_operations(); }}; - for (auto& window : windows_) { + for (auto &window : windows_) { assert(window != nullptr); if (!window->visible()) { continue; @@ -281,12 +284,12 @@ auto luma::window_manager::measure(luma::draw_context& context, luma::theme cons assert(window->content() != nullptr); auto client = client_bounds(window->options(), title_line_height_); window->content()->measure(context, theme, { - .min = {}, - .max = { - .width = client.width, - .height = client.height, - }, - }); + .min = {}, + .max = { + .width = client.width, + .height = client.height, + }, + }); } return luma::clamp(limits.max, limits); } @@ -300,7 +303,7 @@ auto luma::window_manager::arrange(luma::rect bounds) -> void { apply_pending_operations(); }}; luma::control::arrange(bounds); - for (auto& window : windows_) { + for (auto &window : windows_) { assert(window != nullptr); if (window->visible()) { assert(window->content() != nullptr); @@ -309,7 +312,7 @@ auto luma::window_manager::arrange(luma::rect bounds) -> void { } } -auto luma::window_manager::draw(luma::draw_context& context, luma::theme const& theme) const -> void { +auto luma::window_manager::draw(luma::draw_context &context, luma::theme const &theme) const -> void { title_line_height_ = theme.body.line_height; ++mutation_depth_; auto guard = scope_exit{[this] { @@ -317,7 +320,7 @@ auto luma::window_manager::draw(luma::draw_context& context, luma::theme const& --mutation_depth_; apply_pending_operations(); }}; - for (auto const& window : windows_) { + for (auto const &window : windows_) { assert(window != nullptr); if (!window->visible()) { continue; @@ -333,15 +336,16 @@ auto luma::window_manager::draw(luma::draw_context& context, luma::theme const& auto title = title_bounds(window->options(), title_line_height_); context.fill_rect(title, theme.surface_active); context.draw_text(window->options().title, { - .x = title.x + 8.0F, - .y = title.y + window_title_vertical_padding, - }, theme.body, theme.text); + .x = title.x + 8.0F, + .y = title.y + window_title_vertical_padding, + }, + theme.body, theme.text); } context.stroke_rect(bounds, 1.0F, theme.border); } } -auto luma::window_manager::handle_touch(luma::touch_event const& event) -> std::bool_t { +auto luma::window_manager::handle_touch(luma::touch_event const &event) -> std::bool_t { if (event.points.empty()) { return false; } @@ -352,10 +356,10 @@ auto luma::window_manager::handle_touch(luma::touch_event const& event) -> std:: apply_pending_operations(); }}; auto handled = false; - for (auto const& point : event.points) { + for (auto const &point : event.points) { if (auto captured = active_touches_.find(point.id); captured != active_touches_.end()) { auto const window_id = captured->second; - auto* captured_window = find(window_id); + auto *captured_window = find(window_id); auto const captured_visible = captured_window != nullptr && captured_window->visible(); if (captured_visible) { assert(captured_window->content() != nullptr); @@ -368,7 +372,6 @@ auto luma::window_manager::handle_touch(luma::touch_event const& event) -> std:: } continue; } - for (auto current = windows_.rbegin(); current != windows_.rend(); ++current) { assert(*current != nullptr); if (!(*current)->visible()) { @@ -400,8 +403,8 @@ auto luma::window_manager::contains_effective(std::uint64_t id) const -> std::bo if (id == 0) { return false; } - auto exists = std::find_if(windows_.begin(), windows_.end(), [id](auto const& window) { return window && window->id() == id; }) != windows_.end(); - for (auto const& operation : pending_operations_) { + auto exists = std::find_if(windows_.begin(), windows_.end(), [id](auto const &window) { return window && window->id() == id; }) != windows_.end(); + for (auto const &operation : pending_operations_) { switch (operation.kind) { case luma::window_manager::pending_kind::OPEN: if (operation.id == id) { @@ -426,7 +429,7 @@ auto luma::window_manager::contains_effective(std::uint64_t id) const -> std::bo } auto luma::window_manager::close_now(std::uint64_t id) const -> void { - auto found = std::find_if(windows_.begin(), windows_.end(), [id](auto const& window) { return window && window->id() == id; }); + auto found = std::find_if(windows_.begin(), windows_.end(), [id](auto const &window) { return window && window->id() == id; }); if (found == windows_.end()) { return; } @@ -442,7 +445,7 @@ auto luma::window_manager::close_now(std::uint64_t id) const -> void { } auto luma::window_manager::bring_to_front_now(std::uint64_t id) const -> void { - auto found = std::find_if(windows_.begin(), windows_.end(), [id](auto const& window) { return window && window->id() == id; }); + auto found = std::find_if(windows_.begin(), windows_.end(), [id](auto const &window) { return window && window->id() == id; }); if (found == windows_.end()) { return; } @@ -452,14 +455,14 @@ auto luma::window_manager::bring_to_front_now(std::uint64_t id) const -> void { } auto luma::window_manager::set_bounds_now(std::uint64_t id, luma::rect bounds) const -> void { - auto* window = const_cast(this)->find(id); + auto *window = const_cast(this)->find(id); if (window != nullptr) { static_cast(window->set_bounds(bounds)); } } auto luma::window_manager::set_visible_now(std::uint64_t id, std::bool_t visible) const -> void { - auto* window = const_cast(this)->find(id); + auto *window = const_cast(this)->find(id); if (window != nullptr) { window->set_visible(visible); } @@ -471,7 +474,7 @@ auto luma::window_manager::apply_pending_operations() const -> void { } auto pending = std::vector{}; pending.swap(pending_operations_); - for (auto& operation : pending) { + for (auto &operation : pending) { switch (operation.kind) { case luma::window_manager::pending_kind::OPEN: if (operation.window) { @@ -505,20 +508,20 @@ auto luma::window_manager::invalidate_layout() -> void { --mutation_depth_; apply_pending_operations(); }}; - auto controls = std::vector{}; + auto controls = std::vector{}; controls.reserve(windows_.size() + pending_operations_.size()); - for (auto& window : windows_) { + for (auto &window : windows_) { assert(window != nullptr); assert(window->content() != nullptr); controls.push_back(window->content()); } - for (auto& operation : pending_operations_) { + for (auto &operation : pending_operations_) { if (operation.window) { assert(operation.window->content() != nullptr); controls.push_back(operation.window->content()); } } - for (auto* control : controls) { + for (auto *control : controls) { assert(control != nullptr); control->invalidate_layout(); } @@ -526,12 +529,12 @@ auto luma::window_manager::invalidate_layout() -> void { auto luma::window_manager::bind_layout_invalidator(std::function invalidator) -> void { luma::control::bind_layout_invalidator(invalidator); - for (auto& window : windows_) { + for (auto &window : windows_) { assert(window != nullptr); assert(window->content() != nullptr); window->content()->bind_layout_invalidator(invalidator); } - for (auto& operation : pending_operations_) { + for (auto &operation : pending_operations_) { if (operation.window) { assert(operation.window->content() != nullptr); operation.window->content()->bind_layout_invalidator(invalidator); diff --git a/tests/test.cpp b/tests/test.cpp index d320c2a..cf7a6dd 100644 --- a/tests/test.cpp +++ b/tests/test.cpp @@ -22,6 +22,7 @@ #include + namespace { struct fake_draw_context final : public luma::draw_context { @@ -30,11 +31,11 @@ struct fake_draw_context final : public luma::draw_context { auto stroke_line(luma::point, luma::point, std::float32_t, luma::color) -> void override; auto fill_ellipse(luma::rect, luma::color) -> void override; auto stroke_ellipse(luma::rect, std::float32_t, luma::color) -> void override; - auto draw_text(std::string_view, luma::point origin, luma::text_style const& style, luma::color) -> void override; - auto draw_texture(luma::texture const&, luma::rect, luma::rect, luma::color) -> void override; + auto draw_text(std::string_view, luma::point origin, luma::text_style const &style, luma::color) -> void override; + auto draw_texture(luma::texture const &, luma::rect, luma::rect, luma::color) -> void override; auto push_clip(luma::rect bounds) -> void override; auto pop_clip() -> void override; - auto measure_text(std::string_view text, luma::text_style const& style) const -> luma::size override; + auto measure_text(std::string_view text, luma::text_style const &style) const -> luma::size override; std::vector filled{}; std::vector clips{}; std::vector drawn_styles{}; @@ -46,10 +47,10 @@ struct fake_draw_context final : public luma::draw_context { class fixed_control final : public luma::control { public: explicit fixed_control(luma::size value); - auto measure(luma::draw_context&, luma::theme const&, luma::constraints) -> luma::size override; + auto measure(luma::draw_context &, luma::theme const &, luma::constraints) -> luma::size override; auto arrange(luma::rect bounds) -> void override; - auto draw(luma::draw_context&, luma::theme const&) const -> void override; - auto handle_touch(luma::touch_event const& event) -> std::bool_t override; + auto draw(luma::draw_context &, luma::theme const &) const -> void override; + auto handle_touch(luma::touch_event const &event) -> std::bool_t override; luma::size value_{}; luma::rect arranged{}; std::bool_t touched{false}; @@ -58,10 +59,10 @@ public: struct counting_control final : public luma::control { explicit counting_control(luma::size value); - auto measure(luma::draw_context&, luma::theme const&, luma::constraints) -> luma::size override; + auto measure(luma::draw_context &, luma::theme const &, luma::constraints) -> luma::size override; auto arrange(luma::rect bounds) -> void override; - auto draw(luma::draw_context&, luma::theme const&) const -> void override; - auto handle_touch(luma::touch_event const& event) -> std::bool_t override; + auto draw(luma::draw_context &, luma::theme const &) const -> void override; + auto handle_touch(luma::touch_event const &event) -> std::bool_t override; auto invalidate_layout() -> void override; luma::size value_{}; luma::rect arranged{}; @@ -71,9 +72,9 @@ struct counting_control final : public luma::control { }; struct filling_control final : public luma::control { - auto measure(luma::draw_context&, luma::theme const&, luma::constraints limits) -> luma::size override; + auto measure(luma::draw_context &, luma::theme const &, luma::constraints limits) -> luma::size override; auto arrange(luma::rect bounds) -> void override; - auto draw(luma::draw_context& context, luma::theme const&) const -> void override; + auto draw(luma::draw_context &context, luma::theme const &) const -> void override; luma::rect arranged{}; std::int32_t measure_count{}; }; @@ -87,19 +88,19 @@ private: }; struct fake_resources final : public luma::renderer_resources { - auto load_texture(std::string const&) -> std::expected, modulus::error> override; + auto load_texture(std::string const &) -> std::expected, modulus::error> override; }; struct reentrant_resources final : public luma::renderer_resources { - auto load_texture(std::string const& path) -> std::expected, modulus::error> override; - luma::asset_cache* cache{}; + auto load_texture(std::string const &path) -> std::expected, modulus::error> override; + luma::asset_cache *cache{}; std::int32_t load_count{}; std::bool_t inner_loaded{false}; }; struct same_path_reentrant_resources final : public luma::renderer_resources { - auto load_texture(std::string const& path) -> std::expected, modulus::error> override; - luma::asset_cache* cache{}; + auto load_texture(std::string const &path) -> std::expected, modulus::error> override; + luma::asset_cache *cache{}; std::int32_t load_count{}; std::bool_t reentered{false}; std::bool_t recursive_failed{false}; @@ -108,7 +109,7 @@ struct same_path_reentrant_resources final : public luma::renderer_resources { class blocking_resources final : public luma::renderer_resources { public: - auto load_texture(std::string const&) -> std::expected, modulus::error> override; + auto load_texture(std::string const &) -> std::expected, modulus::error> override; auto wait_for_loads(std::int32_t count) -> std::bool_t; auto release() -> void; auto load_count() const -> std::int32_t; @@ -121,9 +122,9 @@ private: }; struct recording_control final : public luma::control { - auto measure(luma::draw_context&, luma::theme const&, luma::constraints) -> luma::size override; - auto draw(luma::draw_context&, luma::theme const&) const -> void override; - auto handle_touch(luma::touch_event const& event) -> std::bool_t override; + auto measure(luma::draw_context &, luma::theme const &, luma::constraints) -> luma::size override; + auto draw(luma::draw_context &, luma::theme const &) const -> void override; + auto handle_touch(luma::touch_event const &event) -> std::bool_t override; std::vector phases{}; std::vector ids{}; }; @@ -149,85 +150,85 @@ class destroy_probe_control final : public luma::control { public: explicit destroy_probe_control(std::shared_ptr state); ~destroy_probe_control() override; - auto measure(luma::draw_context&, luma::theme const&, luma::constraints) -> luma::size override; - auto draw(luma::draw_context&, luma::theme const&) const -> void override; + auto measure(luma::draw_context &, luma::theme const &, luma::constraints) -> luma::size override; + auto draw(luma::draw_context &, luma::theme const &) const -> void override; private: std::shared_ptr state_{}; }; class closing_window_control final : public luma::control { public: - closing_window_control(luma::window_manager& manager, std::uint64_t& id, std::shared_ptr state); + closing_window_control(luma::window_manager &manager, std::uint64_t &id, std::shared_ptr state); ~closing_window_control() override; - auto measure(luma::draw_context&, luma::theme const&, luma::constraints) -> luma::size override; - auto draw(luma::draw_context&, luma::theme const&) const -> void override; - auto handle_touch(luma::touch_event const&) -> std::bool_t override; + auto measure(luma::draw_context &, luma::theme const &, luma::constraints) -> luma::size override; + auto draw(luma::draw_context &, luma::theme const &) const -> void override; + auto handle_touch(luma::touch_event const &) -> std::bool_t override; private: - luma::window_manager& manager_; - std::uint64_t& id_; + luma::window_manager &manager_; + std::uint64_t &id_; std::shared_ptr state_{}; }; class opening_window_control final : public luma::control { public: - opening_window_control(luma::window_manager& manager, std::shared_ptr state); - auto measure(luma::draw_context&, luma::theme const&, luma::constraints) -> luma::size override; - auto draw(luma::draw_context&, luma::theme const&) const -> void override; - auto handle_touch(luma::touch_event const&) -> std::bool_t override; + opening_window_control(luma::window_manager &manager, std::shared_ptr state); + auto measure(luma::draw_context &, luma::theme const &, luma::constraints) -> luma::size override; + auto draw(luma::draw_context &, luma::theme const &) const -> void override; + auto handle_touch(luma::touch_event const &) -> std::bool_t override; private: - luma::window_manager& manager_; + luma::window_manager &manager_; std::shared_ptr state_{}; }; class updating_window_control final : public luma::control { public: - updating_window_control(luma::window_manager& manager, std::uint64_t& id, std::shared_ptr state); - auto measure(luma::draw_context&, luma::theme const&, luma::constraints) -> luma::size override; - auto draw(luma::draw_context&, luma::theme const&) const -> void override; - auto handle_touch(luma::touch_event const&) -> std::bool_t override; + updating_window_control(luma::window_manager &manager, std::uint64_t &id, std::shared_ptr state); + auto measure(luma::draw_context &, luma::theme const &, luma::constraints) -> luma::size override; + auto draw(luma::draw_context &, luma::theme const &) const -> void override; + auto handle_touch(luma::touch_event const &) -> std::bool_t override; private: - luma::window_manager& manager_; - std::uint64_t& id_; + luma::window_manager &manager_; + std::uint64_t &id_; std::shared_ptr state_{}; }; class replacing_root_invalidate_control final : public luma::control { public: - replacing_root_invalidate_control(luma::application& app, std::shared_ptr state); + replacing_root_invalidate_control(luma::application &app, std::shared_ptr state); ~replacing_root_invalidate_control() override; - auto measure(luma::draw_context&, luma::theme const&, luma::constraints) -> luma::size override; - auto draw(luma::draw_context&, luma::theme const&) const -> void override; + auto measure(luma::draw_context &, luma::theme const &, luma::constraints) -> luma::size override; + auto draw(luma::draw_context &, luma::theme const &) const -> void override; auto invalidate_layout() -> void override; private: - luma::application& app_; + luma::application &app_; std::shared_ptr state_{}; }; class closing_window_invalidate_control final : public luma::control { public: - closing_window_invalidate_control(luma::window_manager& manager, std::uint64_t& id, std::shared_ptr state); + closing_window_invalidate_control(luma::window_manager &manager, std::uint64_t &id, std::shared_ptr state); ~closing_window_invalidate_control() override; - auto measure(luma::draw_context&, luma::theme const&, luma::constraints) -> luma::size override; - auto draw(luma::draw_context&, luma::theme const&) const -> void override; + auto measure(luma::draw_context &, luma::theme const &, luma::constraints) -> luma::size override; + auto draw(luma::draw_context &, luma::theme const &) const -> void override; auto invalidate_layout() -> void override; private: - luma::window_manager& manager_; - std::uint64_t& id_; + luma::window_manager &manager_; + std::uint64_t &id_; std::shared_ptr state_{}; }; class closing_dialog_control final : public luma::control { public: - closing_dialog_control(luma::overlay_host& host, std::shared_ptr state, close_phase phase); + closing_dialog_control(luma::overlay_host &host, std::shared_ptr state, close_phase phase); ~closing_dialog_control() override; - auto measure(luma::draw_context&, luma::theme const&, luma::constraints) -> luma::size override; + auto measure(luma::draw_context &, luma::theme const &, luma::constraints) -> luma::size override; auto arrange(luma::rect bounds) -> void override; - auto draw(luma::draw_context&, luma::theme const&) const -> void override; - auto handle_touch(luma::touch_event const&) -> std::bool_t override; + auto draw(luma::draw_context &, luma::theme const &) const -> void override; + auto handle_touch(luma::touch_event const &) -> std::bool_t override; auto invalidate_layout() -> void override; private: auto close_if(close_phase phase) const -> void; - luma::overlay_host& host_; + luma::overlay_host &host_; std::shared_ptr state_{}; close_phase phase_{close_phase::TOUCH}; }; @@ -244,12 +245,12 @@ auto fake_draw_context::fill_ellipse(luma::rect, luma::color) -> void {} auto fake_draw_context::stroke_ellipse(luma::rect, std::float32_t, luma::color) -> void {} -auto fake_draw_context::draw_text(std::string_view, luma::point origin, luma::text_style const& style, luma::color) -> void { +auto fake_draw_context::draw_text(std::string_view, luma::point origin, luma::text_style const &style, luma::color) -> void { drawn_styles.push_back(style); drawn_origins.push_back(origin); } -auto fake_draw_context::draw_texture(luma::texture const&, luma::rect, luma::rect, luma::color) -> void {} +auto fake_draw_context::draw_texture(luma::texture const &, luma::rect, luma::rect, luma::color) -> void {} auto fake_draw_context::push_clip(luma::rect bounds) -> void { clips.push_back(bounds); @@ -261,16 +262,17 @@ auto fake_draw_context::pop_clip() -> void { --clip_depth; } -auto fake_draw_context::measure_text(std::string_view text, luma::text_style const& style) const -> luma::size { +auto fake_draw_context::measure_text(std::string_view text, luma::text_style const &style) const -> luma::size { return { .width = static_cast(text.size()) * style.size * std::float32_t{0.5F}, .height = style.line_height, }; } -fixed_control::fixed_control(luma::size value) : value_{value} {} +fixed_control::fixed_control(luma::size value) + : value_{value} {} -auto fixed_control::measure(luma::draw_context&, luma::theme const&, luma::constraints) -> luma::size { +auto fixed_control::measure(luma::draw_context &, luma::theme const &, luma::constraints) -> luma::size { return value_; } @@ -279,10 +281,10 @@ auto fixed_control::arrange(luma::rect bounds) -> void { arranged = bounds; } -auto fixed_control::draw(luma::draw_context&, luma::theme const&) const -> void {} +auto fixed_control::draw(luma::draw_context &, luma::theme const &) const -> void {} -auto fixed_control::handle_touch(luma::touch_event const& event) -> std::bool_t { - for (auto const& point : event.points) { +auto fixed_control::handle_touch(luma::touch_event const &event) -> std::bool_t { + for (auto const &point : event.points) { if (luma::contains(bounds(), point.position)) { touched = true; last_phase = point.phase; @@ -292,9 +294,10 @@ auto fixed_control::handle_touch(luma::touch_event const& event) -> std::bool_t return false; } -counting_control::counting_control(luma::size value) : value_{value} {} +counting_control::counting_control(luma::size value) + : value_{value} {} -auto counting_control::measure(luma::draw_context&, luma::theme const&, luma::constraints) -> luma::size { +auto counting_control::measure(luma::draw_context &, luma::theme const &, luma::constraints) -> luma::size { ++measure_count; return value_; } @@ -305,10 +308,10 @@ auto counting_control::arrange(luma::rect bounds) -> void { ++arrange_count; } -auto counting_control::draw(luma::draw_context&, luma::theme const&) const -> void {} +auto counting_control::draw(luma::draw_context &, luma::theme const &) const -> void {} -auto counting_control::handle_touch(luma::touch_event const& event) -> std::bool_t { - for (auto const& point : event.points) { +auto counting_control::handle_touch(luma::touch_event const &event) -> std::bool_t { + for (auto const &point : event.points) { if (luma::contains(bounds(), point.position)) { return true; } @@ -320,12 +323,13 @@ auto counting_control::invalidate_layout() -> void { ++invalidate_count; } -auto filling_control::measure(luma::draw_context&, luma::theme const&, luma::constraints limits) -> luma::size { +auto filling_control::measure(luma::draw_context &, luma::theme const &, luma::constraints limits) -> luma::size { ++measure_count; return luma::clamp({ - .width = 20.0F, - .height = 20.0F, - }, limits); + .width = 20.0F, + .height = 20.0F, + }, + limits); } auto filling_control::arrange(luma::rect bounds) -> void { @@ -333,21 +337,22 @@ auto filling_control::arrange(luma::rect bounds) -> void { arranged = bounds; } -auto filling_control::draw(luma::draw_context& context, luma::theme const&) const -> void { +auto filling_control::draw(luma::draw_context &context, luma::theme const &) const -> void { context.fill_rect(bounds(), {}); } -fake_texture::fake_texture(std::int32_t width, std::int32_t height) : info_{.width = width, .height = height} {} +fake_texture::fake_texture(std::int32_t width, std::int32_t height) + : info_{.width = width, .height = height} {} auto fake_texture::info() const -> luma::texture_info { return info_; } -auto fake_resources::load_texture(std::string const&) -> std::expected, modulus::error> { +auto fake_resources::load_texture(std::string const &) -> std::expected, modulus::error> { return modulus::success(std::make_shared()); } -auto reentrant_resources::load_texture(std::string const& path) -> std::expected, modulus::error> { +auto reentrant_resources::load_texture(std::string const &path) -> std::expected, modulus::error> { ++load_count; if (path == "outer.png" && cache != nullptr) { auto inner = cache->texture("inner.png"); @@ -356,7 +361,7 @@ auto reentrant_resources::load_texture(std::string const& path) -> std::expected return modulus::success(std::make_shared()); } -auto same_path_reentrant_resources::load_texture(std::string const& path) -> std::expected, modulus::error> { +auto same_path_reentrant_resources::load_texture(std::string const &path) -> std::expected, modulus::error> { ++load_count; if (!reentered && cache != nullptr) { reentered = true; @@ -369,7 +374,7 @@ auto same_path_reentrant_resources::load_texture(std::string const& path) -> std return modulus::success(std::make_shared()); } -auto blocking_resources::load_texture(std::string const&) -> std::expected, modulus::error> { +auto blocking_resources::load_texture(std::string const &) -> std::expected, modulus::error> { auto lock = std::unique_lock{mutex_}; ++load_count_; load_entered_.notify_all(); @@ -397,24 +402,25 @@ auto blocking_resources::load_count() const -> std::int32_t { return load_count_; } -auto recording_control::measure(luma::draw_context&, luma::theme const&, luma::constraints) -> luma::size { +auto recording_control::measure(luma::draw_context &, luma::theme const &, luma::constraints) -> luma::size { return { .width = 20.0F, .height = 20.0F, }; } -auto recording_control::draw(luma::draw_context&, luma::theme const&) const -> void {} +auto recording_control::draw(luma::draw_context &, luma::theme const &) const -> void {} -auto recording_control::handle_touch(luma::touch_event const& event) -> std::bool_t { - for (auto const& point : event.points) { +auto recording_control::handle_touch(luma::touch_event const &event) -> std::bool_t { + for (auto const &point : event.points) { phases.push_back(point.phase); ids.push_back(point.id); } return true; } -destroy_probe_control::destroy_probe_control(std::shared_ptr state) : state_{std::move(state)} {} +destroy_probe_control::destroy_probe_control(std::shared_ptr state) + : state_{std::move(state)} {} destroy_probe_control::~destroy_probe_control() { state_->destroyed = true; @@ -423,16 +429,17 @@ destroy_probe_control::~destroy_probe_control() { } } -auto destroy_probe_control::measure(luma::draw_context&, luma::theme const&, luma::constraints) -> luma::size { +auto destroy_probe_control::measure(luma::draw_context &, luma::theme const &, luma::constraints) -> luma::size { return { .width = 20.0F, .height = 20.0F, }; } -auto destroy_probe_control::draw(luma::draw_context&, luma::theme const&) const -> void {} +auto destroy_probe_control::draw(luma::draw_context &, luma::theme const &) const -> void {} -closing_window_control::closing_window_control(luma::window_manager& manager, std::uint64_t& id, std::shared_ptr state) : manager_{manager}, id_{id}, state_{std::move(state)} {} +closing_window_control::closing_window_control(luma::window_manager &manager, std::uint64_t &id, std::shared_ptr state) + : manager_{manager}, id_{id}, state_{std::move(state)} {} closing_window_control::~closing_window_control() { state_->destroyed = true; @@ -441,16 +448,16 @@ closing_window_control::~closing_window_control() { } } -auto closing_window_control::measure(luma::draw_context&, luma::theme const&, luma::constraints) -> luma::size { +auto closing_window_control::measure(luma::draw_context &, luma::theme const &, luma::constraints) -> luma::size { return { .width = 20.0F, .height = 20.0F, }; } -auto closing_window_control::draw(luma::draw_context&, luma::theme const&) const -> void {} +auto closing_window_control::draw(luma::draw_context &, luma::theme const &) const -> void {} -auto closing_window_control::handle_touch(luma::touch_event const&) -> std::bool_t { +auto closing_window_control::handle_touch(luma::touch_event const &) -> std::bool_t { state_->in_handle = true; auto status = manager_.close(id_); state_->status_ok = status.has_value(); @@ -458,27 +465,29 @@ auto closing_window_control::handle_touch(luma::touch_event const&) -> std::bool return true; } -opening_window_control::opening_window_control(luma::window_manager& manager, std::shared_ptr state) : manager_{manager}, state_{std::move(state)} {} +opening_window_control::opening_window_control(luma::window_manager &manager, std::shared_ptr state) + : manager_{manager}, state_{std::move(state)} {} -auto opening_window_control::measure(luma::draw_context&, luma::theme const&, luma::constraints) -> luma::size { +auto opening_window_control::measure(luma::draw_context &, luma::theme const &, luma::constraints) -> luma::size { return { .width = 20.0F, .height = 20.0F, }; } -auto opening_window_control::draw(luma::draw_context&, luma::theme const&) const -> void {} +auto opening_window_control::draw(luma::draw_context &, luma::theme const &) const -> void {} -auto opening_window_control::handle_touch(luma::touch_event const&) -> std::bool_t { +auto opening_window_control::handle_touch(luma::touch_event const &) -> std::bool_t { auto opened = manager_.open({ - .title = "Opened", - .bounds = { - .x = 250.0F, - .y = 100.0F, - .width = 50.0F, - .height = 50.0F, - }, - }, std::make_unique()); + .title = "Opened", + .bounds = { + .x = 250.0F, + .y = 100.0F, + .width = 50.0F, + .height = 50.0F, + }, + }, + std::make_unique()); state_->status_ok = opened.has_value(); if (opened) { state_->opened_id = *opened; @@ -487,33 +496,35 @@ auto opening_window_control::handle_touch(luma::touch_event const&) -> std::bool return true; } -updating_window_control::updating_window_control(luma::window_manager& manager, std::uint64_t& id, std::shared_ptr state) : manager_{manager}, id_{id}, state_{std::move(state)} {} +updating_window_control::updating_window_control(luma::window_manager &manager, std::uint64_t &id, std::shared_ptr state) + : manager_{manager}, id_{id}, state_{std::move(state)} {} -auto updating_window_control::measure(luma::draw_context&, luma::theme const&, luma::constraints) -> luma::size { +auto updating_window_control::measure(luma::draw_context &, luma::theme const &, luma::constraints) -> luma::size { return { .width = 20.0F, .height = 20.0F, }; } -auto updating_window_control::draw(luma::draw_context&, luma::theme const&) const -> void {} +auto updating_window_control::draw(luma::draw_context &, luma::theme const &) const -> void {} -auto updating_window_control::handle_touch(luma::touch_event const&) -> std::bool_t { +auto updating_window_control::handle_touch(luma::touch_event const &) -> std::bool_t { auto bounds = manager_.set_bounds(id_, { - .x = 5.0F, - .y = 6.0F, - .width = 20.0F, - .height = 30.0F, - }); + .x = 5.0F, + .y = 6.0F, + .width = 20.0F, + .height = 30.0F, + }); auto visible = manager_.set_visible(id_, false); state_->status_ok = bounds.has_value() && visible.has_value(); - if (auto* window = manager_.find(id_)) { + if (auto *window = manager_.find(id_)) { state_->visible_during_callback = window->visible(); } return true; } -closing_dialog_control::closing_dialog_control(luma::overlay_host& host, std::shared_ptr state, close_phase phase) : host_{host}, state_{std::move(state)}, phase_{phase} {} +closing_dialog_control::closing_dialog_control(luma::overlay_host &host, std::shared_ptr state, close_phase phase) + : host_{host}, state_{std::move(state)}, phase_{phase} {} closing_dialog_control::~closing_dialog_control() { state_->destroyed = true; @@ -522,7 +533,7 @@ closing_dialog_control::~closing_dialog_control() { } } -auto closing_dialog_control::measure(luma::draw_context&, luma::theme const&, luma::constraints) -> luma::size { +auto closing_dialog_control::measure(luma::draw_context &, luma::theme const &, luma::constraints) -> luma::size { close_if(close_phase::MEASURE); return { .width = 20.0F, @@ -535,11 +546,11 @@ auto closing_dialog_control::arrange(luma::rect bounds) -> void { close_if(close_phase::ARRANGE); } -auto closing_dialog_control::draw(luma::draw_context&, luma::theme const&) const -> void { +auto closing_dialog_control::draw(luma::draw_context &, luma::theme const &) const -> void { close_if(close_phase::DRAW); } -auto closing_dialog_control::handle_touch(luma::touch_event const&) -> std::bool_t { +auto closing_dialog_control::handle_touch(luma::touch_event const &) -> std::bool_t { close_if(close_phase::TOUCH); return true; } @@ -558,7 +569,8 @@ auto closing_dialog_control::close_if(close_phase phase) const -> void { state_->in_handle = false; } -replacing_root_invalidate_control::replacing_root_invalidate_control(luma::application& app, std::shared_ptr state) : app_{app}, state_{std::move(state)} {} +replacing_root_invalidate_control::replacing_root_invalidate_control(luma::application &app, std::shared_ptr state) + : app_{app}, state_{std::move(state)} {} replacing_root_invalidate_control::~replacing_root_invalidate_control() { state_->destroyed = true; @@ -567,14 +579,14 @@ replacing_root_invalidate_control::~replacing_root_invalidate_control() { } } -auto replacing_root_invalidate_control::measure(luma::draw_context&, luma::theme const&, luma::constraints) -> luma::size { +auto replacing_root_invalidate_control::measure(luma::draw_context &, luma::theme const &, luma::constraints) -> luma::size { return { .width = 20.0F, .height = 20.0F, }; } -auto replacing_root_invalidate_control::draw(luma::draw_context&, luma::theme const&) const -> void {} +auto replacing_root_invalidate_control::draw(luma::draw_context &, luma::theme const &) const -> void {} auto replacing_root_invalidate_control::invalidate_layout() -> void { state_->in_handle = true; @@ -584,7 +596,8 @@ auto replacing_root_invalidate_control::invalidate_layout() -> void { state_->in_handle = false; } -closing_window_invalidate_control::closing_window_invalidate_control(luma::window_manager& manager, std::uint64_t& id, std::shared_ptr state) : manager_{manager}, id_{id}, state_{std::move(state)} {} +closing_window_invalidate_control::closing_window_invalidate_control(luma::window_manager &manager, std::uint64_t &id, std::shared_ptr state) + : manager_{manager}, id_{id}, state_{std::move(state)} {} closing_window_invalidate_control::~closing_window_invalidate_control() { state_->destroyed = true; @@ -593,13 +606,14 @@ closing_window_invalidate_control::~closing_window_invalidate_control() { } } -auto closing_window_invalidate_control::measure(luma::draw_context&, luma::theme const&, luma::constraints) -> luma::size { +auto closing_window_invalidate_control::measure(luma::draw_context &, luma::theme const &, luma::constraints) -> luma::size { return { .width = 20.0F, .height = 20.0F, }; } -auto closing_window_invalidate_control::draw(luma::draw_context&, luma::theme const&) const -> void {} + +auto closing_window_invalidate_control::draw(luma::draw_context &, luma::theme const &) const -> void {} auto closing_window_invalidate_control::invalidate_layout() -> void { state_->in_handle = true; @@ -635,17 +649,17 @@ BOOST_AUTO_TEST_CASE(rect_contains_points) { .height = 50.0F, }; BOOST_TEST(luma::contains(area, { - .x = 10.0F, - .y = 20.0F, - })); + .x = 10.0F, + .y = 20.0F, + })); BOOST_TEST(luma::contains(area, { - .x = 110.0F, - .y = 70.0F, - })); + .x = 110.0F, + .y = 70.0F, + })); BOOST_TEST(!luma::contains(area, { - .x = 111.0F, - .y = 70.0F, - })); + .x = 111.0F, + .y = 70.0F, + })); } BOOST_AUTO_TEST_CASE(default_application_config_targets_scale_display) { @@ -784,11 +798,11 @@ BOOST_AUTO_TEST_CASE(label_measures_text) { auto control = luma::label("Scale"); BOOST_REQUIRE(control); auto measured = (*control)->measure(context, theme, { - .max = { - .width = 1024.0F, - .height = 600.0F, - }, - }); + .max = { + .width = 1024.0F, + .height = 600.0F, + }, + }); BOOST_TEST(measured.width > 0.0F); BOOST_TEST(measured.height > 0.0F); } @@ -804,51 +818,52 @@ BOOST_AUTO_TEST_CASE(text_controls_measure_with_supplied_theme) { auto label = luma::label("Scale"); BOOST_REQUIRE(label); auto small_label = (*label)->measure(context, small, { - .max = { - .width = 1024.0F, - .height = 600.0F, - }, - }); + .max = { + .width = 1024.0F, + .height = 600.0F, + }, + }); auto large_label = (*label)->measure(context, large, { - .max = { - .width = 1024.0F, - .height = 600.0F, - }, - }); + .max = { + .width = 1024.0F, + .height = 600.0F, + }, + }); BOOST_TEST(large_label.width > small_label.width); BOOST_TEST(large_label.height > small_label.height); auto button = luma::button("Scale", [] {}); BOOST_REQUIRE(button); auto small_button = (*button)->measure(context, small, { - .max = { - .width = 1024.0F, - .height = 600.0F, - }, - }); + .max = { + .width = 1024.0F, + .height = 600.0F, + }, + }); auto large_button = (*button)->measure(context, large, { - .max = { - .width = 1024.0F, - .height = 600.0F, - }, - }); + .max = { + .width = 1024.0F, + .height = 600.0F, + }, + }); BOOST_TEST(large_button.width > small_button.width); BOOST_TEST(large_button.height > small_button.height); auto field = luma::text_field({ - .text = "Scale", - }, [](std::string) {}); + .text = "Scale", + }, + [](std::string) {}); BOOST_REQUIRE(field); auto small_field = (*field)->measure(context, small, { - .max = { - .width = 1024.0F, - .height = 600.0F, - }, - }); + .max = { + .width = 1024.0F, + .height = 600.0F, + }, + }); auto large_field = (*field)->measure(context, large, { - .max = { - .width = 1024.0F, - .height = 600.0F, - }, - }); + .max = { + .width = 1024.0F, + .height = 600.0F, + }, + }); BOOST_TEST(large_field.height > small_field.height); } @@ -882,7 +897,8 @@ BOOST_AUTO_TEST_CASE(application_dispatch_serializes_concurrent_callers) { BOOST_REQUIRE(result); }); } - for (auto& thread : threads) { + + for (auto &thread : threads) { thread.join(); } BOOST_TEST(values.size() == 16U); @@ -957,9 +973,10 @@ BOOST_AUTO_TEST_CASE(custom_control_unique_ptr_overloads_are_unambiguous) { })); BOOST_REQUIRE(scroller); auto children = luma::children(std::make_unique(luma::size{ - .width = 10.0F, - .height = 10.0F, - }), luma::label("Label")); + .width = 10.0F, + .height = 10.0F, + }), + luma::label("Label")); BOOST_REQUIRE(children); BOOST_TEST(children->size() == 2U); } @@ -968,8 +985,9 @@ BOOST_AUTO_TEST_CASE(factory_validation_returns_errors) { BOOST_TEST(!luma::label("")); BOOST_TEST(!luma::button("OK", {})); BOOST_TEST(!luma::text_field({ - .max_length = 0, - }, [](std::string) {})); + .max_length = 0, + }, + [](std::string) {})); BOOST_TEST(!luma::image(nullptr)); BOOST_TEST(!luma::image(std::make_shared(0, 16))); BOOST_TEST(!luma::scroll_view(std::unique_ptr{})); @@ -1038,14 +1056,14 @@ BOOST_AUTO_TEST_CASE(asset_cache_serializes_concurrent_same_path_loads) { start_ready.notify_all(); BOOST_REQUIRE(resources.wait_for_loads(1)); resources.release(); - for (auto& thread : threads) { + for (auto &thread : threads) { thread.join(); } BOOST_TEST(resources.load_count() == 1); for (auto value : ok) { BOOST_TEST(value == 1); } - for (auto const& texture : textures) { + for (auto const &texture : textures) { BOOST_TEST(texture == textures.front()); } } @@ -1064,11 +1082,12 @@ BOOST_AUTO_TEST_CASE(asset_cache_rejects_recursive_same_path_load) { BOOST_AUTO_TEST_CASE(text_input_state_filters_modes_and_keyboard_updates_bound_field) { auto changes = std::vector{}; auto input = luma::make_text_input({ - .mode = luma::text_input_mode::INTEGER, - .max_length = 3, - }, [&](std::string text) { - changes.push_back(std::move(text)); - }); + .mode = luma::text_input_mode::INTEGER, + .max_length = 3, + }, + [&](std::string text) { + changes.push_back(std::move(text)); + }); BOOST_REQUIRE(input); BOOST_REQUIRE((*input)->append("1")); BOOST_TEST(!(*input)->append("x")); @@ -1076,20 +1095,21 @@ BOOST_AUTO_TEST_CASE(text_input_state_filters_modes_and_keyboard_updates_bound_f BOOST_TEST(!(*input)->append("345")); BOOST_TEST((*input)->text() == "12"); auto keyboard = luma::soft_keyboard({ - .rows = { - { - { - "3", - "3", - }, - { - "<-", - "", - luma::keyboard_key_kind::BACKSPACE, - }, - }, - }, - }, *input); + .rows = { + { + { + "3", + "3", + }, + { + "<-", + "", + luma::keyboard_key_kind::BACKSPACE, + }, + }, + }, + }, + *input); BOOST_REQUIRE(keyboard); (*keyboard)->arrange({ .x = 0.0F, @@ -1128,8 +1148,9 @@ BOOST_AUTO_TEST_CASE(text_input_state_filters_modes_and_keyboard_updates_bound_f BOOST_AUTO_TEST_CASE(decimal_text_input_accepts_one_decimal_point) { auto input = luma::make_text_input({ - .mode = luma::text_input_mode::DECIMAL, - }, [](std::string) {}); + .mode = luma::text_input_mode::DECIMAL, + }, + [](std::string) {}); BOOST_REQUIRE(input); BOOST_REQUIRE((*input)->append("1.5")); BOOST_TEST(!(*input)->append(".")); @@ -1149,8 +1170,9 @@ BOOST_AUTO_TEST_CASE(text_input_callback_exceptions_return_errors) { BOOST_AUTO_TEST_CASE(text_input_state_notifies_bound_layout_invalidator) { auto input = luma::make_text_input({ - .text = "a", - }, [](std::string) {}); + .text = "a", + }, + [](std::string) {}); BOOST_REQUIRE(input); auto field = luma::text_field(*input); BOOST_REQUIRE(field); @@ -1171,8 +1193,9 @@ BOOST_AUTO_TEST_CASE(text_input_state_notifies_bound_layout_invalidator) { BOOST_AUTO_TEST_CASE(text_field_layout_invalidator_propagates_through_containers) { auto input = luma::make_text_input({ - .text = "a", - }, [](std::string) {}); + .text = "a", + }, + [](std::string) {}); BOOST_REQUIRE(input); auto field = luma::text_field(*input); BOOST_REQUIRE(field); @@ -1193,7 +1216,7 @@ BOOST_AUTO_TEST_CASE(dialog_accept_and_cancel_close_with_callbacks) { BOOST_REQUIRE(root); auto host_result = luma::overlays(std::move(*root)); BOOST_REQUIRE(host_result); - auto& host = **host_result; + auto &host = **host_result; host.arrange({ .x = 0.0F, .y = 0.0F, @@ -1249,7 +1272,7 @@ BOOST_AUTO_TEST_CASE(dialog_uses_matching_touch_when_not_first_point) { BOOST_REQUIRE(root); auto host_result = luma::overlays(std::move(*root)); BOOST_REQUIRE(host_result); - auto& host = **host_result; + auto &host = **host_result; host.arrange({ .x = 0.0F, .y = 0.0F, @@ -1292,12 +1315,12 @@ BOOST_AUTO_TEST_CASE(dialog_body_receives_touches) { BOOST_REQUIRE(root); auto host_result = luma::overlays(std::move(*root)); BOOST_REQUIRE(host_result); - auto& host = **host_result; + auto &host = **host_result; auto body = std::make_unique(luma::size{ .width = 100.0F, .height = 100.0F, }); - auto* body_ptr = body.get(); + auto *body_ptr = body.get(); BOOST_REQUIRE(host.show_dialog({ .title = "Title", .body = std::move(body), @@ -1338,7 +1361,7 @@ BOOST_AUTO_TEST_CASE(dialog_body_can_close_dialog_from_forwarded_methods_without BOOST_REQUIRE(root); auto host_result = luma::overlays(std::move(*root)); BOOST_REQUIRE(host_result); - auto& host = **host_result; + auto &host = **host_result; auto state = std::make_shared(); auto body = std::make_unique(host, state, phase); BOOST_REQUIRE(host.show_dialog({ @@ -1347,11 +1370,11 @@ BOOST_AUTO_TEST_CASE(dialog_body_can_close_dialog_from_forwarded_methods_without })); if (phase == close_phase::MEASURE) { host.measure(context, theme, { - .max = { - .width = 1000.0F, - .height = 600.0F, - }, - }); + .max = { + .width = 1000.0F, + .height = 600.0F, + }, + }); } else if (phase == close_phase::ARRANGE) { host.arrange({ .x = 0.0F, @@ -1398,16 +1421,17 @@ BOOST_AUTO_TEST_CASE(dialog_body_can_close_dialog_from_forwarded_methods_without BOOST_AUTO_TEST_CASE(window_manager_captures_touch_by_id) { auto manager = luma::window_manager{}; auto content = std::make_unique(); - auto* content_ptr = content.get(); + auto *content_ptr = content.get(); auto id = manager.open({ - .title = "Tool", - .bounds = { - .x = 100.0F, - .y = 100.0F, - .width = 100.0F, - .height = 100.0F, - }, - }, std::move(content)); + .title = "Tool", + .bounds = { + .x = 100.0F, + .y = 100.0F, + .width = 100.0F, + .height = 100.0F, + }, + }, + std::move(content)); BOOST_REQUIRE(id); BOOST_TEST(*id != 0U); BOOST_TEST(manager.handle_touch({ @@ -1452,16 +1476,17 @@ BOOST_AUTO_TEST_CASE(window_manager_captures_touch_by_id) { BOOST_AUTO_TEST_CASE(window_set_bounds_validates_release_inputs) { auto manager = luma::window_manager{}; auto id = manager.open({ - .title = "Tool", - .bounds = { - .x = 100.0F, - .y = 100.0F, - .width = 100.0F, - .height = 100.0F, - }, - }, std::make_unique()); + .title = "Tool", + .bounds = { + .x = 100.0F, + .y = 100.0F, + .width = 100.0F, + .height = 100.0F, + }, + }, + std::make_unique()); BOOST_REQUIRE(id); - auto* window = manager.find(*id); + auto *window = manager.find(*id); BOOST_REQUIRE(window != nullptr); auto original = window->options().bounds; auto invalid = window->set_bounds({ @@ -1488,23 +1513,24 @@ BOOST_AUTO_TEST_CASE(window_manager_uses_decorated_client_area_for_content) { auto theme = luma::default_theme(); auto manager = luma::window_manager{}; auto content = std::make_unique(); - auto* content_ptr = content.get(); + auto *content_ptr = content.get(); auto id = manager.open({ - .title = "Tool", - .bounds = { - .x = 10.0F, - .y = 20.0F, - .width = 100.0F, - .height = 80.0F, - }, - }, std::move(content)); + .title = "Tool", + .bounds = { + .x = 10.0F, + .y = 20.0F, + .width = 100.0F, + .height = 80.0F, + }, + }, + std::move(content)); BOOST_REQUIRE(id); manager.measure(context, theme, { - .max = { - .width = 200.0F, - .height = 200.0F, - }, - }); + .max = { + .width = 200.0F, + .height = 200.0F, + }, + }); manager.arrange({ .x = 0.0F, .y = 0.0F, @@ -1532,23 +1558,24 @@ BOOST_AUTO_TEST_CASE(window_manager_uses_theme_body_line_height_for_decorated_ch theme.body.line_height = 60.0F; auto manager = luma::window_manager{}; auto content = std::make_unique(); - auto* content_ptr = content.get(); + auto *content_ptr = content.get(); auto id = manager.open({ - .title = "Tool", - .bounds = { - .x = 10.0F, - .y = 20.0F, - .width = 100.0F, - .height = 100.0F, - }, - }, std::move(content)); + .title = "Tool", + .bounds = { + .x = 10.0F, + .y = 20.0F, + .width = 100.0F, + .height = 100.0F, + }, + }, + std::move(content)); BOOST_REQUIRE(id); manager.measure(context, theme, { - .max = { - .width = 200.0F, - .height = 200.0F, - }, - }); + .max = { + .width = 200.0F, + .height = 200.0F, + }, + }); manager.arrange({ .x = 0.0F, .y = 0.0F, @@ -1573,67 +1600,69 @@ BOOST_AUTO_TEST_CASE(window_manager_skips_hidden_windows_during_measure) { .width = 20.0F, .height = 20.0F, }); - auto* content_ptr = content.get(); + auto *content_ptr = content.get(); auto id = manager.open({ - .title = "Tool", - .bounds = { - .x = 10.0F, - .y = 20.0F, - .width = 100.0F, - .height = 80.0F, - }, - .visible = false, - }, std::move(content)); + .title = "Tool", + .bounds = { + .x = 10.0F, + .y = 20.0F, + .width = 100.0F, + .height = 80.0F, + }, + .visible = false, + }, + std::move(content)); BOOST_REQUIRE(id); manager.measure(context, theme, { - .max = { - .width = 200.0F, - .height = 200.0F, - }, - }); + .max = { + .width = 200.0F, + .height = 200.0F, + }, + }); BOOST_TEST(content_ptr->measure_count == 0); BOOST_REQUIRE(manager.set_visible(*id, true)); manager.measure(context, theme, { - .max = { - .width = 200.0F, - .height = 200.0F, - }, - }); + .max = { + .width = 200.0F, + .height = 200.0F, + }, + }); BOOST_TEST(content_ptr->measure_count == 1); } BOOST_AUTO_TEST_CASE(window_manager_id_mutators_validate_and_update_windows) { auto manager = luma::window_manager{}; auto id = manager.open({ - .title = "Tool", - .bounds = { - .x = 100.0F, - .y = 100.0F, - .width = 100.0F, - .height = 100.0F, - }, - }, std::make_unique()); + .title = "Tool", + .bounds = { + .x = 100.0F, + .y = 100.0F, + .width = 100.0F, + .height = 100.0F, + }, + }, + std::make_unique()); BOOST_REQUIRE(id); BOOST_TEST(!manager.set_bounds(0, { - .x = 1.0F, - .y = 2.0F, - .width = 3.0F, - .height = 4.0F, - })); + .x = 1.0F, + .y = 2.0F, + .width = 3.0F, + .height = 4.0F, + })); BOOST_TEST(!manager.set_bounds(*id, { - .x = 1.0F, - .y = 2.0F, - .width = -3.0F, - .height = 4.0F, - })); + .x = 1.0F, + .y = 2.0F, + .width = -3.0F, + .height = 4.0F, + })); BOOST_REQUIRE(manager.set_bounds(*id, { - .x = 5.0F, - .y = 6.0F, - .width = 20.0F, - .height = 30.0F, - })); + .x = 5.0F, + .y = 6.0F, + .width = 20.0F, + .height = 30.0F, + })); BOOST_REQUIRE(manager.set_visible(*id, false)); - auto* window = manager.find(*id); + auto *window = manager.find(*id); BOOST_REQUIRE(window != nullptr); BOOST_TEST(window->options().bounds.x == 5.0F); BOOST_TEST(window->options().bounds.height == 30.0F); @@ -1643,27 +1672,29 @@ BOOST_AUTO_TEST_CASE(window_manager_id_mutators_validate_and_update_windows) { BOOST_AUTO_TEST_CASE(window_manager_find_pointer_is_stable_across_open_and_reorder) { auto manager = luma::window_manager{}; auto first = manager.open({ - .title = "First", - .bounds = { - .x = 0.0F, - .y = 0.0F, - .width = 10.0F, - .height = 10.0F, - }, - }, std::make_unique()); + .title = "First", + .bounds = { + .x = 0.0F, + .y = 0.0F, + .width = 10.0F, + .height = 10.0F, + }, + }, + std::make_unique()); BOOST_REQUIRE(first); - auto* first_ptr = manager.find(*first); + auto *first_ptr = manager.find(*first); BOOST_REQUIRE(first_ptr != nullptr); for (auto index = 0; index < 32; ++index) { auto opened = manager.open({ - .title = "Other", - .bounds = { - .x = static_cast(index + 20), - .y = 0.0F, - .width = 10.0F, - .height = 10.0F, - }, - }, std::make_unique()); + .title = "Other", + .bounds = { + .x = static_cast(index + 20), + .y = 0.0F, + .width = 10.0F, + .height = 10.0F, + }, + }, + std::make_unique()); BOOST_REQUIRE(opened); } BOOST_TEST(manager.find(*first) == first_ptr); @@ -1676,14 +1707,15 @@ BOOST_AUTO_TEST_CASE(window_manager_defers_reentrant_close_until_touch_returns) auto state = std::make_shared(); auto id = std::uint64_t{}; auto opened = manager.open({ - .title = "Tool", - .bounds = { - .x = 100.0F, - .y = 100.0F, - .width = 100.0F, - .height = 100.0F, - }, - }, std::make_unique(manager, id, state)); + .title = "Tool", + .bounds = { + .x = 100.0F, + .y = 100.0F, + .width = 100.0F, + .height = 100.0F, + }, + }, + std::make_unique(manager, id, state)); BOOST_REQUIRE(opened); id = *opened; BOOST_TEST(manager.handle_touch({ @@ -1709,14 +1741,15 @@ BOOST_AUTO_TEST_CASE(window_manager_defers_reentrant_close_until_invalidation_re auto state = std::make_shared(); auto id = std::uint64_t{}; auto opened = manager.open({ - .title = "Tool", - .bounds = { - .x = 100.0F, - .y = 100.0F, - .width = 100.0F, - .height = 100.0F, - }, - }, std::make_unique(manager, id, state)); + .title = "Tool", + .bounds = { + .x = 100.0F, + .y = 100.0F, + .width = 100.0F, + .height = 100.0F, + }, + }, + std::make_unique(manager, id, state)); BOOST_REQUIRE(opened); id = *opened; manager.invalidate_layout(); @@ -1730,14 +1763,15 @@ BOOST_AUTO_TEST_CASE(window_manager_defers_reentrant_open_and_returns_reserved_i auto manager = luma::window_manager{}; auto state = std::make_shared(); auto opened = manager.open({ - .title = "Tool", - .bounds = { - .x = 100.0F, - .y = 100.0F, - .width = 100.0F, - .height = 100.0F, - }, - }, std::make_unique(manager, state)); + .title = "Tool", + .bounds = { + .x = 100.0F, + .y = 100.0F, + .width = 100.0F, + .height = 100.0F, + }, + }, + std::make_unique(manager, state)); BOOST_REQUIRE(opened); BOOST_TEST(manager.handle_touch({ .points = { @@ -1762,14 +1796,15 @@ BOOST_AUTO_TEST_CASE(window_manager_defers_reentrant_bounds_and_visibility_updat auto state = std::make_shared(); auto id = std::uint64_t{}; auto opened = manager.open({ - .title = "Tool", - .bounds = { - .x = 100.0F, - .y = 100.0F, - .width = 100.0F, - .height = 100.0F, - }, - }, std::make_unique(manager, id, state)); + .title = "Tool", + .bounds = { + .x = 100.0F, + .y = 100.0F, + .width = 100.0F, + .height = 100.0F, + }, + }, + std::make_unique(manager, id, state)); BOOST_REQUIRE(opened); id = *opened; BOOST_TEST(manager.handle_touch({ @@ -1786,7 +1821,7 @@ BOOST_AUTO_TEST_CASE(window_manager_defers_reentrant_bounds_and_visibility_updat })); BOOST_TEST(state->status_ok); BOOST_TEST(state->visible_during_callback); - auto* window = manager.find(id); + auto *window = manager.find(id); BOOST_REQUIRE(window != nullptr); BOOST_TEST(window->options().bounds.x == 5.0F); BOOST_TEST(window->options().bounds.height == 30.0F); @@ -1796,34 +1831,35 @@ BOOST_AUTO_TEST_CASE(window_manager_defers_reentrant_bounds_and_visibility_updat BOOST_AUTO_TEST_CASE(application_window_facade_validates_pre_run_calls) { auto app = luma::application{}; auto opened = app.open_window({ - .title = "Tool", - .bounds = { - .x = 100.0F, - .y = 100.0F, - .width = 100.0F, - .height = 100.0F, - }, - }, std::make_unique()); + .title = "Tool", + .bounds = { + .x = 100.0F, + .y = 100.0F, + .width = 100.0F, + .height = 100.0F, + }, + }, + std::make_unique()); BOOST_REQUIRE(opened); BOOST_REQUIRE(app.set_window_bounds(*opened, { - .x = 5.0F, - .y = 6.0F, - .width = 20.0F, - .height = 30.0F, - })); + .x = 5.0F, + .y = 6.0F, + .width = 20.0F, + .height = 30.0F, + })); BOOST_REQUIRE(app.set_window_visible(*opened, false)); BOOST_TEST(!app.set_window_bounds(0, { - .x = 5.0F, - .y = 6.0F, - .width = 20.0F, - .height = 30.0F, - })); + .x = 5.0F, + .y = 6.0F, + .width = 20.0F, + .height = 30.0F, + })); BOOST_TEST(!app.set_window_bounds(*opened, { - .x = 5.0F, - .y = 6.0F, - .width = -20.0F, - .height = 30.0F, - })); + .x = 5.0F, + .y = 6.0F, + .width = -20.0F, + .height = 30.0F, + })); } BOOST_AUTO_TEST_CASE(containers_route_simultaneous_touches_to_siblings) { @@ -1833,20 +1869,20 @@ BOOST_AUTO_TEST_CASE(containers_route_simultaneous_touches_to_siblings) { .width = 50.0F, .height = 50.0F, }); - auto* first_ptr = first.get(); + auto *first_ptr = first.get(); auto second = std::make_unique(luma::size{ .width = 50.0F, .height = 50.0F, }); - auto* second_ptr = second.get(); + auto *second_ptr = second.get(); auto control = luma::row(luma::children(modulus::success(std::unique_ptr{std::move(first)}), modulus::success(std::unique_ptr{std::move(second)})), 0.0F, luma::alignment::START); BOOST_REQUIRE(control); (*control)->measure(context, theme, { - .max = { - .width = 100.0F, - .height = 50.0F, - }, - }); + .max = { + .width = 100.0F, + .height = 50.0F, + }, + }); (*control)->arrange({ .x = 0.0F, .y = 0.0F, @@ -1884,20 +1920,20 @@ BOOST_AUTO_TEST_CASE(row_and_column_apply_cross_axis_alignment) { .width = 20.0F, .height = 10.0F, }); - auto* first_ptr = first.get(); + auto *first_ptr = first.get(); auto second = std::make_unique(luma::size{ .width = 20.0F, .height = 20.0F, }); - auto* second_ptr = second.get(); + auto *second_ptr = second.get(); auto row = luma::row(luma::children(modulus::success(std::unique_ptr{std::move(first)}), modulus::success(std::unique_ptr{std::move(second)})), 0.0F, luma::alignment::END); BOOST_REQUIRE(row); (*row)->measure(context, theme, { - .max = { - .width = 100.0F, - .height = 100.0F, - }, - }); + .max = { + .width = 100.0F, + .height = 100.0F, + }, + }); (*row)->arrange({ .x = 0.0F, .y = 0.0F, @@ -1910,15 +1946,15 @@ BOOST_AUTO_TEST_CASE(row_and_column_apply_cross_axis_alignment) { .width = 20.0F, .height = 10.0F, }); - auto* child_ptr = child.get(); + auto *child_ptr = child.get(); auto column = luma::column(luma::children(modulus::success(std::unique_ptr{std::move(child)})), 0.0F, luma::alignment::CENTER); BOOST_REQUIRE(column); (*column)->measure(context, theme, { - .max = { - .width = 100.0F, - .height = 100.0F, - }, - }); + .max = { + .width = 100.0F, + .height = 100.0F, + }, + }); (*column)->arrange({ .x = 0.0F, .y = 0.0F, @@ -1938,11 +1974,11 @@ BOOST_AUTO_TEST_CASE(panel_measure_includes_padding) { auto control = luma::panel(luma::children(modulus::success(std::unique_ptr{std::move(child)}))); BOOST_REQUIRE(control); auto measured = (*control)->measure(context, theme, { - .max = { - .width = 100.0F, - .height = 100.0F, - }, - }); + .max = { + .width = 100.0F, + .height = 100.0F, + }, + }); BOOST_TEST(measured.width == 36.0F); BOOST_TEST(measured.height == 26.0F); } @@ -1954,11 +1990,11 @@ BOOST_AUTO_TEST_CASE(scroll_view_uses_nested_clips) { auto outer = luma::scroll_view(std::move(inner)); BOOST_REQUIRE(outer); (*outer)->measure(context, theme, { - .max = { - .width = 100.0F, - .height = 100.0F, - }, - }); + .max = { + .width = 100.0F, + .height = 100.0F, + }, + }); (*outer)->arrange({ .x = 0.0F, .y = 0.0F, @@ -1979,11 +2015,11 @@ BOOST_AUTO_TEST_CASE(scroll_view_forwards_taps_to_child) { })); BOOST_REQUIRE(control); (*control)->measure(context, theme, { - .max = { - .width = 100.0F, - .height = 100.0F, - }, - }); + .max = { + .width = 100.0F, + .height = 100.0F, + }, + }); (*control)->arrange({ .x = 0.0F, .y = 0.0F, @@ -2022,15 +2058,15 @@ BOOST_AUTO_TEST_CASE(scroll_view_forwards_simultaneous_child_taps) { auto theme = luma::default_theme(); auto first_clicked = false; auto second_clicked = false; - auto content = luma::row(luma::children(luma::button("A", [&] {first_clicked = true;}), luma::button("B", [&] {second_clicked = true;})), 0.0F, luma::alignment::START); + auto content = luma::row(luma::children(luma::button("A", [&] { first_clicked = true; }), luma::button("B", [&] { second_clicked = true; })), 0.0F, luma::alignment::START); auto control = luma::scroll_view(std::move(content)); BOOST_REQUIRE(control); (*control)->measure(context, theme, { - .max = { - .width = 100.0F, - .height = 100.0F, - }, - }); + .max = { + .width = 100.0F, + .height = 100.0F, + }, + }); (*control)->arrange({ .x = 0.0F, .y = 0.0F, @@ -2090,11 +2126,11 @@ BOOST_AUTO_TEST_CASE(scroll_view_drag_suppresses_child_click) { })); BOOST_REQUIRE(control); (*control)->measure(context, theme, { - .max = { - .width = 100.0F, - .height = 100.0F, - }, - }); + .max = { + .width = 100.0F, + .height = 100.0F, + }, + }); (*control)->arrange({ .x = 0.0F, .y = 0.0F, @@ -2147,15 +2183,15 @@ BOOST_AUTO_TEST_CASE(scroll_view_allows_content_beyond_four_viewports) { .width = 20.0F, .height = 1000.0F, }); - auto* child_ptr = child.get(); + auto *child_ptr = child.get(); auto control = luma::scroll_view(std::unique_ptr{std::move(child)}); BOOST_REQUIRE(control); auto measured = (*control)->measure(context, theme, { - .max = { - .width = 100.0F, - .height = 100.0F, - }, - }); + .max = { + .width = 100.0F, + .height = 100.0F, + }, + }); BOOST_TEST(measured.height == 100.0F); (*control)->arrange({ .x = 0.0F, @@ -2203,22 +2239,22 @@ BOOST_AUTO_TEST_CASE(scroll_view_caches_measurement_and_rearranges_on_scroll_mov .width = 20.0F, .height = 1000.0F, }); - auto* child_ptr = child.get(); + auto *child_ptr = child.get(); auto control = luma::scroll_view(std::unique_ptr{std::move(child)}); BOOST_REQUIRE(control); auto measured = (*control)->measure(context, theme, { - .max = { - .width = 100.0F, - .height = 100.0F, - }, - }); + .max = { + .width = 100.0F, + .height = 100.0F, + }, + }); BOOST_TEST(measured.height == 100.0F); measured = (*control)->measure(context, theme, { - .max = { - .width = 100.0F, - .height = 100.0F, - }, - }); + .max = { + .width = 100.0F, + .height = 100.0F, + }, + }); BOOST_TEST(measured.height == 100.0F); BOOST_TEST(child_ptr->measure_count == 1); (*control)->arrange({ @@ -2255,11 +2291,11 @@ BOOST_AUTO_TEST_CASE(scroll_view_caches_measurement_and_rearranges_on_scroll_mov BOOST_TEST(child_ptr->arranged.y < 0.0F); (*control)->invalidate_layout(); measured = (*control)->measure(context, theme, { - .max = { - .width = 100.0F, - .height = 100.0F, - }, - }); + .max = { + .width = 100.0F, + .height = 100.0F, + }, + }); BOOST_TEST(measured.height == 100.0F); BOOST_TEST(child_ptr->measure_count == 2); BOOST_TEST(child_ptr->invalidate_count >= 1);