From 6e8bf37cc84642815113dcc88fea9fe8c1b8aebc Mon Sep 17 00:00:00 2001 From: Lajos Koszti Date: Wed, 16 Aug 2017 11:42:37 +0200 Subject: Rotate toolbar button on rotated toolbar In 393ba45f91480bb10f510248837c6051b7ff6a03 added the possibility to add custom buttons to the toolbar. However, if the toolbar is rotated the buttons stays horizontal. Update the button to rotate the text and update the width/height of the button if rotated --- src/ButtonTool.cc | 17 +++++++++++++++-- src/ButtonTool.hh | 1 + 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/ButtonTool.cc b/src/ButtonTool.cc index 746549f..5f9aec1 100644 --- a/src/ButtonTool.cc +++ b/src/ButtonTool.cc @@ -51,8 +51,15 @@ void ButtonTool::updateSizing() { btn.setBorderWidth(bw); if (FbTk::TextButton *txtBtn = dynamic_cast(&btn)) { bw += 2; // extra padding, seems somehow required... - resize(theme()->font().textWidth(txtBtn->text()) + 2*bw, - theme()->font().height() + 2*bw); + + unsigned int new_width = theme()->font().textWidth(txtBtn->text()) + 2*bw; + unsigned int new_height = theme()->font().height() + 2*bw; + + if (orientation() == FbTk::ROT0 || orientation() == FbTk::ROT180) { + resize(new_width, new_height); + } else { + resize(new_height, new_width); + } } } @@ -93,3 +100,9 @@ void ButtonTool::renderTheme(int alpha) { btn.clear(); } +void ButtonTool::setOrientation(FbTk::Orientation orient) { + FbTk::Button &btn = static_cast(window()); + btn.setOrientation(orient); + ToolbarItem::setOrientation(orient); +} + diff --git a/src/ButtonTool.hh b/src/ButtonTool.hh index ec74618..e5e5026 100644 --- a/src/ButtonTool.hh +++ b/src/ButtonTool.hh @@ -39,6 +39,7 @@ public: FbTk::ThemeProxy &theme, FbTk::ImageControl &img_ctrl); virtual ~ButtonTool(); + void setOrientation(FbTk::Orientation orient); protected: void renderTheme(int alpha); -- cgit v0.11.2