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