remove sidebar and make panels popup
This commit is contained in:
@@ -85,30 +85,20 @@ void App::init_toolbar_main()
|
||||
}
|
||||
}
|
||||
|
||||
template <class T> std::shared_ptr<T> find_or_create_panel(NodeScroll* panels)
|
||||
template <class T> std::shared_ptr<T> create_panel(LayoutManager& manager)
|
||||
{
|
||||
std::shared_ptr<T> ret;
|
||||
auto node_find = std::find_if(panels->m_children.begin(), panels->m_children.end(),
|
||||
[](const std::shared_ptr<Node>&p) { return (bool)std::dynamic_pointer_cast<T>(p); });
|
||||
if (node_find != panels->m_children.end())
|
||||
{
|
||||
ret = std::static_pointer_cast<T>(*node_find);
|
||||
}
|
||||
else
|
||||
{
|
||||
ret = std::make_shared<T>();
|
||||
ret->m_manager = panels->m_manager;
|
||||
ret->init();
|
||||
ret->create();
|
||||
ret->loaded();
|
||||
}
|
||||
ret = std::make_shared<T>();
|
||||
ret->m_manager = &manager;
|
||||
ret->init();
|
||||
ret->create();
|
||||
ret->loaded();
|
||||
return ret;
|
||||
}
|
||||
|
||||
void App::init_sidebar()
|
||||
{
|
||||
sidebar = layout[main_id]->find<NodeBorder>("sidebar");
|
||||
panels = layout[main_id]->find<NodeScroll>("panels");
|
||||
canvas = layout[main_id]->find<NodeCanvas>("paint-canvas");
|
||||
quick = layout[main_id]->find<NodePanelQuick>("panel-quick");
|
||||
|
||||
@@ -118,10 +108,10 @@ void App::init_sidebar()
|
||||
//stroke = layout[main_id]->find<NodePanelStroke>("panel-stroke");
|
||||
|
||||
//brushes = find_or_create_panel<NodePanelBrush>(panels);
|
||||
layers = find_or_create_panel<NodePanelLayer>(panels);
|
||||
color = find_or_create_panel<NodePanelColor>(panels);
|
||||
stroke = find_or_create_panel<NodePanelStroke>(panels);
|
||||
grid = find_or_create_panel<NodePanelGrid>(panels);
|
||||
layers = create_panel<NodePanelLayer>(layout);
|
||||
color = create_panel<NodePanelColor>(layout);
|
||||
stroke = create_panel<NodePanelStroke>(layout);
|
||||
grid = create_panel<NodePanelGrid>(layout);
|
||||
//presets = find_or_create_panel<NodePanelBrushPreset>(panels);
|
||||
|
||||
canvas->m_canvas->on_mode_changed = [this](kCanvasMode prev, kCanvasMode mode) {
|
||||
@@ -230,9 +220,28 @@ void App::init_sidebar()
|
||||
if (auto* button = layout[main_id]->find<NodeButtonCustom>("btn-stroke"))
|
||||
{
|
||||
button->on_click = [this, button](Node*) {
|
||||
panels->get_child_index(stroke.get()) == -1 ? panels->add_child(stroke) : panels->remove_child(stroke.get());
|
||||
panels->fix_scroll();
|
||||
button->set_active(panels->get_child_index(stroke.get()) != -1);
|
||||
auto screen = layout[main_id]->m_size;
|
||||
glm::vec2 pos = button->m_pos + glm::vec2(button->m_size.x * 0.5f, button->m_size.y);
|
||||
layout[main_id]->add_child(stroke);
|
||||
auto tick = layout[main_id]->add_child<NodeImage>();
|
||||
tick->SetPositioning(YGPositionTypeAbsolute);
|
||||
tick->SetSize(32, 16);
|
||||
tick->SetPosition(pos.x - 16, pos.y);
|
||||
tick->set_image("data/ui/popup-tick-up.png");
|
||||
layout[main_id]->update();
|
||||
|
||||
stroke->SetPosition(pos.x - stroke->m_size.x / 2.f, pos.y + 16);
|
||||
stroke->SetPositioning(YGPositionTypeAbsolute);
|
||||
stroke->m_capture_children = false;
|
||||
stroke->m_mouse_ignore = false;
|
||||
stroke->mouse_capture();
|
||||
auto scroll = stroke->find<NodeScroll>("scroller");
|
||||
scroll->SetMaxHeight(glm::max(100.f, screen.y - pos.y - 200.f));
|
||||
layout[main_id]->update();
|
||||
|
||||
stroke->on_popup_close = [this, tick](Node*) {
|
||||
tick->destroy();
|
||||
};
|
||||
};
|
||||
}
|
||||
//if (auto* button = layout[main_id]->find<NodeButtonCustom>("btn-brush"))
|
||||
@@ -254,27 +263,76 @@ void App::init_sidebar()
|
||||
if (auto* button = layout[main_id]->find<NodeButtonCustom>("btn-color"))
|
||||
{
|
||||
button->on_click = [this, button](Node*) {
|
||||
panels->get_child_index(color.get()) == -1 ? panels->add_child(color) : panels->remove_child(color.get());
|
||||
panels->fix_scroll();
|
||||
button->set_active(panels->get_child_index(color.get()) != -1);
|
||||
// auto pick = layout[main_id]->add_child<NodeColorPicker>();
|
||||
// pick->m_color_cur->m_color = Canvas::I->m_current_brush->m_tip_color;
|
||||
auto screen = layout[main_id]->m_size;
|
||||
glm::vec2 pos = button->m_pos + glm::vec2(button->m_size.x * 0.5f, button->m_size.y);
|
||||
layout[main_id]->add_child(color);
|
||||
auto tick = layout[main_id]->add_child<NodeImage>();
|
||||
tick->SetPositioning(YGPositionTypeAbsolute);
|
||||
tick->SetSize(32, 16);
|
||||
tick->SetPosition(pos.x - 16, pos.y);
|
||||
tick->set_image("data/ui/popup-tick-up.png");
|
||||
layout[main_id]->update();
|
||||
|
||||
color->SetPosition(pos.x - color->m_size.x / 2.f, pos.y + 16);
|
||||
color->SetPositioning(YGPositionTypeAbsolute);
|
||||
color->m_capture_children = false;
|
||||
color->m_mouse_ignore = false;
|
||||
color->mouse_capture();
|
||||
layout[main_id]->update();
|
||||
|
||||
color->on_popup_close = [this, tick](Node*) {
|
||||
tick->destroy();
|
||||
};
|
||||
};
|
||||
}
|
||||
if (auto* button = layout[main_id]->find<NodeButtonCustom>("btn-layer"))
|
||||
{
|
||||
button->on_click = [this, button](Node*) {
|
||||
panels->get_child_index(layers.get()) == -1 ? panels->add_child(layers) : panels->remove_child(layers.get());
|
||||
panels->fix_scroll();
|
||||
button->set_active(panels->get_child_index(layers.get()) != -1);
|
||||
auto screen = layout[main_id]->m_size;
|
||||
glm::vec2 pos = button->m_pos + glm::vec2(button->m_size.x * 0.5f, button->m_size.y);
|
||||
layout[main_id]->add_child(layers);
|
||||
auto tick = layout[main_id]->add_child<NodeImage>();
|
||||
tick->SetPositioning(YGPositionTypeAbsolute);
|
||||
tick->SetSize(32, 16);
|
||||
tick->SetPosition(pos.x - 16, pos.y);
|
||||
tick->set_image("data/ui/popup-tick-up.png");
|
||||
layout[main_id]->update();
|
||||
|
||||
layers->SetPosition(pos.x - layers->m_size.x / 2.f, pos.y + 16);
|
||||
layers->SetPositioning(YGPositionTypeAbsolute);
|
||||
layers->m_capture_children = false;
|
||||
layers->m_mouse_ignore = false;
|
||||
layers->mouse_capture();
|
||||
layout[main_id]->update();
|
||||
|
||||
layers->on_popup_close = [this, tick](Node*) {
|
||||
tick->destroy();
|
||||
};
|
||||
};
|
||||
}
|
||||
if (auto* button = layout[main_id]->find<NodeButtonCustom>("btn-grids-panel"))
|
||||
{
|
||||
button->on_click = [this, button](Node*) {
|
||||
panels->get_child_index(grid.get()) == -1 ? panels->add_child(grid) : panels->remove_child(grid.get());
|
||||
panels->fix_scroll();
|
||||
button->set_active(panels->get_child_index(grid.get()) != -1);
|
||||
auto screen = layout[main_id]->m_size;
|
||||
glm::vec2 pos = button->m_pos + glm::vec2(button->m_size.x * 0.5f, button->m_size.y);
|
||||
layout[main_id]->add_child(grid);
|
||||
auto tick = layout[main_id]->add_child<NodeImage>();
|
||||
tick->SetPositioning(YGPositionTypeAbsolute);
|
||||
tick->SetSize(32, 16);
|
||||
tick->SetPosition(pos.x - 16, pos.y);
|
||||
tick->set_image("data/ui/popup-tick-up.png");
|
||||
layout[main_id]->update();
|
||||
|
||||
grid->SetPosition(pos.x - grid->m_size.x / 2.f, pos.y + 16);
|
||||
grid->SetPositioning(YGPositionTypeAbsolute);
|
||||
grid->m_capture_children = false;
|
||||
grid->m_mouse_ignore = false;
|
||||
grid->mouse_capture();
|
||||
layout[main_id]->update();
|
||||
|
||||
grid->on_popup_close = [this, tick](Node*) {
|
||||
tick->destroy();
|
||||
};
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -954,10 +1012,6 @@ void App::initLayout()
|
||||
{
|
||||
LOG("restore layout");
|
||||
layout.restore_context();
|
||||
//if (panels->get_child_index(brushes.get()) == -1) brushes->restore_context();
|
||||
if (panels->get_child_index(layers.get()) == -1) layers->restore_context();
|
||||
if (panels->get_child_index(color.get()) == -1) color->restore_context();
|
||||
if (panels->get_child_index(stroke.get()) == -1) stroke->restore_context();
|
||||
}
|
||||
else
|
||||
layout.load("data/layout.xml");
|
||||
|
||||
Reference in New Issue
Block a user