Implement HorizontalListLayout and VerticalListLayout widgets
This commit is contained in:
@@ -24,10 +24,10 @@ namespace JUI
|
||||
public:
|
||||
LayoutContainer();
|
||||
LayoutContainer(Widget* parent);
|
||||
~LayoutContainer() override;
|
||||
~LayoutContainer() override {}
|
||||
void Update(float delta) override;
|
||||
void Draw() override;
|
||||
virtual void ApplyLayout();
|
||||
virtual void ApplyLayout() = 0;
|
||||
|
||||
Vector2 GetAbsoluteSize() const override { return parent->GetAbsoluteSize(); }
|
||||
Vector2 GetAbsolutePosition() const override { return parent->GetAbsolutePosition(); }
|
||||
|
@@ -19,18 +19,72 @@ namespace JUI
|
||||
class ListLayout : public LayoutContainer
|
||||
{
|
||||
public:
|
||||
|
||||
ListLayout();
|
||||
explicit ListLayout(Widget* parent);
|
||||
~ListLayout() override {}
|
||||
};
|
||||
|
||||
namespace LayoutOrder
|
||||
{
|
||||
enum class H { LEFT, RIGHT };
|
||||
enum class V { TOP, BOTTOM };
|
||||
}
|
||||
|
||||
/// Lays child elements out in a vertical descending list.
|
||||
/// Child element positions are overriden 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->SetPosition({0, consumed_height, 0, 0});
|
||||
consumed_height += child_widget->GetAbsoluteSize().y;
|
||||
consumed_height += pad_bottom.Pixels;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
class HorizontalListLayout : public ListLayout
|
||||
{
|
||||
public:
|
||||
HorizontalListLayout();
|
||||
explicit HorizontalListLayout(Widget* parent);
|
||||
void ApplyLayout() override
|
||||
{
|
||||
if (layout == LayoutOrder::H::LEFT)
|
||||
{
|
||||
int consumed_width = 0;
|
||||
for (auto &child_widget : children)
|
||||
{
|
||||
consumed_width += pad_left.Pixels;
|
||||
child_widget->SetPosition({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->SetPosition({consumed_width, 0, 0, 0});
|
||||
consumed_width -= child_widget->GetAbsoluteSize().x;
|
||||
consumed_width -= pad_right.Pixels;
|
||||
}
|
||||
}
|
||||
}
|
||||
protected:
|
||||
LayoutOrder::H layout = LayoutOrder::H::LEFT;
|
||||
};
|
||||
}
|
@@ -14,14 +14,14 @@
|
||||
#include <JUI/Base/Widget.hpp>
|
||||
|
||||
/** Rich-Text Markup specification (Totally not stolen from ROBLOX)
|
||||
Color: I want the <color="#FF6600>orange</color> candy.
|
||||
Size: <size="40">This is big</size> This is small.
|
||||
Font: <font="JetBrains Mono">class RichText.hpp { }; </font>
|
||||
Weight: <weight="heavy">Heavy</stroke> <weight="900">Extra Heavy</stroke>
|
||||
Bold: Text in <b>bold</b>
|
||||
Italic: <i>Italicized</i>
|
||||
Underline: <u>Underline</u>
|
||||
Strikethrough: <s>Strikethrough</s>
|
||||
Color: I want the <color="#FF6600>orange</color> candy.
|
||||
Size: <size="40">This is big</size> This is small.
|
||||
Font: <font="JetBrains Mono">class RichText.hpp { }; </font>
|
||||
Weight: <weight="heavy">Heavy</stroke> <weight="900">Extra Heavy</stroke>
|
||||
Bold: Text in <b>bold</b>
|
||||
Italic: <i>Italicized</i>
|
||||
Underline: <u>Underline</u>
|
||||
Strikethrough: <s>Strikethrough</s>
|
||||
|
||||
Escape Forms
|
||||
< <
|
||||
@@ -34,7 +34,6 @@
|
||||
namespace RichTextFormat
|
||||
{
|
||||
|
||||
|
||||
class RichTextToken
|
||||
{
|
||||
public:
|
||||
@@ -49,7 +48,6 @@ namespace RichTextFormat
|
||||
bool strikethrough;
|
||||
};
|
||||
|
||||
|
||||
class RichTextSequence
|
||||
{
|
||||
public:
|
||||
|
28
main.cpp
28
main.cpp
@@ -11,11 +11,13 @@
|
||||
|
||||
#include <iostream>
|
||||
#include <JGL/JGL.h>
|
||||
#include "JUI/Widgets/Rect.hpp"
|
||||
#include "JUI/Widgets/RadioButton.hpp"
|
||||
#include "JUI/Widgets/Window.hpp"
|
||||
#include "JUI/Widgets/Scene.hpp"
|
||||
#include "JUI/Widgets/Text.hpp"
|
||||
#include <JUI/Widgets/Rect.hpp>
|
||||
#include <JUI/Widgets/RadioButton.hpp>
|
||||
#include <JUI/Widgets/Window.hpp>
|
||||
#include <JUI/Widgets/Scene.hpp>
|
||||
#include <JUI/Widgets/Text.hpp>
|
||||
#include <JUI/Widgets/ListLayout.hpp>
|
||||
#include <JUI/Widgets/TextRect.hpp>
|
||||
#include <rewindow/types/window.h>
|
||||
#include <jlog/jlog.hpp>
|
||||
|
||||
@@ -51,6 +53,22 @@ JUI::Scene* CreateScene() {
|
||||
rect_element->BGColor({0, 64, 0});
|
||||
};
|
||||
|
||||
|
||||
|
||||
auto list = new VerticalListLayout(rect_element);
|
||||
|
||||
TextRect* a = new TextRect(list);
|
||||
a->SetTextSize(16);
|
||||
a->SetFont(FreeSans);
|
||||
a->SetSize({100, 25, 0, 0});
|
||||
a->SetContent("This Dick");
|
||||
|
||||
TextRect* b = new TextRect(list);
|
||||
b->SetTextSize(16);
|
||||
b->SetContent("This Dick2");
|
||||
b->SetSize({100, 25, 0, 0});
|
||||
b->SetFont(FreeSans);
|
||||
|
||||
Text *text = new Text(rect_element);
|
||||
text->SetContent("YO MAMA");
|
||||
text->SetFont(FreeSans);
|
||||
|
@@ -1 +1,20 @@
|
||||
#include <JUI/Widgets/ListLayout.hpp>
|
||||
#include <JUI/Widgets/ListLayout.hpp>
|
||||
|
||||
namespace JUI
|
||||
{
|
||||
ListLayout::ListLayout() : LayoutContainer() {}
|
||||
ListLayout::ListLayout(Widget* parent) : ListLayout() {}
|
||||
|
||||
VerticalListLayout::VerticalListLayout() : ListLayout() {}
|
||||
VerticalListLayout::VerticalListLayout(Widget* parent) : VerticalListLayout()
|
||||
{
|
||||
this->SetParent(parent);
|
||||
}
|
||||
|
||||
|
||||
|
||||
HorizontalListLayout::HorizontalListLayout() : ListLayout() {}
|
||||
|
||||
|
||||
HorizontalListLayout::HorizontalListLayout(Widget* parent) {}
|
||||
}
|
Reference in New Issue
Block a user