corrected code style

This commit is contained in:
2026-03-16 01:54:45 +03:00
parent 1744172694
commit 6487554844
5 changed files with 174 additions and 87 deletions

View File

@@ -12,6 +12,7 @@ AlignConsecutiveMacros: AcrossEmptyLinesAndComments
AlignTrailingComments: false
AllowShortBlocksOnASingleLine: Never
AllowShortFunctionsOnASingleLine: None
AllowShortLambdasOnASingleLine: None
AllowShortIfStatementsOnASingleLine: false
AllowShortLoopsOnASingleLine: false
BreakTemplateDeclarations: Leave

View File

@@ -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),

View File

@@ -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<float>& position, const Color& color, const std::string_view& text);
void draw_dashed_line(const Vector2<float>& from, const Vector2<float>& to, const Color& color, float dash_len,
float gap_len, float thickness) const;

View File

@@ -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<W>;
// ── 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<None, Bar, DashedBar, Label, Centered<Label>>;
// ── 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<SideWidget> children; RightSide(std::initializer_list<SideWidget> c) : children(c) {} };
struct LeftSide { std::initializer_list<SideWidget> children; LeftSide(std::initializer_list<SideWidget> c) : children(c) {} };
struct TopSide { std::initializer_list<SideWidget> children; TopSide(std::initializer_list<SideWidget> c) : children(c) {} };
struct BottomSide { std::initializer_list<SideWidget> children; BottomSide(std::initializer_list<SideWidget> c) : children(c) {} };
struct RightSide
{
std::initializer_list<SideWidget> children;
RightSide(const std::initializer_list<SideWidget> c): children(c)
{
}
};
struct LeftSide
{
std::initializer_list<SideWidget> children;
LeftSide(const std::initializer_list<SideWidget> c): children(c)
{
}
};
struct TopSide
{
std::initializer_list<SideWidget> children;
TopSide(const std::initializer_list<SideWidget> c): children(c)
{
}
};
struct BottomSide
{
std::initializer_list<SideWidget> children;
BottomSide(const std::initializer_list<SideWidget> 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<typename W>
requires std::constructible_from<SideWidget, W>
requires std::constructible_from<SideWidget, W>
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<typename W>
std::optional<W> when(const bool condition, W widget)
{
if (condition) return std::move(widget);
if (condition)
return std::move(widget);
return std::nullopt;
}
} // namespace omath::hud

View File

@@ -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<widget::Label>& 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<widget::Label>& 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<widget::Label>& 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<widget::Label>& 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<widget::Label>& 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<widget::Label>& 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<widget::Label>& 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<widget::Label>& w)
{
add_centered_bottom_label(w.child.color, w.child.offset, w.child.outlined,
w.child.text);
},
},
child);
}
} // namespace omath::hud