1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2024-12-28 00:15:06 +00:00
OpenMW/components/widgets/windowcaption.cpp
2022-09-22 21:35:26 +03:00

60 lines
1.4 KiB
C++

#include "windowcaption.hpp"
#include <stdexcept>
namespace Gui
{
WindowCaption::WindowCaption()
: mLeft(nullptr)
, mRight(nullptr)
, mClient(nullptr)
{
}
void WindowCaption::initialiseOverride()
{
Base::initialiseOverride();
assignWidget(mLeft, "Left");
assignWidget(mRight, "Right");
assignWidget(mClient, "Client");
if (!mClient)
throw std::runtime_error("WindowCaption needs an EditBox Client widget in its skin");
}
void WindowCaption::setCaption(const MyGUI::UString& _value)
{
EditBox::setCaption(_value);
align();
}
void WindowCaption::setSize(const MyGUI::IntSize& _value)
{
Base::setSize(_value);
align();
}
void WindowCaption::setCoord(const MyGUI::IntCoord& _value)
{
Base::setCoord(_value);
align();
}
void WindowCaption::align()
{
MyGUI::IntSize textSize = getTextSize();
MyGUI::Widget* caption = mClient;
caption->setSize(textSize.width + 24, caption->getHeight());
int barwidth = (getWidth() - caption->getWidth()) / 2;
caption->setPosition(barwidth, caption->getTop());
if (mLeft)
mLeft->setCoord(0, mLeft->getTop(), barwidth, mLeft->getHeight());
if (mRight)
mRight->setCoord(barwidth + caption->getWidth(), mRight->getTop(), barwidth, mRight->getHeight());
}
}