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
|
@ -1,9 +1,11 @@
|
|||
#include "HorizontalSpacer.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <numeric>
|
||||
|
||||
HorizontalSpacer::HorizontalSpacer()
|
||||
: Widget()
|
||||
: Widget(),
|
||||
mScales()
|
||||
{
|
||||
|
||||
}
|
||||
|
@ -13,18 +15,42 @@ std::unique_ptr<HorizontalSpacer> HorizontalSpacer::Create()
|
|||
return std::make_unique<HorizontalSpacer>();
|
||||
}
|
||||
|
||||
void HorizontalSpacer::AddWidget(WidgetUPtr widget)
|
||||
{
|
||||
AddWidgetWithScale(std::move(widget), 1.0);
|
||||
}
|
||||
|
||||
void HorizontalSpacer::AddWidgetWithScale(WidgetUPtr widget, double scale)
|
||||
{
|
||||
Widget::AddWidget(std::move(widget));
|
||||
mScales.push_back(scale);
|
||||
}
|
||||
|
||||
void HorizontalSpacer::AddChildLayers(const PaintEvent* event)
|
||||
{
|
||||
mLayers.clear();
|
||||
unsigned delta = mHeight / mChildren.size();
|
||||
double scaleSum = std::accumulate(mScales.begin(), mScales.end(), 0.0);
|
||||
double offset = 0;
|
||||
double height = mHeight;
|
||||
if (mMaxHeight > 0 && height > mMaxHeight)
|
||||
{
|
||||
height = mMaxHeight;
|
||||
}
|
||||
for(std::size_t idx=0; idx<mChildren.size(); idx++)
|
||||
{
|
||||
auto& child = mChildren[idx];
|
||||
double scale = mScales[idx];
|
||||
double delta = height * (scale/scaleSum);
|
||||
if (child->GetMaxHeight() > 0 && delta > child->GetMaxHeight())
|
||||
{
|
||||
delta = child->GetMaxHeight();
|
||||
}
|
||||
child->SetSize(mWidth, delta);
|
||||
child->SetLocation(DiscretePoint(mLocation.GetX(), mLocation.GetY() + delta*idx));
|
||||
child->SetLocation(DiscretePoint(mLocation.GetX(), mLocation.GetY() + offset));
|
||||
child->OnPaintEvent(event);
|
||||
auto layers = child->GetLayers();
|
||||
mLayers.insert(mLayers.end(), layers.begin(), layers.end());
|
||||
offset += delta;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue