From cc80230bd85dbaf1036b4cf37259d3146229fb00 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20L=C3=BCbking?= Date: Thu, 4 Aug 2016 15:20:35 +0200 Subject: expose a preferredWidth of *Button's --- src/FbTk/Button.hh | 2 ++ src/FbTk/TextButton.cc | 4 ++++ src/FbTk/TextButton.hh | 1 + src/IconButton.cc | 7 +++++++ src/IconButton.hh | 2 ++ 5 files changed, 16 insertions(+) diff --git a/src/FbTk/Button.hh b/src/FbTk/Button.hh index 1f65799..c3276a6 100644 --- a/src/FbTk/Button.hh +++ b/src/FbTk/Button.hh @@ -55,6 +55,8 @@ public: virtual void setBackgroundColor(const Color &color); virtual bool setOrientation(FbTk::Orientation orient) { return orient == FbTk::ROT0; } + virtual unsigned int preferredWidth() const { return width(); } + /** @name eventhandlers */ diff --git a/src/FbTk/TextButton.cc b/src/FbTk/TextButton.cc index 4d05ecd..0cc1b51 100644 --- a/src/FbTk/TextButton.cc +++ b/src/FbTk/TextButton.cc @@ -112,6 +112,10 @@ unsigned int TextButton::textWidth() const { return font().textWidth(text()); } +unsigned int TextButton::preferredWidth() const { + return m_bevel + m_left_padding + m_right_padding + textWidth(); +} + void TextButton::renderForeground(FbWindow &win, FbDrawable &drawable) { // (win should always be *this, no need to check) drawText(0, 0, &drawable); diff --git a/src/FbTk/TextButton.hh b/src/FbTk/TextButton.hh index fe92cc3..90c7c3d 100644 --- a/src/FbTk/TextButton.hh +++ b/src/FbTk/TextButton.hh @@ -62,6 +62,7 @@ public: unsigned int textWidth() const; int bevel() const { return m_bevel; } + virtual unsigned int preferredWidth() const; protected: virtual void drawText(int x_offset, int y_offset, FbDrawable *drawable_override); diff --git a/src/IconButton.cc b/src/IconButton.cc index 4997365..4b0b423 100644 --- a/src/IconButton.cc +++ b/src/IconButton.cc @@ -279,3 +279,10 @@ bool IconButton::setOrientation(FbTk::Orientation orient) { return false; } +unsigned int IconButton::preferredWidth() const { + unsigned int r = TextButton::preferredWidth(); + if (m_icon_pixmap.drawable()) + r += m_icon_window.width() + 1; + return r; +} + diff --git a/src/IconButton.hh b/src/IconButton.hh index 876cfe2..d3cb3d8 100644 --- a/src/IconButton.hh +++ b/src/IconButton.hh @@ -65,6 +65,8 @@ public: bool setOrientation(FbTk::Orientation orient); + virtual unsigned int preferredWidth() const; + const FbTk::Signal<> &titleChanged() { return m_title_changed; } protected: -- cgit v0.11.2