summaryrefslogtreecommitdiff
path: root/plugingui/tabwidget.cc
diff options
context:
space:
mode:
authorBent Bisballe Nyeng <deva@aasimon.org>2019-02-11 10:52:30 +0100
committerBent Bisballe Nyeng <deva@aasimon.org>2019-02-11 10:52:30 +0100
commit43c2a51331d3e91d86ef50c5262920bdaa260925 (patch)
treeffc5b03be36537e6f028df935a251493d4557979 /plugingui/tabwidget.cc
parent152423c0274887415b50c0d31828036a8fe54708 (diff)
Show/hide drumkit tab depending on if the current kit has a valid image attached or not.
Diffstat (limited to 'plugingui/tabwidget.cc')
-rw-r--r--plugingui/tabwidget.cc32
1 files changed, 30 insertions, 2 deletions
diff --git a/plugingui/tabwidget.cc b/plugingui/tabwidget.cc
index 7ba39c9..17a540e 100644
--- a/plugingui/tabwidget.cc
+++ b/plugingui/tabwidget.cc
@@ -39,7 +39,7 @@ TabWidget::TabWidget(Widget *parent)
CONNECT(&stack, currentChanged, this, &TabWidget::setActiveButtons);
}
-void TabWidget::addTab(const std::string& title, Widget* widget)
+TabID TabWidget::addTab(const std::string& title, Widget* widget)
{
buttons.emplace_back(this, widget);
auto& button = buttons.back();
@@ -48,11 +48,13 @@ void TabWidget::addTab(const std::string& title, Widget* widget)
CONNECT(&button, switchTabNotifier, this, &TabWidget::switchTab);
CONNECT(&button, scrollNotifier, this, &TabWidget::rotateTab);
sizeChanged(width(), height());
+ return button.getID();
}
void TabWidget::setTabWidth(std::size_t width)
{
tab_width = width;
+ relayout();
}
std::size_t TabWidget::getTabWidth() const
@@ -60,6 +62,19 @@ std::size_t TabWidget::getTabWidth() const
return tab_width;
}
+void TabWidget::setVisible(TabID tab_id, bool visible)
+{
+ for (auto& button : buttons)
+ {
+ if(button.getID() == tab_id)
+ {
+ button.setVisible(visible);
+ relayout();
+ return;
+ }
+ }
+}
+
std::size_t TabWidget::getBarHeight() const
{
return topbar.height();
@@ -116,8 +131,12 @@ void TabWidget::sizeChanged(int width, int height)
if(buttons.size() > 0)
{
- for (auto& button : buttons)
+ for(auto& button : buttons)
{
+ if(!button.visible())
+ {
+ continue;
+ }
int min_width = button.getMinimalWidth();
button_width = std::max(button_width, min_width + button_border_width);
}
@@ -136,6 +155,10 @@ void TabWidget::sizeChanged(int width, int height)
pos = button_padding_left;
for(auto& button : buttons)
{
+ if(!button.visible())
+ {
+ continue;
+ }
button.resize(button_width, bar_height);
button.move(pos, 0);
pos += button_width + button_padding_inner;
@@ -145,4 +168,9 @@ void TabWidget::sizeChanged(int width, int height)
stack.resize(width, std::max((int)height - bar_height, 0));
}
+void TabWidget::relayout()
+{
+ sizeChanged(TabWidget::width(), TabWidget::height()); // Force re-layout
+}
+
} // GUI::