overlays/utils: Add simple utility to center align a child component

This commit is contained in:
kd-11 2026-03-15 20:08:22 +03:00 committed by kd-11
parent 198fe71cc4
commit 281706fdae
2 changed files with 24 additions and 0 deletions

View file

@ -684,6 +684,20 @@ namespace rsx
width = static_cast<u16>(ceilf(max_w));
}
u16 overlay_element::compute_vertically_centered(u16 element_height)
{
const u16 half_height = h / 2;
const u16 element_half_height = element_height / 2;
return std::max(half_height, element_half_height) - element_half_height;
}
u16 overlay_element::compute_horizontally_centered(u16 element_width)
{
const u16 half_width = h / 2;
const u16 element_half_width = element_width / 2;
return std::max(half_width, element_half_width) - element_half_width;
}
layout_container::layout_container()
{
// Transparent by default

View file

@ -224,6 +224,16 @@ namespace rsx
virtual void set_visible(bool visible) { this->visible = visible; m_is_compiled = false; }
virtual bool is_visible() const { return visible; }
// Calculate the vertical offset for an element of height Y if it were to be placed as a child of this element
u16 compute_vertically_centered(u16 element_height);
// Calculate the horizontal offset for an element of width X if it were to be placed as a child of this element
u16 compute_horizontally_centered(u16 element_width);
// Wrappers for the placement functions
u16 compute_vertically_centered(const overlay_element* other) { return compute_vertically_centered(other->h); }
u16 compute_horizontally_centered(const overlay_element* other) { return compute_horizontally_centered(other->w); }
protected:
bool m_is_compiled = false; // Only use m_is_compiled as a getter in is_compiled() if possible
};