From 64875548449513d6509734f123235f05d98e85fb Mon Sep 17 00:00:00 2001 From: Orange Date: Mon, 16 Mar 2026 01:54:45 +0300 Subject: [PATCH] corrected code style --- .clang-format | 1 + examples/example_hud/gui/main_window.cpp | 12 +- include/omath/hud/entity_overlay.hpp | 18 +- include/omath/hud/entity_overlay_widgets.hpp | 50 ++++-- source/hud/entity_overlay.cpp | 180 +++++++++++++------ 5 files changed, 174 insertions(+), 87 deletions(-) diff --git a/.clang-format b/.clang-format index 0d5d0d4..5da3e77 100644 --- a/.clang-format +++ b/.clang-format @@ -12,6 +12,7 @@ AlignConsecutiveMacros: AcrossEmptyLinesAndComments AlignTrailingComments: false AllowShortBlocksOnASingleLine: Never AllowShortFunctionsOnASingleLine: None +AllowShortLambdasOnASingleLine: None AllowShortIfStatementsOnASingleLine: false AllowShortLoopsOnASingleLine: false BreakTemplateDeclarations: Leave diff --git a/examples/example_hud/gui/main_window.cpp b/examples/example_hud/gui/main_window.cpp index 6813cd1..05c022f 100644 --- a/examples/example_hud/gui/main_window.cpp +++ b/examples/example_hud/gui/main_window.cpp @@ -167,8 +167,7 @@ namespace imgui_desktop::gui m_corner_ratio, m_box_thickness}), when(m_show_dashed_box, DashedBox{m_dash_color, m_dash_len, m_dash_gap, m_dash_thickness}), - RightSide - { + RightSide{ when(m_show_right_bar, bar), when(m_show_right_dashed_bar, dbar), when(m_show_right_labels, @@ -178,8 +177,7 @@ namespace imgui_desktop::gui when(m_show_right_labels, Label{{1.f, 0.f, 1.f, 1.f}, m_label_offset, m_outlined, "*LOCKED*"}), }, - LeftSide - { + LeftSide{ when(m_show_left_bar, bar), when(m_show_left_dashed_bar, dbar), when(m_show_left_labels, Label{omath::Color::from_rgba(255, 128, 0, 255), @@ -187,8 +185,7 @@ namespace imgui_desktop::gui when(m_show_left_labels, Label{omath::Color::from_rgba(0, 200, 255, 255), m_label_offset, m_outlined, "Level: 42"}), }, - TopSide - { + TopSide{ when(m_show_top_bar, bar), when(m_show_top_dashed_bar, dbar), when(m_show_centered_top, Centered{Label{omath::Color::from_rgba(0, 255, 255, 255), @@ -198,8 +195,7 @@ namespace imgui_desktop::gui when(m_show_top_labels, Label{omath::Color::from_rgba(255, 0, 0, 255), m_label_offset, m_outlined, "*BLEEDING*"}), }, - BottomSide - { + BottomSide{ when(m_show_bottom_bar, bar), when(m_show_bottom_dashed_bar, dbar), when(m_show_centered_bottom, Centered{Label{omath::Color::from_rgba(255, 255, 255, 255), diff --git a/include/omath/hud/entity_overlay.hpp b/include/omath/hud/entity_overlay.hpp index 5de3c19..ef5492c 100644 --- a/include/omath/hud/entity_overlay.hpp +++ b/include/omath/hud/entity_overlay.hpp @@ -142,15 +142,15 @@ namespace omath::hud dispatch(*w); } - void dispatch(const widget::Box& w); - void dispatch(const widget::CorneredBox& w); - void dispatch(const widget::DashedBox& w); - void dispatch(const widget::RightSide& w); - void dispatch(const widget::LeftSide& w); - void dispatch(const widget::TopSide& w); - void dispatch(const widget::BottomSide& w); - void dispatch(const widget::Skeleton& w); - void dispatch(const widget::SnapLine& w); + void dispatch(const widget::Box& box); + void dispatch(const widget::CorneredBox& cornered_box); + void dispatch(const widget::DashedBox& dashed_box); + void dispatch(const widget::RightSide& right_side); + void dispatch(const widget::LeftSide& left_side); + void dispatch(const widget::TopSide& top_side); + void dispatch(const widget::BottomSide& bottom_side); + void dispatch(const widget::Skeleton& skeleton); + void dispatch(const widget::SnapLine& snap_line); void draw_outlined_text(const Vector2& position, const Color& color, const std::string_view& text); void draw_dashed_line(const Vector2& from, const Vector2& to, const Color& color, float dash_len, float gap_len, float thickness) const; diff --git a/include/omath/hud/entity_overlay_widgets.hpp b/include/omath/hud/entity_overlay_widgets.hpp index 0cf8e47..0a4b3e6 100644 --- a/include/omath/hud/entity_overlay_widgets.hpp +++ b/include/omath/hud/entity_overlay_widgets.hpp @@ -84,9 +84,9 @@ namespace omath::hud::widget struct Label { - Color color; - float offset; - bool outlined; + Color color; + float offset; + bool outlined; std::string_view text; }; @@ -100,7 +100,9 @@ namespace omath::hud::widget Centered(W) -> Centered; // ── Side widget variant ─────────────────────────────────────────────────── - struct None {}; ///< No-op placeholder — used by widget::when for disabled elements. + struct None + { + }; ///< No-op placeholder — used by widget::when for disabled elements. using SideWidget = std::variant>; // ── Side containers ─────────────────────────────────────────────────────── @@ -109,10 +111,34 @@ namespace omath::hud::widget // temporary side-container object, which is consumed within the same // full-expression by EntityOverlay::dispatch. No heap allocation occurs. - struct RightSide { std::initializer_list children; RightSide(std::initializer_list c) : children(c) {} }; - struct LeftSide { std::initializer_list children; LeftSide(std::initializer_list c) : children(c) {} }; - struct TopSide { std::initializer_list children; TopSide(std::initializer_list c) : children(c) {} }; - struct BottomSide { std::initializer_list children; BottomSide(std::initializer_list c) : children(c) {} }; + struct RightSide + { + std::initializer_list children; + RightSide(const std::initializer_list c): children(c) + { + } + }; + struct LeftSide + { + std::initializer_list children; + LeftSide(const std::initializer_list c): children(c) + { + } + }; + struct TopSide + { + std::initializer_list children; + TopSide(const std::initializer_list c): children(c) + { + } + }; + struct BottomSide + { + std::initializer_list children; + BottomSide(const std::initializer_list c): children(c) + { + } + }; } // namespace omath::hud::widget @@ -121,10 +147,11 @@ namespace omath::hud::widget /// Inside XxxSide containers: returns the widget as a SideWidget when condition is true, /// or None{} otherwise. Preferred over hud::when for types inside the SideWidget variant. template - requires std::constructible_from + requires std::constructible_from SideWidget when(const bool condition, W widget) { - if (condition) return SideWidget{std::move(widget)}; + if (condition) + return SideWidget{std::move(widget)}; return None{}; } } // namespace omath::hud::widget @@ -136,7 +163,8 @@ namespace omath::hud template std::optional when(const bool condition, W widget) { - if (condition) return std::move(widget); + if (condition) + return std::move(widget); return std::nullopt; } } // namespace omath::hud diff --git a/source/hud/entity_overlay.cpp b/source/hud/entity_overlay.cpp index 05f6315..1165136 100644 --- a/source/hud/entity_overlay.cpp +++ b/source/hud/entity_overlay.cpp @@ -458,84 +458,146 @@ namespace omath::hud { } // ── widget dispatch ─────────────────────────────────────────────────────── - void EntityOverlay::dispatch(const widget::Box& w) - { add_2d_box(w.color, w.fill, w.thickness); } + void EntityOverlay::dispatch(const widget::Box& box) + { + add_2d_box(box.color, box.fill, box.thickness); + } - void EntityOverlay::dispatch(const widget::CorneredBox& w) - { add_cornered_2d_box(w.color, w.fill, w.corner_ratio, w.thickness); } + void EntityOverlay::dispatch(const widget::CorneredBox& cornered_box) + { + add_cornered_2d_box(cornered_box.color, cornered_box.fill, cornered_box.corner_ratio, cornered_box.thickness); + } - void EntityOverlay::dispatch(const widget::DashedBox& w) - { add_dashed_box(w.color, w.dash_len, w.gap_len, w.thickness); } + void EntityOverlay::dispatch(const widget::DashedBox& dashed_box) + { + add_dashed_box(dashed_box.color, dashed_box.dash_len, dashed_box.gap_len, dashed_box.thickness); + } - void EntityOverlay::dispatch(const widget::Skeleton& w) - { add_skeleton(w.color, w.thickness); } + void EntityOverlay::dispatch(const widget::Skeleton& skeleton) + { + add_skeleton(skeleton.color, skeleton.thickness); + } - void EntityOverlay::dispatch(const widget::SnapLine& w) - { add_snap_line(w.start, w.color, w.width); } + void EntityOverlay::dispatch(const widget::SnapLine& snap_line) + { + add_snap_line(snap_line.start, snap_line.color, snap_line.width); + } // ── Side container dispatch ─────────────────────────────────────────────── void EntityOverlay::dispatch(const widget::RightSide& s) { for (const auto& child : s.children) - std::visit(widget::Overloaded{ - [](const widget::None&) {}, - [this](const widget::Bar& w) - { add_right_bar(w.color, w.outline, w.bg, w.size, w.ratio, w.offset); }, - [this](const widget::DashedBar& w) - { add_right_dashed_bar(w.color, w.outline, w.bg, w.size, w.ratio, w.dash_len, w.gap_len, w.offset); }, - [this](const widget::Label& w) - { add_right_label(w.color, w.offset, w.outlined, w.text); }, - [this](const widget::Centered& w) - { add_right_label(w.child.color, w.child.offset, w.child.outlined, w.child.text); }, - }, child); + std::visit( + widget::Overloaded{ + [](const widget::None&) + { + }, + [this](const widget::Bar& w) + { + add_right_bar(w.color, w.outline, w.bg, w.size, w.ratio, w.offset); + }, + [this](const widget::DashedBar& w) + { + add_right_dashed_bar(w.color, w.outline, w.bg, w.size, w.ratio, w.dash_len, w.gap_len, + w.offset); + }, + [this](const widget::Label& w) + { + add_right_label(w.color, w.offset, w.outlined, w.text); + }, + [this](const widget::Centered& w) + { + add_right_label(w.child.color, w.child.offset, w.child.outlined, w.child.text); + }, + }, + child); } void EntityOverlay::dispatch(const widget::LeftSide& s) { for (const auto& child : s.children) - std::visit(widget::Overloaded{ - [](const widget::None&) {}, - [this](const widget::Bar& w) - { add_left_bar(w.color, w.outline, w.bg, w.size, w.ratio, w.offset); }, - [this](const widget::DashedBar& w) - { add_left_dashed_bar(w.color, w.outline, w.bg, w.size, w.ratio, w.dash_len, w.gap_len, w.offset); }, - [this](const widget::Label& w) - { add_left_label(w.color, w.offset, w.outlined, w.text); }, - [this](const widget::Centered& w) - { add_left_label(w.child.color, w.child.offset, w.child.outlined, w.child.text); }, - }, child); + std::visit( + widget::Overloaded{ + [](const widget::None&) + { + }, + [this](const widget::Bar& w) + { + add_left_bar(w.color, w.outline, w.bg, w.size, w.ratio, w.offset); + }, + [this](const widget::DashedBar& w) + { + add_left_dashed_bar(w.color, w.outline, w.bg, w.size, w.ratio, w.dash_len, w.gap_len, + w.offset); + }, + [this](const widget::Label& w) + { + add_left_label(w.color, w.offset, w.outlined, w.text); + }, + [this](const widget::Centered& w) + { + add_left_label(w.child.color, w.child.offset, w.child.outlined, w.child.text); + }, + }, + child); } - void EntityOverlay::dispatch(const widget::TopSide& s) + void EntityOverlay::dispatch(const widget::TopSide& top_side) { - for (const auto& child : s.children) - std::visit(widget::Overloaded{ - [](const widget::None&) {}, - [this](const widget::Bar& w) - { add_top_bar(w.color, w.outline, w.bg, w.size, w.ratio, w.offset); }, - [this](const widget::DashedBar& w) - { add_top_dashed_bar(w.color, w.outline, w.bg, w.size, w.ratio, w.dash_len, w.gap_len, w.offset); }, - [this](const widget::Label& w) - { add_top_label(w.color, w.offset, w.outlined, w.text); }, - [this](const widget::Centered& w) - { add_centered_top_label(w.child.color, w.child.offset, w.child.outlined, w.child.text); }, - }, child); + for (const auto& child : top_side.children) + std::visit( + widget::Overloaded{ + [](const widget::None&) + { + }, + [this](const widget::Bar& w) + { + add_top_bar(w.color, w.outline, w.bg, w.size, w.ratio, w.offset); + }, + [this](const widget::DashedBar& w) + { + add_top_dashed_bar(w.color, w.outline, w.bg, w.size, w.ratio, w.dash_len, w.gap_len, + w.offset); + }, + [this](const widget::Label& w) + { + add_top_label(w.color, w.offset, w.outlined, w.text); + }, + [this](const widget::Centered& w) + { + add_centered_top_label(w.child.color, w.child.offset, w.child.outlined, w.child.text); + }, + }, + child); } - - void EntityOverlay::dispatch(const widget::BottomSide& s) + void EntityOverlay::dispatch(const widget::BottomSide& bottom_side) { - for (const auto& child : s.children) - std::visit(widget::Overloaded{ - [](const widget::None&) {}, - [this](const widget::Bar& w) - { add_bottom_bar(w.color, w.outline, w.bg, w.size, w.ratio, w.offset); }, - [this](const widget::DashedBar& w) - { add_bottom_dashed_bar(w.color, w.outline, w.bg, w.size, w.ratio, w.dash_len, w.gap_len, w.offset); }, - [this](const widget::Label& w) - { add_bottom_label(w.color, w.offset, w.outlined, w.text); }, - [this](const widget::Centered& w) - { add_centered_bottom_label(w.child.color, w.child.offset, w.child.outlined, w.child.text); }, - }, child); + for (const auto& child : bottom_side.children) + std::visit( + widget::Overloaded{ + [](const widget::None&) + { + }, + [this](const widget::Bar& w) + { + add_bottom_bar(w.color, w.outline, w.bg, w.size, w.ratio, w.offset); + }, + [this](const widget::DashedBar& w) + { + add_bottom_dashed_bar(w.color, w.outline, w.bg, w.size, w.ratio, w.dash_len, w.gap_len, + w.offset); + }, + [this](const widget::Label& w) + { + add_bottom_label(w.color, w.offset, w.outlined, w.text); + }, + [this](const widget::Centered& w) + { + add_centered_bottom_label(w.child.color, w.child.offset, w.child.outlined, + w.child.text); + }, + }, + child); } } // namespace omath::hud \ No newline at end of file