dockspce widget initial

This commit is contained in:
IlyaShurupov 2024-06-25 18:34:38 +03:00
parent 559c91a144
commit 7158be5890
8 changed files with 72 additions and 12 deletions

View file

@ -110,6 +110,7 @@ namespace tp {
}
void attach(Node* node, Node* node_to) {
node->next = node->prev = nullptr;
if (node_to) {
if (node_to->next) {
node->next = node_to->next;

View file

@ -23,15 +23,21 @@ namespace tp {
NamedSliderWidget mSlider;
};
class SimpleWidget2 : public Widget {
class SimpleWidget2 : public DockSpaceWidget {
public:
SimpleWidget2() {
this->mChildWidgets.pushBack(&mFloating);
mFloating.addWidgetToMenu(&mWidget);
mFloating.addWidgetToMenu(&mWidget2);
// this->mChildWidgets.pushBack(&mFloating2);
// mFloating2.addWidgetToMenu(&mWidget2);
this->mChildWidgets.pushBack(&mFloating2);
mFloating2.addWidgetToMenu(&mWidget2);
mFloating2.mArea = { 200, 100, 100, 100 };
this->mChildWidgets.pushBack(&mFloating3);
mFloating3.addWidgetToMenu(&mWidget3);
mFloating3.mArea = { 400, 100, 100, 100 };
}
private:
@ -40,5 +46,8 @@ namespace tp {
FloatingWidget mFloating2;
SimpleWidget mWidget2;
FloatingWidget mFloating3;
SimpleWidget mWidget3;
};
}

View file

@ -0,0 +1,34 @@
#include "DockspaceWidget.hpp"
using namespace tp;
void DockSpaceWidget::eventProcess(const tp::Events& events) {
if (this->mChildWidgets.size() > 1 && events.isPressed(InputID::MOUSE1)) {
Widget* activeChild = nullptr;
for (auto childNode = this->mChildWidgets.firstNode(); childNode; childNode = childNode->next) {
auto child = childNode->data;
if (child->mArea.isInside(events.getPointer())) {
mChildWidgets.detach(childNode);
mChildWidgets.pushFront(childNode);
child->mHandlesEvents = true;
activeChild = child;
break;
}
}
if (activeChild) {
for (auto child : this->mChildWidgets) {
if (activeChild != child.data()) child->mHandlesEvents = false;
}
}
}
}
void DockSpaceWidget::eventDraw(Canvas& canvas) {
canvas.rect(this->mArea, RGBA(0, 0, 0, 1), 0);
}

View file

@ -9,11 +9,11 @@ FloatingWidget::FloatingWidget() {
}
void FloatingWidget::eventProcess(const Events& events) {
mActionStartRelativePos = events.getPointerPrev() - this->mArea.pos;
checkFloating(events);
checkResizing(events);
mActionStartRelativePos = events.getPointer() - this->mArea.pos;
CollapsableMenu::eventProcess(events);
}

View file

@ -17,10 +17,13 @@ void Widget::procWrapper(const Events& events, const RectF& parentArea) {
checkClicked(events);
eventProcess(events);
if (mHandlesEvents) {
for (auto child : mChildWidgets) {
child->procWrapper(events, getArea());
eventProcess(events);
for (auto child : mChildWidgets) {
child->procWrapper(events, getArea());
}
}
}
@ -31,8 +34,8 @@ void Widget::drawWrapper(Canvas& canvas) {
// draw child widgets
canvas.pushClamp(this->mArea);
for (auto child : mChildWidgets) {
child->drawWrapper(canvas);
for (auto child = mChildWidgets.lastNode(); child; child = child->prev) {
child->data->drawWrapper(canvas);
}
canvas.popClamp();
}

View file

@ -0,0 +1,11 @@
#include "FloatingWidget.hpp"
namespace tp {
class DockSpaceWidget : public Widget {
public:
DockSpaceWidget() = default;
void eventProcess(const Events& events) override;
void eventDraw(Canvas& canvas) override;
};
}

View file

@ -57,6 +57,7 @@ namespace tp {
bool mVisible = false;
bool mEnable = true;
bool mHandlesEvents = true;
bool mInFocus = false;
bool mHolding = false;

View file

@ -9,3 +9,4 @@
#include "CollapsableMenu.hpp"
#include "FloatingWidget.hpp"
#include "Animations.hpp"
#include "DockspaceWidget.hpp"