103 lines
2.9 KiB
C++
103 lines
2.9 KiB
C++
#include "StackPanel.hpp"
|
|
#include <functional>
|
|
#include <GUI_Paint.h>
|
|
|
|
//using namespace myink::ui;
|
|
|
|
void draw_background(const PositionalProperties & positionals, const Color & background_color);
|
|
void draw_border(const PositionalProperties positionals, const Color & color, const LineWidth & border_line_width);
|
|
|
|
StackPanel::StackPanel(const StackPanelStyleProperties & s, const DrawItemCallBackList & i, const MoveToNextItem & m): style(s), itmes(i), move(m)
|
|
{
|
|
}
|
|
|
|
StackPanel::~StackPanel()
|
|
{
|
|
}
|
|
|
|
PositionalProperties StackPanel::draw(const PositionalProperties & positionals) const
|
|
{
|
|
auto border_line_width = style.border_line_width;
|
|
auto margin = style.margin;
|
|
auto padding = style.padding;
|
|
auto inner_gap = border_line_width + padding;
|
|
auto gap = inner_gap + margin;
|
|
if (itmes.size == 0) {
|
|
PositionalProperties outer = {
|
|
positionals.left,
|
|
positionals.top,
|
|
positionals.width + 2 * (gap),
|
|
positionals.height + 2 * (gap)
|
|
};
|
|
draw_background(outer, style.background_color);
|
|
return outer;
|
|
}
|
|
|
|
PositionalProperties inner = {
|
|
positionals.left + gap,
|
|
positionals.top + gap,
|
|
0,
|
|
0
|
|
};
|
|
|
|
for(auto i = 0; i < itmes.size; i++) {
|
|
auto callback = itmes.callbacks[i];
|
|
auto last = callback(inner);
|
|
inner = move(inner, last);
|
|
}
|
|
|
|
auto out_distance = 2 * (gap + padding);
|
|
PositionalProperties outer = {
|
|
positionals.left,
|
|
positionals.top,
|
|
inner.width + out_distance,
|
|
inner.height + out_distance
|
|
};
|
|
|
|
if (border_line_width < 1)
|
|
{
|
|
return outer;
|
|
}
|
|
|
|
PositionalProperties border_positionals = {
|
|
positionals.left + padding,
|
|
positionals.top + padding,
|
|
inner.width + (2 * margin) + border_line_width,
|
|
inner.height + (2 * margin) + border_line_width
|
|
};
|
|
|
|
draw_border(border_positionals, style.border_line_color, border_line_width);
|
|
return outer;
|
|
}
|
|
|
|
PositionalProperties StackPanel::move_down(const PositionalProperties & i, const PositionalProperties & p)
|
|
{
|
|
return {
|
|
i.left,
|
|
i.top + p.height,
|
|
p.width > i.width ? p.width : i.width,
|
|
i.height + p.height
|
|
};
|
|
}
|
|
|
|
PositionalProperties StackPanel::move_right(const PositionalProperties & i, const PositionalProperties & p)
|
|
{
|
|
return {
|
|
i.left + p.width,
|
|
i.top,
|
|
i.width + p.width,
|
|
p.height > i.height ? p.height : i.height
|
|
};
|
|
}
|
|
|
|
void draw_background(const PositionalProperties & positionals, const Color & background_color)
|
|
{
|
|
Paint_ClearWindows(positionals.left, positionals.top, positionals.left + positionals.width, positionals.top + positionals.height, background_color);
|
|
}
|
|
|
|
void draw_border(const PositionalProperties p, const Color & color, const LineWidth & border_line_width)
|
|
{
|
|
auto border_line_width_pixel = border_line_width > 8 ? DOT_PIXEL::DOT_PIXEL_8X8 : DOT_PIXEL(border_line_width);
|
|
Paint_DrawRectangle(p.left, p.top, p.left + p.width, p.top + p.height, color, border_line_width_pixel, DRAW_FILL_EMPTY);
|
|
}
|