add BasePanel & add padding property to SplitBox
This commit is contained in:
@@ -0,0 +1,43 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "Container.hpp"
|
||||||
|
|
||||||
|
namespace gui {
|
||||||
|
class BasePanel : public Container {
|
||||||
|
public:
|
||||||
|
virtual ~BasePanel() = default;
|
||||||
|
|
||||||
|
virtual void setOrientation(Orientation orientation) {
|
||||||
|
this->orientation = orientation;
|
||||||
|
refresh();
|
||||||
|
}
|
||||||
|
|
||||||
|
Orientation getOrientation() const {
|
||||||
|
return orientation;
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual void setPadding(glm::vec4 padding) {
|
||||||
|
this->padding = padding;
|
||||||
|
refresh();
|
||||||
|
}
|
||||||
|
|
||||||
|
glm::vec4 getPadding() const {
|
||||||
|
return padding;
|
||||||
|
}
|
||||||
|
protected:
|
||||||
|
BasePanel(
|
||||||
|
glm::vec2 size,
|
||||||
|
glm::vec4 padding = glm::vec4(0.0f),
|
||||||
|
float interval = 2.0f,
|
||||||
|
Orientation orientation = Orientation::vertical
|
||||||
|
)
|
||||||
|
: Container(std::move(size)),
|
||||||
|
padding(std::move(padding)),
|
||||||
|
interval(interval) {
|
||||||
|
}
|
||||||
|
|
||||||
|
Orientation orientation = Orientation::vertical;
|
||||||
|
glm::vec4 padding;
|
||||||
|
float interval = 2.0f;
|
||||||
|
};
|
||||||
|
}
|
||||||
@@ -5,9 +5,7 @@
|
|||||||
using namespace gui;
|
using namespace gui;
|
||||||
|
|
||||||
Panel::Panel(glm::vec2 size, glm::vec4 padding, float interval)
|
Panel::Panel(glm::vec2 size, glm::vec4 padding, float interval)
|
||||||
: Container(size),
|
: BasePanel(size, padding, interval, Orientation::vertical)
|
||||||
padding(padding),
|
|
||||||
interval(interval)
|
|
||||||
{
|
{
|
||||||
setColor(glm::vec4(0.0f, 0.0f, 0.0f, 0.75f));
|
setColor(glm::vec4(0.0f, 0.0f, 0.0f, 0.75f));
|
||||||
}
|
}
|
||||||
@@ -31,15 +29,6 @@ int Panel::getMinLength() const {
|
|||||||
return minLength;
|
return minLength;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Panel::setPadding(glm::vec4 padding) {
|
|
||||||
this->padding = padding;
|
|
||||||
refresh();
|
|
||||||
}
|
|
||||||
|
|
||||||
glm::vec4 Panel::getPadding() const {
|
|
||||||
return padding;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Panel::cropToContent() {
|
void Panel::cropToContent() {
|
||||||
if (maxLength > 0.0f) {
|
if (maxLength > 0.0f) {
|
||||||
setSize(glm::vec2(
|
setSize(glm::vec2(
|
||||||
@@ -109,11 +98,3 @@ void Panel::refresh() {
|
|||||||
actualLength = size.y;
|
actualLength = size.y;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Panel::setOrientation(Orientation orientation) {
|
|
||||||
this->orientation = orientation;
|
|
||||||
}
|
|
||||||
|
|
||||||
Orientation Panel::getOrientation() const {
|
|
||||||
return orientation;
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,16 +1,10 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "commons.hpp"
|
#include "commons.hpp"
|
||||||
#include "Container.hpp"
|
#include "BasePanel.hpp"
|
||||||
|
|
||||||
namespace gui {
|
namespace gui {
|
||||||
class Panel : public Container {
|
class Panel : public BasePanel {
|
||||||
protected:
|
|
||||||
Orientation orientation = Orientation::vertical;
|
|
||||||
glm::vec4 padding;
|
|
||||||
float interval = 2.0f;
|
|
||||||
int minLength = 0;
|
|
||||||
int maxLength = 0;
|
|
||||||
public:
|
public:
|
||||||
Panel(
|
Panel(
|
||||||
glm::vec2 size,
|
glm::vec2 size,
|
||||||
@@ -21,9 +15,6 @@ namespace gui {
|
|||||||
|
|
||||||
virtual void cropToContent();
|
virtual void cropToContent();
|
||||||
|
|
||||||
virtual void setOrientation(Orientation orientation);
|
|
||||||
Orientation getOrientation() const;
|
|
||||||
|
|
||||||
virtual void add(const std::shared_ptr<UINode>& node) override;
|
virtual void add(const std::shared_ptr<UINode>& node) override;
|
||||||
virtual void remove(UINode* node) override;
|
virtual void remove(UINode* node) override;
|
||||||
|
|
||||||
@@ -35,8 +26,8 @@ namespace gui {
|
|||||||
|
|
||||||
virtual void setMinLength(int value);
|
virtual void setMinLength(int value);
|
||||||
int getMinLength() const;
|
int getMinLength() const;
|
||||||
|
protected:
|
||||||
virtual void setPadding(glm::vec4 padding);
|
int minLength = 0;
|
||||||
glm::vec4 getPadding() const;
|
int maxLength = 0;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
using namespace gui;
|
using namespace gui;
|
||||||
|
|
||||||
SplitBox::SplitBox(const glm::vec2& size, float splitPos, Orientation orientation)
|
SplitBox::SplitBox(const glm::vec2& size, float splitPos, Orientation orientation)
|
||||||
: Container(size), splitPos(splitPos), orientation(orientation) {
|
: BasePanel(size, glm::vec4(), 4.0f, orientation), splitPos(splitPos) {
|
||||||
setCursor(
|
setCursor(
|
||||||
orientation == Orientation::vertical ? CursorShape::NS_RESIZE
|
orientation == Orientation::vertical ? CursorShape::NS_RESIZE
|
||||||
: CursorShape::EW_RESIZE
|
: CursorShape::EW_RESIZE
|
||||||
@@ -40,18 +40,22 @@ void SplitBox::refresh() {
|
|||||||
}
|
}
|
||||||
auto nodeA = nodes.at(0);
|
auto nodeA = nodes.at(0);
|
||||||
auto nodeB = nodes.at(1);
|
auto nodeB = nodes.at(1);
|
||||||
|
|
||||||
|
float sepRadius = interval / 2.0f;
|
||||||
|
|
||||||
nodeA->setPos(glm::vec2());
|
nodeA->setPos(glm::vec2(padding));
|
||||||
|
|
||||||
|
const auto& p = padding;
|
||||||
if (orientation == Orientation::vertical) {
|
if (orientation == Orientation::vertical) {
|
||||||
float splitPos = this->splitPos * size.y;
|
float splitPos = this->splitPos * size.y;
|
||||||
nodeA->setSize(glm::vec2(size.x, splitPos - splitRadius));
|
nodeA->setSize({size.x-p.x-p.z, splitPos - sepRadius - p.y});
|
||||||
nodeB->setSize(glm::vec2(size.x, size.y - splitPos - splitRadius));
|
nodeB->setSize({size.x-p.x-p.z, size.y - splitPos - sepRadius - p.w});
|
||||||
nodeB->setPos(glm::vec2(0.0f, splitPos + splitRadius));
|
nodeB->setPos({p.x, splitPos + sepRadius});
|
||||||
} else {
|
} else {
|
||||||
float splitPos = this->splitPos * size.x;
|
float splitPos = this->splitPos * size.x;
|
||||||
nodeA->setSize(glm::vec2(splitPos - splitRadius, size.y));
|
nodeA->setSize({splitPos - sepRadius - p.x, size.y - p.y - p.w});
|
||||||
nodeB->setSize(glm::vec2(size.x - splitPos - splitRadius, size.y));
|
nodeB->setSize({size.x - splitPos - sepRadius - p.z, size.y - p.y - p.w});
|
||||||
nodeB->setPos(glm::vec2(splitPos + splitRadius, 0.0f));
|
nodeB->setPos({splitPos + sepRadius, p.y});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "Container.hpp"
|
#include "BasePanel.hpp"
|
||||||
|
|
||||||
namespace gui {
|
namespace gui {
|
||||||
class SplitBox : public Container {
|
class SplitBox : public BasePanel {
|
||||||
public:
|
public:
|
||||||
SplitBox(const glm::vec2& size, float splitPos, Orientation orientation);
|
SplitBox(const glm::vec2& size, float splitPos, Orientation orientation);
|
||||||
|
|
||||||
@@ -12,7 +12,5 @@ namespace gui {
|
|||||||
virtual void fullRefresh() override;
|
virtual void fullRefresh() override;
|
||||||
private:
|
private:
|
||||||
float splitPos;
|
float splitPos;
|
||||||
int splitRadius = 2;
|
|
||||||
Orientation orientation;
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
+27
-10
@@ -207,11 +207,10 @@ void UiXmlReader::readUINode(
|
|||||||
read_uinode(reader, element, node);
|
read_uinode(reader, element, node);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void read_panel_impl(
|
static void read_base_panel_impl(
|
||||||
UiXmlReader& reader,
|
UiXmlReader& reader,
|
||||||
const xml::xmlelement& element,
|
const xml::xmlelement& element,
|
||||||
Panel& panel,
|
BasePanel& panel
|
||||||
bool subnodes = true
|
|
||||||
) {
|
) {
|
||||||
read_uinode(reader, element, panel);
|
read_uinode(reader, element, panel);
|
||||||
|
|
||||||
@@ -224,6 +223,22 @@ static void read_panel_impl(
|
|||||||
size.y + padding.y + padding.w
|
size.y + padding.y + padding.w
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
if (element.has("orientation")) {
|
||||||
|
auto &oname = element.attr("orientation").getText();
|
||||||
|
if (oname == "horizontal") {
|
||||||
|
panel.setOrientation(Orientation::horizontal);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void read_panel_impl(
|
||||||
|
UiXmlReader& reader,
|
||||||
|
const xml::xmlelement& element,
|
||||||
|
Panel& panel,
|
||||||
|
bool subnodes = true
|
||||||
|
) {
|
||||||
|
read_base_panel_impl(reader, element, panel);
|
||||||
|
|
||||||
if (element.has("size")) {
|
if (element.has("size")) {
|
||||||
panel.setResizing(false);
|
panel.setResizing(false);
|
||||||
}
|
}
|
||||||
@@ -233,12 +248,6 @@ static void read_panel_impl(
|
|||||||
if (element.has("min-length")) {
|
if (element.has("min-length")) {
|
||||||
panel.setMinLength(element.attr("min-length").asInt());
|
panel.setMinLength(element.attr("min-length").asInt());
|
||||||
}
|
}
|
||||||
if (element.has("orientation")) {
|
|
||||||
auto &oname = element.attr("orientation").getText();
|
|
||||||
if (oname == "horizontal") {
|
|
||||||
panel.setOrientation(Orientation::horizontal);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (subnodes) {
|
if (subnodes) {
|
||||||
for (auto& sub : element.getElements()) {
|
for (auto& sub : element.getElements()) {
|
||||||
if (sub->isText())
|
if (sub->isText())
|
||||||
@@ -324,7 +333,15 @@ static std::shared_ptr<UINode> read_split_box(
|
|||||||
: Orientation::vertical;
|
: Orientation::vertical;
|
||||||
auto splitBox =
|
auto splitBox =
|
||||||
std::make_shared<SplitBox>(glm::vec2(), splitPos, orientation);
|
std::make_shared<SplitBox>(glm::vec2(), splitPos, orientation);
|
||||||
read_container_impl(reader, element, *splitBox);
|
read_base_panel_impl(reader, element, *splitBox);
|
||||||
|
for (auto& sub : element.getElements()) {
|
||||||
|
if (sub->isText())
|
||||||
|
continue;
|
||||||
|
auto subnode = reader.readUINode(*sub);
|
||||||
|
if (subnode) {
|
||||||
|
splitBox->add(subnode);
|
||||||
|
}
|
||||||
|
}
|
||||||
return splitBox;
|
return splitBox;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user