1 /* TextButton.cpp
2 * Copyright (C) 2018, 2019 Sven Jähnichen
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <https://www.gnu.org/licenses/>.
16 */
17
18 #include "TextButton.hpp"
19
20 namespace BWidgets
21 {
TextButton()22 TextButton::TextButton () :
23 TextButton (0.0, 0.0, BWIDGETS_DEFAULT_BUTTON_WIDTH, BWIDGETS_DEFAULT_BUTTON_HEIGHT, "textbutton", "", 0.0) {}
24
TextButton(const double x,const double y,const double width,const double height,const std::string & name,double defaultValue)25 TextButton::TextButton (const double x, const double y, const double width, const double height, const std::string& name, double defaultValue) :
26 TextButton (x, y, width, height, name, name, defaultValue) {}
27
TextButton(const double x,const double y,const double width,const double height,const std::string & name,const std::string & label,double defaultValue)28 TextButton::TextButton (const double x, const double y, const double width, const double height,
29 const std::string& name, const std::string& label, double defaultValue) :
30 Button (x, y, width, height, name, defaultValue),
31 buttonLabel (0, 0, width, height, name, label)
32 {
33 buttonLabel.setClickable (false);
34 buttonLabel.setState (defaultValue ? BColors::ACTIVE : BColors::NORMAL);
35 buttonLabel.setBorder (BWIDGETS_DEFAULT_MENU_TEXTBORDER);
36 add (buttonLabel);
37 }
38
TextButton(const TextButton & that)39 TextButton::TextButton (const TextButton& that) : Button (that), buttonLabel (that.buttonLabel)
40 {
41 add (buttonLabel);
42 }
43
~TextButton()44 TextButton:: ~TextButton () {}
45
operator =(const TextButton & that)46 TextButton& TextButton::operator= (const TextButton& that)
47 {
48 release (&buttonLabel);
49
50 Button::operator= (that);
51 buttonLabel = that.buttonLabel;
52
53 add (buttonLabel);
54
55 return *this;
56 }
57
clone() const58 Widget* TextButton::clone () const {return new TextButton (*this);}
59
setWidth(const double width)60 void TextButton::setWidth (const double width)
61 {
62 Button::setWidth (width);
63 buttonLabel.setWidth (width);
64 }
65
setHeight(const double height)66 void TextButton::setHeight (const double height)
67 {
68 Button::setHeight (height);
69 buttonLabel.setHeight (height);
70 }
71
resize()72 void TextButton::resize ()
73 {
74 buttonLabel.resize ();
75 Widget::resize ();
76 }
77
resize(const double width,const double height)78 void TextButton::resize (const double width, const double height) {TextButton::resize (BUtilities::Point (width, height));}
79
resize(const BUtilities::Point extends)80 void TextButton::resize (const BUtilities::Point extends)
81 {
82 Widget::resize (BUtilities::Point (extends.x, extends.y));
83 buttonLabel.resize (BUtilities::Point (extends.x, extends.y));
84 }
85
setValue(const double val)86 void TextButton::setValue (const double val)
87 {
88 if (val) buttonLabel.setState (BColors::ACTIVE);
89 else buttonLabel.setState (BColors::NORMAL);
90 Button::setValue (val);
91 }
92
getLabel()93 Label* TextButton::getLabel () {return &buttonLabel;}
94
applyTheme(BStyles::Theme & theme)95 void TextButton::applyTheme (BStyles::Theme& theme) {applyTheme (theme, name_);}
applyTheme(BStyles::Theme & theme,const std::string & name)96 void TextButton::applyTheme (BStyles::Theme& theme, const std::string& name)
97 {
98 Button::applyTheme (theme, name);
99 buttonLabel.applyTheme (theme, name);
100 update ();
101 }
102
103 }
104