Implement LayoutOrder getter and setter on VerticalListLayout and HorizontalListLayout
This commit is contained in:
@@ -29,62 +29,31 @@ namespace JUI
|
||||
enum class V { TOP, BOTTOM };
|
||||
}
|
||||
|
||||
/// Lays child elements out in a vertical descending list.
|
||||
/// Child element positions are overriden by this widget.
|
||||
/// Lays child elements out in a vertical list.
|
||||
/// Child element positions are overridden by this widget.
|
||||
class VerticalListLayout : public ListLayout
|
||||
{
|
||||
public:
|
||||
VerticalListLayout();
|
||||
explicit VerticalListLayout(Widget* parent);
|
||||
|
||||
void ApplyLayout() override
|
||||
{
|
||||
int consumed_height = 0;
|
||||
for (auto& child_widget : children)
|
||||
{
|
||||
// TODO: Implement widget.LayoutOrder property
|
||||
// TODO: Sort children by LayoutOrder
|
||||
consumed_height += pad_top.Pixels;
|
||||
child_widget->Position({0, consumed_height, 0, 0});
|
||||
consumed_height += child_widget->GetAbsoluteSize().y;
|
||||
consumed_height += pad_bottom.Pixels;
|
||||
}
|
||||
}
|
||||
void ApplyLayout() override;
|
||||
void LayoutOrder(LayoutOrder::V order);
|
||||
[[nodiscard]] LayoutOrder::V LayoutOrder() const;
|
||||
protected:
|
||||
LayoutOrder::V layout = LayoutOrder::V::TOP;
|
||||
};
|
||||
|
||||
/// Lays child elements out in a horizontal list.
|
||||
/// Child element positions are overridden by this widget.
|
||||
class HorizontalListLayout : public ListLayout
|
||||
{
|
||||
public:
|
||||
HorizontalListLayout();
|
||||
explicit HorizontalListLayout(Widget* parent);
|
||||
void ApplyLayout() override
|
||||
{
|
||||
// TODO: Implement widget.LayoutOrder and sort by that number.
|
||||
|
||||
if (layout == LayoutOrder::H::LEFT)
|
||||
{
|
||||
int consumed_width = 0;
|
||||
for (auto &child_widget : children)
|
||||
{
|
||||
consumed_width += pad_left.Pixels;
|
||||
child_widget->Position({consumed_width, 0, 0, 0});
|
||||
consumed_width += child_widget->GetAbsoluteSize().x;
|
||||
consumed_width += pad_right.Pixels;
|
||||
}
|
||||
}
|
||||
|
||||
if (layout == LayoutOrder::H::RIGHT)
|
||||
{
|
||||
int consumed_width = this->GetAbsoluteSize().x;
|
||||
for (auto &child_widget : children)
|
||||
{
|
||||
consumed_width -= pad_left.Pixels;
|
||||
child_widget->Position({consumed_width, 0, 0, 0});
|
||||
consumed_width -= child_widget->GetAbsoluteSize().x;
|
||||
consumed_width -= pad_right.Pixels;
|
||||
}
|
||||
}
|
||||
}
|
||||
void ApplyLayout() override;
|
||||
void LayoutOrder(LayoutOrder::H order);
|
||||
[[nodiscard]] LayoutOrder::H LayoutOrder() const;
|
||||
protected:
|
||||
LayoutOrder::H layout = LayoutOrder::H::LEFT;
|
||||
};
|
||||
|
@@ -11,10 +11,84 @@ namespace JUI
|
||||
this->Parent(parent);
|
||||
}
|
||||
|
||||
void VerticalListLayout::ApplyLayout() {
|
||||
|
||||
if (layout == LayoutOrder::V::TOP)
|
||||
{
|
||||
int consumed_height = 0;
|
||||
for (auto& child_widget : children)
|
||||
{
|
||||
// TODO: Implement widget.LayoutOrder property
|
||||
// TODO: Sort children by LayoutOrder
|
||||
consumed_height += pad_top.Pixels;
|
||||
child_widget->Position({0, consumed_height, 0, 0});
|
||||
consumed_height += child_widget->GetAbsoluteSize().y;
|
||||
consumed_height += pad_bottom.Pixels;
|
||||
}
|
||||
}
|
||||
|
||||
if (layout == LayoutOrder::V::BOTTOM)
|
||||
{
|
||||
int consumed_height = this->GetAbsoluteSize().y;
|
||||
for (auto& child_widget : children)
|
||||
{
|
||||
// TODO: Implement widget.LayoutOrder property
|
||||
// TODO: Sort children by LayoutOrder
|
||||
consumed_height -= pad_top.Pixels;
|
||||
consumed_height -= child_widget->GetAbsoluteSize().y;
|
||||
child_widget->Position({0, consumed_height, 0, 0});
|
||||
consumed_height -= pad_bottom.Pixels;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void VerticalListLayout::LayoutOrder(LayoutOrder::V order) {
|
||||
layout = order;
|
||||
}
|
||||
|
||||
LayoutOrder::V VerticalListLayout::LayoutOrder() const { return layout;}
|
||||
|
||||
HorizontalListLayout::HorizontalListLayout() : ListLayout() {}
|
||||
|
||||
|
||||
HorizontalListLayout::HorizontalListLayout(Widget* parent) : HorizontalListLayout() {
|
||||
Parent(parent);
|
||||
}
|
||||
|
||||
void HorizontalListLayout::ApplyLayout() {
|
||||
// TODO: Implement widget.LayoutOrder and sort by that number.
|
||||
|
||||
if (layout == LayoutOrder::H::LEFT)
|
||||
{
|
||||
int consumed_width = 0;
|
||||
for (auto &child_widget : children)
|
||||
{
|
||||
consumed_width += pad_left.Pixels;
|
||||
child_widget->Position({consumed_width, 0, 0, 0});
|
||||
consumed_width += child_widget->GetAbsoluteSize().x;
|
||||
consumed_width += pad_right.Pixels;
|
||||
}
|
||||
}
|
||||
|
||||
if (layout == LayoutOrder::H::RIGHT)
|
||||
{
|
||||
int consumed_width = this->GetAbsoluteSize().x;
|
||||
for (auto &child_widget : children)
|
||||
{
|
||||
consumed_width -= pad_left.Pixels;
|
||||
consumed_width -= child_widget->GetAbsoluteSize().x;
|
||||
child_widget->Position({consumed_width, 0, 0, 0});
|
||||
consumed_width -= pad_right.Pixels;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void HorizontalListLayout::LayoutOrder(LayoutOrder::H order) {
|
||||
layout = order;
|
||||
}
|
||||
|
||||
LayoutOrder::H HorizontalListLayout::LayoutOrder() const {
|
||||
return layout;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user