overlays/utils: Add simple utility to center align a child component
This commit is contained in:
@@ -684,6 +684,20 @@ namespace rsx
|
|||||||
width = static_cast<u16>(ceilf(max_w));
|
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()
|
layout_container::layout_container()
|
||||||
{
|
{
|
||||||
// Transparent by default
|
// Transparent by default
|
||||||
|
|||||||
@@ -224,6 +224,16 @@ namespace rsx
|
|||||||
virtual void set_visible(bool visible) { this->visible = visible; m_is_compiled = false; }
|
virtual void set_visible(bool visible) { this->visible = visible; m_is_compiled = false; }
|
||||||
virtual bool is_visible() const { return visible; }
|
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:
|
protected:
|
||||||
bool m_is_compiled = false; // Only use m_is_compiled as a getter in is_compiled() if possible
|
bool m_is_compiled = false; // Only use m_is_compiled as a getter in is_compiled() if possible
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user