#include <ugadgets.hpp>
Inheritance diagram for UTextfield:
Public Member Functions | |
UTextfield (const UArgs &=UArgs::none) | |
constructor; see also ~UGroup() and the creator shortcut utextfield() | |
UEdit & | edit () |
const UEdit & | edit () const |
virtual void | setEditable (bool state=true) |
virtual bool | isEditable () const |
Friends | |
UTextfield & | utextfield (const UArgs &a=UArgs::none) |
creator shortcut that is equivalent to *new UTextField(). |
A UTextfield is a UTextbox that can edit text.
utextfield( "bla bla" );is functionally equivalent to:
utextbox( uedit() + "bla bla" );
A textbox can contain arbitrary children (for instance pixmap images, other gadgets...) If a textbox contain several UStr(s) all of them are editable.
UStr& msg = ustr("my message"); utextfield( UPix::doc + "Error: " + UPix::ray + msg )
Geometry: Same Geometry and Properties as UTextbox except that the text is editable and the default background is white. This gadget keeps its initial size (which is calculated to make children that were added at creation time visible). See UTextbox for details.
Callbacks: as for other UBox subclasses generic callback conditions make it possible to specify callback methods and functions: see class UCond. For instance:
Exemple:
XXX* obj = ...; UStr& msg = ustr("error message"); utextfield( UPix::ray + msg + UOn::action / ucall(obj, &XXX::foo1) + UOn::strChange / ucall(obj, &msg, &XXX::foo2) )foo1 and foo2 are XXX methods (non member functions can also be specified: see class UCall). There are several ways to retreive the text in callback functions: foo1() retreives all the text included in the textfield while foo2() passes 'msg' as an argument. The text can be changed by foo2() but not by foo1().
void XXX::foo1(UEvent& e) { if (e.getSource()) { // returns the textfield // collates the text enclosed in the textfield and copies it to 's' UStr s = e.getSource()->copyText(); cout << s << endl; }
void XXX::foo2(UStr* s) { // 's' points to 'msg'. 'msg' is changed if 's' is changed. cout << *s << endl; }