init
This commit is contained in:
95
StackPanel.cpp
Normal file
95
StackPanel.cpp
Normal file
@@ -0,0 +1,95 @@
|
||||
#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);
|
||||
PositionalProperties move_down(const PositionalProperties & i, const PositionalProperties & p);
|
||||
PositionalProperties move_right(const PositionalProperties & i, const PositionalProperties & p);
|
||||
|
||||
StackPanel::StackPanel(const PositionalProperties & p, const StackPanelStyleProperties & s, const DrawItemCallBackList & i, const MoveToNextItem & m) : positionals(p), style(s), itmes(i), move(m)
|
||||
{
|
||||
}
|
||||
|
||||
StackPanel::~StackPanel()
|
||||
{
|
||||
}
|
||||
|
||||
void StackPanel::draw() 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;
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
if (border_line_width < 1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
Reference in New Issue
Block a user