add panels docking
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
#include "pch.h"
|
||||
#include "node_panel_floating.h"
|
||||
#include "log.h"
|
||||
|
||||
Node* NodePanelFloating::clone_instantiate() const
|
||||
{
|
||||
@@ -32,6 +33,19 @@ void NodePanelFloating::init_controls()
|
||||
m_button_minimize->on_click = [this](Node*) {
|
||||
m_container->ToggleVisibility();
|
||||
};
|
||||
m_button_close = find<NodeButton>("button-close");
|
||||
m_button_close->on_click = [this](Node*) {
|
||||
m_container->remove_all_children();
|
||||
destroy();
|
||||
};
|
||||
}
|
||||
|
||||
void NodePanelFloating::handle_parent_resize(glm::vec2 old_size, glm::vec2 new_size)
|
||||
{
|
||||
auto newsize = glm::clamp(GetSize(), { 0, 0 }, m_parent->m_size);
|
||||
SetHeight(newsize.y);
|
||||
auto newpos = glm::clamp(GetPosition(), { 0, 0 }, m_parent->m_size - m_size);
|
||||
SetPosition(newpos);
|
||||
}
|
||||
|
||||
kEventResult NodePanelFloating::handle_event(Event* e)
|
||||
@@ -43,21 +57,100 @@ kEventResult NodePanelFloating::handle_event(Event* e)
|
||||
{
|
||||
case kEventType::MouseDownL:
|
||||
m_dragging = true;
|
||||
m_drag_start_pos = m_pos;
|
||||
if (me->m_pos.y - m_pos.y > m_size.y - 20.f)
|
||||
{
|
||||
if (me->m_pos.x - m_pos.x > m_size.x - 20.f)
|
||||
{
|
||||
m_action = kDragAction::Resize;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_action = kDragAction::Reheight;
|
||||
}
|
||||
m_drag_start_pos = GetSize();
|
||||
}
|
||||
else
|
||||
{
|
||||
m_drag_start_pos = GetPosition();
|
||||
m_action = kDragAction::Move;
|
||||
m_outline = root()->add_child<NodeBorder>();
|
||||
m_outline->SetPositioning(YGPositionTypeAbsolute);
|
||||
m_outline->SetPosition(m_pos);
|
||||
m_outline->SetSize(GetSize());
|
||||
m_outline->m_color = { 0, 0, 0, 0.1 };
|
||||
m_outline->m_thinkness = 1;
|
||||
}
|
||||
m_drag_start_cur = me->m_pos;
|
||||
mouse_capture();
|
||||
m_parent->move_child_front(this);
|
||||
ret = kEventResult::Consumed;
|
||||
break;
|
||||
case kEventType::MouseMove:
|
||||
if (m_dragging)
|
||||
{
|
||||
auto newpos = glm::clamp(m_drag_start_pos + me->m_pos - m_drag_start_cur, { 0, 0 }, root()->m_size - m_size);
|
||||
SetPosition(newpos);
|
||||
if (m_action == kDragAction::Move)
|
||||
{
|
||||
auto newpos = glm::clamp(m_drag_start_pos + me->m_pos - m_drag_start_cur, { 0, 0 }, m_parent->m_size - m_size);
|
||||
SetPosition(newpos);
|
||||
m_outline->SetPosition(m_parent->m_pos + m_drag_start_pos + me->m_pos - m_drag_start_cur);
|
||||
m_outline->SetSize(GetSize());
|
||||
|
||||
auto nodes = root()->find("ui-root")->get_children_at_point(me->m_pos);
|
||||
for (auto const& c : nodes)
|
||||
{
|
||||
if (c->m_nodeID_s.find("drop") == 0)
|
||||
{
|
||||
m_outline->SetPosition(c->m_pos);
|
||||
m_outline->SetSize(c->m_size);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (m_action == kDragAction::Reheight)
|
||||
{
|
||||
auto newsize = glm::clamp(m_drag_start_pos + me->m_pos - m_drag_start_cur, { 0, 0 }, m_parent->m_size);
|
||||
SetHeight(newsize.y);
|
||||
}
|
||||
else if (m_action == kDragAction::Resize)
|
||||
{
|
||||
auto newsize = glm::clamp(m_drag_start_pos + me->m_pos - m_drag_start_cur, { 0, 0 }, m_parent->m_size);
|
||||
SetSize(newsize);
|
||||
}
|
||||
ret = kEventResult::Consumed;
|
||||
}
|
||||
break;
|
||||
case kEventType::MouseUpL:
|
||||
m_dragging = false;
|
||||
if (m_action == kDragAction::Move)
|
||||
{
|
||||
m_outline->destroy();
|
||||
auto nodes = root()->find("ui-root")->get_children_at_point(me->m_pos);
|
||||
bool docked = false;
|
||||
auto ref = m_parent->m_children[m_parent->get_child_index(this)];
|
||||
for (auto const& c : nodes)
|
||||
{
|
||||
if (c->m_nodeID_s.find("drop") == 0)
|
||||
{
|
||||
//auto panel = m_container->m_children.front();
|
||||
//panel->SetSize(300, 300);
|
||||
//c->add_child(m_container->m_children.front());
|
||||
//destroy();
|
||||
SetPositioning(YGPositionTypeRelative);
|
||||
SetWidth(300);
|
||||
SetPosition(0, 0);
|
||||
c->add_child(ref);
|
||||
docked = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!docked)
|
||||
{
|
||||
auto cont = root()->find("floatings");
|
||||
SetPositioning(YGPositionTypeAbsolute);
|
||||
SetPosition(m_outline->m_pos - cont->m_pos);
|
||||
cont->add_child(ref);
|
||||
}
|
||||
}
|
||||
mouse_release();
|
||||
ret = kEventResult::Consumed;
|
||||
break;
|
||||
|
||||
Reference in New Issue
Block a user