Add some widget layout and ability event handling.
This commit is contained in:
parent
b99708e7d3
commit
4e85edacc8
24 changed files with 285 additions and 31 deletions
52
src/ui_elements/widgets/VerticalSpacer.cpp
Normal file
52
src/ui_elements/widgets/VerticalSpacer.cpp
Normal file
|
@ -0,0 +1,52 @@
|
|||
#include "VerticalSpacer.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <numeric>
|
||||
|
||||
VerticalSpacer::VerticalSpacer()
|
||||
: Widget(),
|
||||
mScales()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
std::unique_ptr<VerticalSpacer> VerticalSpacer::Create()
|
||||
{
|
||||
return std::make_unique<VerticalSpacer>();
|
||||
}
|
||||
|
||||
void VerticalSpacer::AddWidget(WidgetUPtr widget)
|
||||
{
|
||||
AddWidgetWithScale(std::move(widget), 1.0);
|
||||
}
|
||||
|
||||
void VerticalSpacer::AddWidgetWithScale(WidgetUPtr widget, double scale)
|
||||
{
|
||||
Widget::AddWidget(std::move(widget));
|
||||
mScales.push_back(scale);
|
||||
}
|
||||
|
||||
void VerticalSpacer::AddChildLayers(const PaintEvent* event)
|
||||
{
|
||||
mLayers.clear();
|
||||
double scaleSum = std::accumulate(mScales.begin(), mScales.end(), 0.0);
|
||||
double offset = 0;
|
||||
unsigned delta = mWidth / mChildren.size();
|
||||
for(std::size_t idx=0; idx<mChildren.size(); idx++)
|
||||
{
|
||||
auto& child = mChildren[idx];
|
||||
double scale = mScales[idx];
|
||||
double delta = mWidth * (scale/scaleSum);
|
||||
child->SetSize(delta, mHeight);
|
||||
child->SetLocation(DiscretePoint(mLocation.GetX() + offset, mLocation.GetY()));
|
||||
child->OnPaintEvent(event);
|
||||
auto layers = child->GetLayers();
|
||||
mLayers.insert(mLayers.end(), layers.begin(), layers.end());
|
||||
offset += delta;
|
||||
}
|
||||
}
|
||||
|
||||
void VerticalSpacer::OnPaintEvent(const PaintEvent* event)
|
||||
{
|
||||
AddChildLayers(event);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue