X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fentry.cpp;h=28b454d90d10c62ab589ae5e8daca9246bd044f8;hb=6081ed9020ad22214a8e5b3829092f97b12d7c71;hp=efb4b45c57d354ca4f11b453ff567fe58d108421;hpb=9b29612d1cde85fee9b3f011e86a5cabe5dbcce3;p=libs%2Fgltk.git diff --git a/source/entry.cpp b/source/entry.cpp index efb4b45..28b454d 100644 --- a/source/entry.cpp +++ b/source/entry.cpp @@ -16,17 +16,16 @@ Distributed under the LGPL using namespace std; -#include - namespace Msp { namespace GLtk { Entry::Entry(const Resources &r, const string &t): Widget(r), - text(t), - edit_pos(text.size()) + text(), + edit_pos(0) { update_style(); + set_text(t); } void Entry::set_text(const string &t) @@ -52,7 +51,9 @@ void Entry::key_press(unsigned key, unsigned, wchar_t ch) if(edit_pos>0) text.erase(--edit_pos, 1); } - else + else if(key==Input::KEY_ENTER) + signal_enter.emit(); + else if(ch>=' ') { text.insert(edit_pos, Codecs::encode(Codecs::ustring(1, ch))); ++edit_pos; @@ -62,7 +63,7 @@ void Entry::key_press(unsigned key, unsigned, wchar_t ch) void Entry::render_special(const Part &part) const { if(part.get_name()=="text") - render_text(part, text); + text.render(part, geom); else if(part.get_name()=="cursor") { if(!part.get_graphic(state)) @@ -72,8 +73,8 @@ void Entry::render_special(const Part &part) const const float font_size=font->get_default_size(); Geometry rgeom=part.get_geometry(); - rgeom.x=static_cast(font->get_string_width(text.substr(0, edit_pos))*font_size); - rgeom.w=static_cast(font->get_string_width(text)*font_size); + rgeom.x=static_cast(font->get_string_width(text.get().substr(0, edit_pos))*font_size); + rgeom.w=static_cast(font->get_string_width(text.get())*font_size); part.get_alignment().apply(rgeom, geom, part.get_margin()); GL::push_matrix(); @@ -83,6 +84,11 @@ void Entry::render_special(const Part &part) const } } +void Entry::on_style_change() +{ + text.set_style(style); +} + Entry::Loader::Loader(Entry &ent): Widget::Loader(ent)