1 /* TextToggleButton.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 "TextToggleButton.hpp"
19
20 namespace BWidgets
21 {
TextToggleButton()22 TextToggleButton::TextToggleButton () : TextToggleButton (0.0, 0.0, BWIDGETS_DEFAULT_BUTTON_WIDTH, BWIDGETS_DEFAULT_BUTTON_HEIGHT,
23 "texttogglebutton", "", 0.0) {}
24
TextToggleButton(const double x,const double y,const double width,const double height,const std::string & name,double defaultValue)25 TextToggleButton::TextToggleButton (const double x, const double y, const double width, const double height, const std::string& name, double defaultValue) :
26 TextToggleButton (x, y, width, height, name, name, defaultValue) {}
27
TextToggleButton(const double x,const double y,const double width,const double height,const std::string & name,const std::string & label,double defaultValue)28 TextToggleButton::TextToggleButton (const double x, const double y, const double width, const double height,
29 const std::string& name, const std::string& label, double defaultValue) :
30 ToggleButton (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
TextToggleButton(const TextToggleButton & that)39 TextToggleButton::TextToggleButton (const TextToggleButton& that) : ToggleButton (that), buttonLabel (that.buttonLabel)
40 {
41 add (buttonLabel);
42 }
43
~TextToggleButton()44 TextToggleButton:: ~TextToggleButton () {}
45
operator =(const TextToggleButton & that)46 TextToggleButton& TextToggleButton::operator= (const TextToggleButton& that)
47 {
48 release (&buttonLabel);
49
50 ToggleButton::operator= (that);
51 buttonLabel = that.buttonLabel;
52
53 add (buttonLabel);
54
55 return *this;
56 }
57
clone() const58 Widget* TextToggleButton::clone () const {return new TextToggleButton (*this);}
59
setWidth(const double width)60 void TextToggleButton::setWidth (const double width)
61 {
62 Button::setWidth (width);
63 buttonLabel.setWidth (width);
64 }
65
setHeight(const double height)66 void TextToggleButton::setHeight (const double height)
67 {
68 Button::setHeight (height);
69 buttonLabel.setHeight (height);
70 }
71
resize()72 void TextToggleButton::resize ()
73 {
74 buttonLabel.resize ();
75 Widget::resize ();
76 }
77
resize(const double width,const double height)78 void TextToggleButton::resize (const double width, const double height) {TextToggleButton::resize (BUtilities::Point (width, height));}
79
resize(const BUtilities::Point extends)80 void TextToggleButton::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 TextToggleButton::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* TextToggleButton::getLabel () {return &buttonLabel;}
94
applyTheme(BStyles::Theme & theme)95 void TextToggleButton::applyTheme (BStyles::Theme& theme) {applyTheme (theme, name_);}
applyTheme(BStyles::Theme & theme,const std::string & name)96 void TextToggleButton::applyTheme (BStyles::Theme& theme, const std::string& name)
97 {
98 ToggleButton::applyTheme (theme, name);
99 buttonLabel.applyTheme (theme, name);
100 update ();
101 }
102
103 }
104