fix sidebar scroll when adding or removing panels

This commit is contained in:
2017-08-12 18:45:49 +01:00
parent 2711d4e9b0
commit 6d3c9380b2
4 changed files with 53 additions and 54 deletions

View File

@@ -6,6 +6,9 @@
using namespace ui;
static glm::vec4 color_button_normal{ .1, .1, .1, 1 };
static glm::vec4 color_button_hlight{ 1, .0, .0, 1 };
void App::init_toolbar_main()
{
@@ -85,7 +88,7 @@ void App::init_toolbar_main()
void App::init_sidebar()
{
sidebar = layout[main_id]->find<NodeBorder>("sidebar");
panels = layout[main_id]->find<Node>("panels");
panels = layout[main_id]->find<NodeScroll>("panels");
canvas = layout[main_id]->find<NodeCanvas>("paint-canvas");
canvas->data_path = data_path;
@@ -177,13 +180,42 @@ void App::init_sidebar()
layers->on_layer_highlight_changed = [this](Node*, int idx, bool highlight) {
canvas->m_canvas->m_layers[canvas->m_canvas->m_order[idx]].m_hightlight = highlight;
};
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_color(panels->get_child_index(stroke.get()) == -1 ? color_button_normal : color_button_hlight);
};
}
if (auto* button = layout[main_id]->find<NodeButtonCustom>("btn-brush"))
{
button->on_click = [this, button](Node*) {
panels->get_child_index(brushes.get()) == -1 ? panels->add_child(brushes) : panels->remove_child(brushes.get());
panels->fix_scroll();
button->set_color(panels->get_child_index(brushes.get()) == -1 ? color_button_normal : color_button_hlight);
};
}
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_color(panels->get_child_index(color.get()) == -1 ? color_button_normal : color_button_hlight);
};
}
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_color(panels->get_child_index(layers.get()) == -1 ? color_button_normal : color_button_hlight);
};
}
}
void App::init_toolbar_draw()
{
static glm::vec4 color_button_normal{ .1, .1, .1, 1 };
static glm::vec4 color_button_hlight{ 1, .0, .0, 1 };
if (auto* button = layout[main_id]->find<NodeButton>("btn-pen"))
{
button->on_click = [this](Node*) {
@@ -274,34 +306,6 @@ void App::init_toolbar_draw()
canvas->m_canvas->clear(canvas->m_brush.m_tip_color);
};
}
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());
button->set_color(panels->get_child_index(stroke.get()) == -1 ? color_button_normal : color_button_hlight);
};
}
if (auto* button = layout[main_id]->find<NodeButtonCustom>("btn-brush"))
{
button->on_click = [this, button](Node*) {
panels->get_child_index(brushes.get()) == -1 ? panels->add_child(brushes) : panels->remove_child(brushes.get());
button->set_color(panels->get_child_index(brushes.get()) == -1 ? color_button_normal : color_button_hlight);
};
}
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());
button->set_color(panels->get_child_index(color.get()) == -1 ? color_button_normal : color_button_hlight);
};
}
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());
button->set_color(panels->get_child_index(layers.get()) == -1 ? color_button_normal : color_button_hlight);
};
}
}
void App::init_menu_file()