From 25ac09f7ee1c7c6c9b1360c1d92eb3fb2ee4a3b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Nusser?= Date: Thu, 20 Apr 2017 22:22:36 +0200 Subject: Set text in tabs correctly and fix magic values in button classes. --- plugingui/button.cc | 6 +++--- plugingui/tabbutton.cc | 9 ++++----- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/plugingui/button.cc b/plugingui/button.cc index 8e386c0..907b1a1 100644 --- a/plugingui/button.cc +++ b/plugingui/button.cc @@ -51,6 +51,7 @@ void Button::repaintEvent(RepaintEvent* repaintEvent) int padTop = 3; int padLeft = 0; + int padTextTop = 3; int w = width(); int h = height(); @@ -80,9 +81,8 @@ void Button::repaintEvent(RepaintEvent* repaintEvent) p.setColour(Colour(0.55)); } - auto x = (w / 2) - (3 * text.length()) + (draw_state == State::Up ? 0 : 1) + - (padLeft / 2); - auto y = (h / 2) + 5 + 1 + (draw_state == State::Up ? 0 : 1) + (padTop / 2); + auto x = padLeft + (width() - font.textWidth(text)) / 2; + auto y = padTop + padTextTop + font.textHeight(text); p.drawText(x, y, font, text, enabled); } diff --git a/plugingui/tabbutton.cc b/plugingui/tabbutton.cc index 27588da..56552c0 100644 --- a/plugingui/tabbutton.cc +++ b/plugingui/tabbutton.cc @@ -85,6 +85,7 @@ void TabButton::repaintEvent(RepaintEvent* e) int padTop = 3; int padLeft = 0; + int padTextTop = 3; int w = width(); int h = height(); @@ -102,11 +103,9 @@ void TabButton::repaintEvent(RepaintEvent* e) p.drawImage(padLeft, padTop, tab_active); } - p.setColour(Colour(0.1)); - // FIXME: fix all the magic values here - 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); + auto x = padLeft + (width() - font.textWidth(text)) / 2; + auto y = padTop + padTextTop + font.textHeight(text); + p.drawText(x, y, font, text, true); } void TabButton::clickHandler() -- cgit v1.2.3