From e3f5b7c84f95b2a16d5921a0e0bc17d6cf63e0d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Nusser?= Date: Sun, 16 Apr 2017 13:42:02 +0200 Subject: Fix drawing bug of TabButton. --- plugingui/tabbutton.cc | 18 +++++++----------- plugingui/tabbutton.h | 2 +- 2 files changed, 8 insertions(+), 12 deletions(-) (limited to 'plugingui') diff --git a/plugingui/tabbutton.cc b/plugingui/tabbutton.cc index 1fc4619..27588da 100644 --- a/plugingui/tabbutton.cc +++ b/plugingui/tabbutton.cc @@ -65,6 +65,8 @@ std::size_t TabButton::getMinimalHeight() const void TabButton::setActive(bool active) { + this->active = active; + if (active) { draw_state = State::Down; } @@ -91,25 +93,19 @@ void TabButton::repaintEvent(RepaintEvent* e) return; } - switch(draw_state) - { - case State::Up: + if (draw_state == State::Up && !active) { tab_passive.setSize(w - padLeft, h - padTop); p.drawImage(padLeft, padTop, tab_passive); - break; - - case State::Down: + } + else { tab_active.setSize(w - padLeft, h - padTop); p.drawImage(padLeft, padTop, tab_active); - break; } p.setColour(Colour(0.1)); // FIXME: fix all the magic values here - auto x = (width() / 2) - (3 * text.length()) + - (draw_state == State::Up ? 0 : 1) + (padLeft / 2); - auto y = (height() / 2) + 5 + 1 + (draw_state == State::Up ? 0 : 1) + - (padTop / 2); + auto x = (width() / 2) - (3 * text.length()) + (padLeft / 2); + auto y = (height() / 2) + 5 + 1 + (padTop / 2); p.drawText(x, y + 4, font, text, true); } diff --git a/plugingui/tabbutton.h b/plugingui/tabbutton.h index 2f0dc10..a248335 100644 --- a/plugingui/tabbutton.h +++ b/plugingui/tabbutton.h @@ -57,7 +57,7 @@ private: void clickHandler(); Widget* tab_widget; - bool active; + bool active{false}; TexturedBox tab_active{getImageCache(), ":tab.png", 0, 0, // atlas offset (x, y) -- cgit v1.2.3