41 lines
1.1 KiB
C++
41 lines
1.1 KiB
C++
/**
|
|
* @file Alignment.cpp
|
|
* @author apio (cloudapio.eu)
|
|
* @brief UI component alignment.
|
|
*
|
|
* @copyright Copyright (c) 2023, the Luna authors.
|
|
*
|
|
*/
|
|
|
|
#include <ui/Alignment.h>
|
|
|
|
namespace ui
|
|
{
|
|
Rect align(Rect container, Rect contained, VerticalAlignment valign, HorizontalAlignment halign)
|
|
{
|
|
Rect result;
|
|
result.width = contained.width;
|
|
result.height = contained.height;
|
|
result.pos.y = container.pos.y;
|
|
result.pos.x = container.pos.x;
|
|
|
|
switch (valign)
|
|
{
|
|
case VerticalAlignment::Top: break;
|
|
case VerticalAlignment::Center: result.pos.y += (container.height - contained.height) / 2; break;
|
|
case VerticalAlignment::Bottom: result.pos.y += container.height - contained.height; break;
|
|
default: break;
|
|
}
|
|
|
|
switch (halign)
|
|
{
|
|
case HorizontalAlignment::Left: break;
|
|
case HorizontalAlignment::Center: result.pos.x += (container.width - contained.width) / 2; break;
|
|
case HorizontalAlignment::Right: result.pos.x += container.width - contained.width; break;
|
|
default: break;
|
|
}
|
|
|
|
return result;
|
|
}
|
|
}
|