2 GoatKit - a themable/animated widget toolkit for games
3 Copyright (C) 2014 John Tsiombikas <nuclear@member.fsf.org>
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
32 tbox = new TextBoxImpl;
41 const char *TextBox::get_type_name() const
46 bool TextBox::can_focus() const
56 void TextBox::set_text(const char *t)
58 tbox->text = std::string(t);
61 const char *TextBox::get_text() const
63 return tbox->text.c_str();
66 int TextBox::set_cursor(int idx)
68 int len = tbox->text.size();
72 } else if(idx > len) {
80 int TextBox::get_cursor() const
85 int TextBox::cursor_begin()
87 return tbox->cursor = 0;
90 int TextBox::cursor_end()
92 return set_cursor(INT_MAX);
95 int TextBox::cursor_prev()
97 return set_cursor(tbox->cursor - 1);
100 int TextBox::cursor_next()
102 return set_cursor(tbox->cursor + 1);
105 void TextBox::insert(char c)
107 int len = tbox->text.size();
108 if(tbox->cursor >= len) {
109 tbox->text.push_back(c);
112 tbox->text.insert(tbox->cursor++, 1, c);
116 void TextBox::on_key(const KeyEvent &ev)
118 if(!ev.press) return; // ignore key release events
138 tbox->text.erase(tbox->cursor, 1);
142 if(tbox->cursor > 0) {
143 tbox->text.erase(--tbox->cursor, 1);
157 if(isprint(ev.key)) {
163 void TextBox::on_click()
168 } // namespace goatkit