From 876a70fce2d3c5d36172c74728d0d961af7ca9a5 Mon Sep 17 00:00:00 2001 From: akir Date: Sun, 10 Oct 2004 16:04:33 +0000 Subject: added padding: space between text and the border --- src/FbTk/TextButton.cc | 24 ++++++++++++++++++------ src/FbTk/TextButton.hh | 11 ++++++++++- 2 files changed, 28 insertions(+), 7 deletions(-) diff --git a/src/FbTk/TextButton.cc b/src/FbTk/TextButton.cc index 6d93c92..9b4798b 100644 --- a/src/FbTk/TextButton.cc +++ b/src/FbTk/TextButton.cc @@ -19,7 +19,7 @@ // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. -// $Id: TextButton.cc,v 1.6 2004/09/11 22:58:20 fluxgen Exp $ +// $Id: TextButton.cc,v 1.7 2004/10/10 16:04:33 akir Exp $ #include "TextButton.hh" #include "Font.hh" @@ -36,6 +36,8 @@ TextButton::TextButton(const FbTk::FbWindow &parent, m_font(&font), m_text(text), m_justify(FbTk::LEFT), m_bevel(1), + m_left_padding(0), + m_right_padding(0), m_buffer(drawable(), width(), height(), depth()) { } @@ -79,6 +81,19 @@ void TextButton::setBevel(int bevel) { m_bevel = bevel; } +void TextButton::setTextPaddingLeft(unsigned int leftpadding) { + m_left_padding = leftpadding; +} + +void TextButton::setTextPaddingRight(unsigned int rightpadding) { + m_right_padding = rightpadding; +} + +void TextButton::setTextPadding(unsigned int padding) { + setTextPaddingLeft(padding/2); + setTextPaddingRight(padding/2); +} + /// clear window and redraw text void TextButton::clear() { TextButton::clearArea(0, 0, @@ -121,9 +136,6 @@ void TextButton::clearArea(int x, int y, updateTransparent(x, y, width, height); drawText(); } - - - } unsigned int TextButton::textWidth() const { @@ -133,7 +145,7 @@ unsigned int TextButton::textWidth() const { void TextButton::drawText(int x_offset, int y_offset) { unsigned int textlen = text().size(); // do text alignment - int align_x = FbTk::doAlignment(width() - x_offset, + int align_x = FbTk::doAlignment(width() - x_offset - m_left_padding - m_right_padding, bevel(), justify(), font(), @@ -150,7 +162,7 @@ void TextButton::drawText(int x_offset, int y_offset) { screenNumber(), gc(), // graphic context text().c_str(), textlen, // string and string size - align_x + x_offset, center_pos + y_offset); // position + align_x + x_offset + m_left_padding, center_pos + y_offset); // position } void TextButton::exposeEvent(XExposeEvent &event) { diff --git a/src/FbTk/TextButton.hh b/src/FbTk/TextButton.hh index 8c5b583..42c26f5 100644 --- a/src/FbTk/TextButton.hh +++ b/src/FbTk/TextButton.hh @@ -19,7 +19,7 @@ // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. -// $Id: TextButton.hh,v 1.5 2004/01/08 22:03:13 fluxgen Exp $ +// $Id: TextButton.hh,v 1.6 2004/10/10 16:04:33 akir Exp $ #ifndef FBTK_TEXTBUTTON_HH #define FBTK_TEXTBUTTON_HH @@ -44,6 +44,9 @@ public: void setText(const std::string &text); void setFont(const FbTk::Font &font); void setBevel(int bevel); + void setTextPadding(unsigned int padding); + void setTextPaddingLeft(unsigned int leftpadding); + void setTextPaddingRight(unsigned int rightpadding); void resize(unsigned int width, unsigned int height); void moveResize(int x, int y, @@ -63,6 +66,8 @@ public: inline const FbTk::Font &font() const { return *m_font; } unsigned int textWidth() const; int bevel() const { return m_bevel; } + unsigned int leftPadding() const { return m_left_padding; } + unsigned int rightPadding() const { return m_right_padding; } protected: virtual void drawText(int x_offset = 0, int y_offset = 0); @@ -71,7 +76,11 @@ private: const FbTk::Font *m_font; std::string m_text; FbTk::Justify m_justify; + int m_bevel; + unsigned int m_left_padding; ///< space between buttonborder and text + unsigned int m_right_padding; ///< space between buttonborder and text + FbTk::FbPixmap m_buffer; ///< for background buffer }; -- cgit v0.11.2