1.1-rc3
Public Types | Public Member Functions | Static Public Member Functions | Protected Types | Protected Member Functions | Protected Attributes | List of all members
TextBox Class Reference

Input text box. More...

Inheritance diagram for TextBox:
Inheritance graph
[legend]

Public Types

enum  TextFlag : uint32_t { fit_to_width = detail::bit(0), multiline = detail::bit(1), word_wrap = detail::bit(2), no_virt_keyboard = detail::bit(3) }
 Text flags. More...
 
using TextFlags = egt::Flags< TextFlag >
 Text flags. More...
 
using ValidatorCallback = std::function< bool(const std::string &)>
 Validator callback type. More...
 
- Public Types inherited from Widget
enum  Flag : uint32_t {
  plane_window = detail::bit(0), window = detail::bit(1), frame = detail::bit(2), disabled = detail::bit(3),
  readonly = detail::bit(4), active = detail::bit(5), invisible = detail::bit(6), grab_mouse = detail::bit(7),
  no_clip = detail::bit(8), no_layout = detail::bit(9), no_autoresize = detail::bit(10), checked = detail::bit(11)
}
 Common flags used for various widget properties. More...
 
using Flags = egt::Flags< Widget::Flag >
 Widget flags. More...
 
using WalkCallback = std::function< bool(Widget *widget, int level)>
 Callback definition used by walk(). More...
 
using WidgetId = uint64_t
 Type used to identify a unique Widget ID. More...
 
- Public Types inherited from Object
using EventCallback = std::function< void(Event &event)>
 Event handler callback function. More...
 
using FilterFlags = FlagsBase< EventId >
 Event handler EventId filter. More...
 
using RegisterHandle = uint64_t
 Handle type. More...
 

Public Member Functions

 TextBox (const std::string &text, const Rect &rect, const AlignFlags &text_align=default_text_align(), const TextFlags &flags={}) noexcept
 
 TextBox (const std::string &text, const TextFlags &flags, const AlignFlags &text_align=default_text_align()) noexcept
 
 TextBox (const std::string &text={}, const AlignFlags &text_align=default_text_align(), const TextFlags &flags={}) noexcept
 
 TextBox (const TextBox &)=delete
 
 TextBox (Frame &parent, const std::string &text, const Rect &rect, const AlignFlags &text_align=default_text_align(), const TextFlags &flags={}) noexcept
 
 TextBox (Frame &parent, const std::string &text={}, const AlignFlags &text_align=default_text_align(), const TextFlags &flags={}) noexcept
 
 TextBox (TextBox &&)=default
 
 ~TextBox () noexcept override
 
void add_validator_function (ValidatorCallback callback)
 Add a callback to be invoked to validate the input. More...
 
size_t append (const std::string &str)
 Move the cursor to the end and insert. More...
 
void clear () override
 Clear the text value. More...
 
EGT_NODISCARD size_t cursor () const
 Get the cursor position. More...
 
void cursor_backward (size_t count=1)
 Move the cursor backward by the specified count from the current position. More...
 
void cursor_begin ()
 Move the cursor to the beginning. More...
 
void cursor_end ()
 Move the cursor to the end. More...
 
void cursor_forward (size_t count=1)
 Move the cursor forward by the specified count from the current position. More...
 
void cursor_set (size_t pos)
 Set the cursor to the specific position. More...
 
void deserialize (const std::string &name, const std::string &value, const Serializer::Attributes &attrs) override
 Deserialize widget properties. More...
 
void draw (Painter &painter, const Rect &rect) override
 Draw the widget. More...
 
void handle (Event &event) override
 Handle an event. More...
 
void input_validation_enabled (bool enabled)
 Enable or disable input validation. More...
 
size_t insert (const std::string &str)
 Insert text at the cursor. More...
 
EGT_NODISCARD size_t max_length () const
 Get the max length of allowed text. More...
 
void max_length (size_t len)
 Set the maximum allowed length of the text. More...
 
EGT_NODISCARD Size min_size_hint () const override
 Get a minimum size hint for the Widget. More...
 
TextBoxoperator= (const TextBox &)=delete
 
TextBoxoperator= (TextBox &&)=default
 
EGT_NODISCARD std::string selected_text () const
 Get, or copy, the selected text. More...
 
void selection (size_t pos, size_t length)
 Set the selection of text. More...
 
void selection_all ()
 Select all of the text. More...
 
void selection_clear ()
 Clear any selection. More...
 
void selection_delete ()
 Delete the selected text. More...
 
EGT_NODISCARD size_t selection_length () const
 Get the length of the selection. More...
 
EGT_NODISCARD size_t selection_start () const
 Get the start position of the selection. More...
 
void serialize (Serializer &serializer) const override
 Serialize the widget to the specified serializer. More...
 
virtual const EGT_NODISCARD std::string & text () const
 Get the text of the Label. More...
 
virtual void text (const std::string &str)
 Set the text. More...
 
void text (const std::string &str) override
 Set the text. More...
 
const EGT_NODISCARD TextFlagstext_flags () const
 Get a const ref of the flags. More...
 
- Public Member Functions inherited from TextWidget
 TextWidget (std::string text={}, const Rect &rect={}, const AlignFlags &text_align=AlignFlag::center) noexcept
 
void deserialize (const std::string &name, const std::string &value, const Serializer::Attributes &attrs) override
 Deserialize widget properties. More...
 
virtual EGT_NODISCARD size_t len () const
 Get the length of the text. More...
 
void serialize (Serializer &serializer) const override
 Serialize the widget to the specified serializer. More...
 
virtual const EGT_NODISCARD std::string & text () const
 Get the text of the Label. More...
 
EGT_NODISCARD AlignFlags text_align () const
 Get the text alignment within the Label. More...
 
void text_align (const AlignFlags &align)
 Set the text alignment within the Label. More...
 
- Public Member Functions inherited from Widget
 Widget (const Rect &rect={}, const Widget::Flags &flags={}) noexcept
 
 Widget (const Widget &)=delete
 
 Widget (Frame &parent, const Rect &rect={}, const Widget::Flags &flags={}) noexcept
 
 Widget (Widget &&) noexcept=default
 
 ~Widget () noexcept override
 
EGT_NODISCARD bool active () const
 Get the active state. More...
 
void active (bool value)
 Set the active state. More...
 
AlignFlagsalign ()
 Get the alignment. More...
 
const EGT_NODISCARD AlignFlagsalign () const
 Get the alignment. More...
 
void align (const AlignFlags &a)
 Align the widget. More...
 
EGT_NODISCARD float alpha () const
 Get the alpha property. More...
 
void alpha (float alpha)
 Set the alpha property. More...
 
EGT_NODISCARD bool autoresize () const
 Return the autoresize state of the widget. More...
 
void autoresize (bool value)
 Set the autoresize state. More...
 
EGT_NODISCARD DefaultDim border () const
 Get the border width. More...
 
void border (DefaultDim border)
 Set the border width. More...
 
EGT_NODISCARD Theme::BorderFlags border_flags () const
 Get the border flags. More...
 
void border_flags (const Theme::BorderFlags &flags)
 Set the border flags. More...
 
EGT_NODISCARD float border_radius () const
 Get the border radius. More...
 
void border_radius (float radius)
 Set the border radius. More...
 
const EGT_NODISCARD Rectbox () const
 Bounding box for the Widget. More...
 
void box (const Rect &rect)
 Change the bounding box of the widget. More...
 
bool can_handle_event () const
 Returns true if the widget is capable of handling an event. More...
 
EGT_NODISCARD Point center () const
 Get the center point of the widget's box(). More...
 
EGT_NODISCARD bool checked () const
 Get the boolean checked state of the a widget. More...
 
virtual void checked (bool value)
 Set the checked state of the widget. More...
 
EGT_NODISCARD bool clip () const
 Return the clip state of the widget. More...
 
const EGT_NODISCARD Patterncolor (Palette::ColorId id) const
 Get a Widget color. More...
 
void color (Palette::ColorId id, const Pattern &color, Palette::GroupId group=Palette::GroupId::normal)
 Add a color to the widget's instance palette. More...
 
const EGT_NODISCARD Patterncolor (Palette::ColorId id, Palette::GroupId group) const
 Get a Widget color. More...
 
virtual EGT_NODISCARD Rect content_area () const
 Return the area that content is allowed to be positioned into. More...
 
virtual void damage ()
 Damage the box() of the widget and cause a redraw. More...
 
virtual void damage (const Rect &rect)
 Mark the specified rect as a damaged area of the widget. More...
 
void detach ()
 Detach this widget from its parent. More...
 
void disable ()
 Set the disabled state to true. More...
 
void disable_toggle ()
 Toggle the disabled state. More...
 
EGT_NODISCARD bool disabled () const
 Return the disabled state of the widget. More...
 
void disabled (bool value)
 Set the disabled state. More...
 
DisplayPoint display_origin ()
 Get the display origin of the Widget. More...
 
virtual Point display_to_local (const DisplayPoint &p)
 Convert a display point to a local point. More...
 
void draw_box (Painter &painter, Palette::ColorId bg, Palette::ColorId border) const
 Helper function to draw this widget's box using the appropriate theme. More...
 
void draw_circle (Painter &painter, Palette::ColorId bg, Palette::ColorId border) const
 Helper function to draw this widget's circle using the appropriate theme. More...
 
void enable ()
 Set the disabled state to false. More...
 
Theme::FillFlagsfill_flags ()
 Get a modifiable fill flags reference. More...
 
const EGT_NODISCARD Theme::FillFlagsfill_flags () const
 Get the fill flags. More...
 
void fill_flags (const Theme::FillFlags &flags)
 Set the fill flags. More...
 
EGT_NODISCARD bool focus () const
 Get the current focus state. More...
 
const EGT_NODISCARD Fontfont () const
 Get the widget Font. More...
 
void font (const Font &font)
 Set the widget Font. More...
 
EGT_NODISCARD bool frame () const
 Return the frame state of the widget. More...
 
EGT_NODISCARD bool grab_mouse () const
 Return the grab_mouse state of the widget. More...
 
void grab_mouse (bool value)
 Set the grab_mouse state. More...
 
EGT_NODISCARD DefaultDim height () const
 Height of the widget's box(). More...
 
void height (DefaultDim h)
 Change the height. More...
 
virtual void hide ()
 Hide the Widget. More...
 
EGT_NODISCARD DefaultDim horizontal_ratio () const
 Get the horizontal ratio relative to parent. More...
 
void horizontal_ratio (DefaultDim horizontal)
 Set the horizontal ratio relative to parent. More...
 
EGT_NODISCARD bool in_layout () const
 Indicate if the Widget is computing the layout or not. More...
 
virtual void layout ()
 Perform layout of the Widget. More...
 
DisplayPoint local_to_display (const Point &p)
 Convert a local point to a display point. More...
 
EGT_NODISCARD DefaultDim margin () const
 Get the margin width. More...
 
void margin (DefaultDim margin)
 Set the margin width. More...
 
void min_size_hint (const Size &size)
 Set the minimum size hint for the Widget. More...
 
EGT_NODISCARD size_t moat () const
 Get the sum of the margin(), padding(), and border() around the content of the widget. More...
 
virtual void move (const Point &point)
 Move the Widget to a new position. More...
 
void move_to_center ()
 Move the widget to the center of its parent. More...
 
void move_to_center (const Point &point)
 Move the widget to the specified center point. More...
 
EGT_NODISCARD bool no_layout () const
 Return the no_layout state of the widget. More...
 
void no_layout (bool value)
 Set the no_layout state. More...
 
Widgetoperator= (const Widget &)=delete
 
Widgetoperator= (Widget &&) noexcept=default
 
EGT_NODISCARD DefaultDim padding () const
 Return the padding width. More...
 
void padding (DefaultDim padding)
 Set the padding width. More...
 
virtual void paint (Painter &painter)
 Paint the Widget using a Painter. More...
 
virtual void paint_to_file (const std::string &filename={})
 Draw the widget to a file. More...
 
void palette (const Palette &palette)
 Set the widget instance Palette. More...
 
Frameparent ()
 Get a pointer to the parent Frame, or nullptr if none exists. More...
 
const EGT_NODISCARD Frameparent () const
 Get a pointer to the parent Frame, or nullptr if none exists. More...
 
EGT_NODISCARD bool plane_window () const
 Return the plane_window state of the widget. More...
 
const EGT_NODISCARD Pointpoint () const
 Get the origin of the widget's box(). More...
 
void ratio (DefaultDim horizontal, DefaultDim vertical)
 Set the size ratio relative to parent. More...
 
void ratio (DefaultDim ratio)
 Set the size ratio relative to parent. More...
 
EGT_NODISCARD bool readonly () const
 Get the readonly state of the widget. More...
 
void readonly (bool value)
 Set the readonly state of the widget. More...
 
void readonly_toggle ()
 Toggle the readonly state. More...
 
void reset_palette ()
 Clear the widget instance palette. More...
 
void reset_theme ()
 Reset the Widget's Theme to the default Theme. More...
 
virtual void resize (const Size &size)
 Resize the widget. More...
 
void resize_by_ratio (DefaultDim hratio, DefaultDim vratio)
 Scale the current size of the Widget given the ratio. More...
 
void resize_by_ratio (DefaultDim ratio)
 Scale the current size of the Widget given the ratio. More...
 
virtual void scale (float hscale, float vscale)
 Set the scale of the widget. More...
 
void scale (float scale)
 Set the scale of the widget. More...
 
virtual EGT_NODISCARD Screenscreen () const
 Get a pointer to the Screen instance, using using a parent as necessary. More...
 
virtual void show ()
 Show the Widget. More...
 
const EGT_NODISCARD Sizesize () const
 Get the size of the widget's box(). More...
 
const EGT_NODISCARD Themetheme () const
 Get the Widget Theme. More...
 
void theme (const Theme &theme)
 Set the Widget's theme to a new theme. More...
 
EGT_NODISCARD Point to_parent (const Point &r) const
 Convert a point with a local origin to a parent origin. More...
 
EGT_NODISCARD Rect to_parent (const Rect &r) const
 Convert a point in a rect a local origin to a parent origin. More...
 
virtual EGT_NODISCARD std::string type () const
 Returns a string representation of the type of this widget. More...
 
const EGT_NODISCARD Rectuser_requested_box () const
 Get the box corresponding to the user requested one, not the actual one. More...
 
EGT_NODISCARD DefaultDim vertical_ratio () const
 Get the vertical ratio relative to parent. More...
 
void vertical_ratio (DefaultDim vertical)
 Set the vertical ratio relative to parent. More...
 
EGT_NODISCARD bool visible () const
 Get the visible state of the widget. More...
 
void visible (bool value)
 Set the visible state. More...
 
void visible_toggle ()
 Toggle the visibility state. More...
 
virtual void walk (const WalkCallback &callback, int level=0)
 Walk the Widget tree and call callback with each Widget. More...
 
EGT_NODISCARD WidgetId widgetid () const
 Get the unique id of the widget. More...
 
EGT_NODISCARD DefaultDim width () const
 Width of the widget's box(). More...
 
void width (DefaultDim w)
 Change the width. More...
 
EGT_NODISCARD DefaultDim x () const
 X coordinate of the widget's box(). More...
 
void x (DefaultDim x)
 Set the X coordinate of the box. More...
 
EGT_NODISCARD DefaultDim xratio () const
 Get the X position ratio relative to parent. More...
 
void xratio (DefaultDim xratio)
 Set the X position ratio relative to parent. More...
 
EGT_NODISCARD DefaultDim y () const
 Y coordinate of the widget's box(). More...
 
void y (DefaultDim y)
 Set the Y coordinate of the box. More...
 
EGT_NODISCARD DefaultDim yratio () const
 Get the Y position ratio relative to parent. More...
 
void yratio (DefaultDim yratio)
 Set the Y position ratio relative to parent. More...
 
virtual EGT_NODISCARD size_t zorder () const
 Get the zorder of the widget. More...
 
virtual void zorder_bottom ()
 Move the widget to the bottom. More...
 
virtual void zorder_down ()
 Move this widgets zorder down relative to other widgets with the same parent. More...
 
virtual void zorder_top ()
 Move the widget to the top. More...
 
virtual void zorder_up ()
 Move this widgets zorder up relative to other widgets with the same parent. More...
 
- Public Member Functions inherited from Object
 Object () noexcept=default
 
 Object (const Object &)=delete
 
 Object (Object &&)=default
 
virtual ~Object () noexcept=default
 
void clear_handlers ()
 Clear all registered event handlers. More...
 
void invoke_handlers (Event &event)
 Invoke all handlers with the specified event. More...
 
void invoke_handlers (EventId event)
 Invoke all handlers with the specified EventId. More...
 
const EGT_NODISCARD std::string & name () const
 Get the name of the Object. More...
 
void name (const std::string &name)
 Set the name of the Object. More...
 
RegisterHandle on_event (const EventCallback &handler, const FilterFlags &mask={})
 Add an event handler to be called when the widget generates an event. More...
 
Objectoperator= (const Object &)=delete
 
Objectoperator= (Object &&)=default
 
void remove_handler (RegisterHandle handle)
 Remove an event handler. More...
 

Static Public Member Functions

static AlignFlags default_text_align ()
 Change text align. More...
 
static void default_text_align (const AlignFlags &align)
 Change default text align. More...
 
- Static Public Member Functions inherited from TextWidget
static Font scale_font (const Size &target, const std::string &text, const Font &font)
 Given a Font, text, and a target Size, scale the font size so that the text will will fit and return the new Font. More...
 

Protected Types

using ValidatorCallbackArray = std::vector< ValidatorCallback >
 Type array used for validator callbacks. More...
 
- Protected Types inherited from Object
using CallbackArray = std::vector< CallbackMeta >
 Helper type for an array of callbacks. More...
 

Protected Member Functions

void continue_show_cursor ()
 If the cursor is shown, keep is shown some more. More...
 
void handle_key (const Key &key)
 Process key events. More...
 
void hide_cursor ()
 Hide/disable the visibility of the cursor. More...
 
void show_cursor ()
 Show/enable the visibility of the cursor. More...
 
bool validate_input (const std::string &str)
 Validate the input against the validator pattern. More...
 
EGT_NODISCARD size_t width_to_len (const std::string &str) const
 Given text, return the number of UTF8 characters that will fit on a single line inside of the widget. More...
 
- Protected Member Functions inherited from TextWidget
EGT_NODISCARD Size text_size (const std::string &text) const
 Get the size of the text. More...
 
- Protected Member Functions inherited from Widget
const EGT_NODISCARD Palettedefault_palette () const
 Get a reference to the default palette. More...
 
Widget::Flagsflags ()
 Get a modifiable ref of the flags. More...
 
const EGT_NODISCARD Widget::Flagsflags () const
 Get a const ref of the flags. More...
 
EGT_NODISCARD Rect local_box () const
 Get the local box which is the same size as box(), but with the origin zeroed. More...
 
EGT_NODISCARD bool parent_in_layout ()
 Indicate if our parent is computing the layout. More...
 
void parent_layout ()
 Call our parent to do a layout. More...
 
virtual void set_parent (Frame *parent)
 Set this widget's parent. More...
 
virtual EGT_NODISCARD bool top_level () const
 Is this widget a top level widget? More...
 

Protected Attributes

size_t m_cursor_pos {0}
 The current position of the cursor. More...
 
size_t m_select_len {0}
 Selection length. More...
 
size_t m_select_start {0}
 Selection start position. More...
 
PeriodicTimer m_timer
 Timer for blinking the cursor. More...
 
bool m_validate_input {false}
 Validation of the input. More...
 
ValidatorCallbackArray m_validator_callbacks
 Callbacks invoked to validate the input. More...
 
- Protected Attributes inherited from TextWidget
std::string m_text
 The text. More...
 
AlignFlags m_text_align {AlignFlag::center}
 Alignment of the text. More...
 
- Protected Attributes inherited from Widget
Rect m_box
 Bounding box. More...
 
bool m_in_layout {false}
 Status for whether this widget is currently performing layout. More...
 
Size m_min_size
 Minimum size of the widget when not an empty value. More...
 
Framem_parent {nullptr}
 Pointer to this widget's parent. More...
 
Rect m_user_requested_box
 Keep track of the box requested by the user. More...
 
WidgetId m_widgetid {0}
 Unique ID of this widget. More...
 
- Protected Attributes inherited from Object
detail::CopyOnWriteAllocate< CallbackArraym_callbacks
 Array of callbacks. More...
 
RegisterHandle m_handle_counter {0}
 Counter used to generate unique handles for each callback registration. More...
 
std::string m_name
 A user defined name for the Object. More...
 

Additional Inherited Members

- Public Attributes inherited from TextWidget
Signal on_text_changed
 Event signal. More...
 
- Public Attributes inherited from Widget
Signal on_checked_changed
 Event signal. More...
 
Signal on_gain_focus
 Invoked when the widget gains focus. More...
 
Signal on_lost_focus
 Invoked when the widget loses focus. More...
 
Signal on_show
 Invoked when a widget is shown. More...
 
Signal on_hide
 Invoked when a widget is hidden. More...
 

Detailed Description

Input text box.

Supported Features:

Example

TextBox textbox;

Member Typedef Documentation

◆ TextFlags

Text flags.

◆ ValidatorCallback

using ValidatorCallback = std::function<bool(const std::string&)>

Validator callback type.

See also
add_validator_function()

◆ ValidatorCallbackArray

using ValidatorCallbackArray = std::vector<ValidatorCallback>
protected

Type array used for validator callbacks.

Member Enumeration Documentation

◆ TextFlag

enum TextFlag : uint32_t
strong

Text flags.

Enumerator
fit_to_width 

When not multiline, only allow max length to be what can fit.

multiline 

Enable multi-line text.

word_wrap 

Wrap at word boundaries instead of character boundaries. Must be flag::multiline.

no_virt_keyboard 

Do not display a virtual keyboard when focus is gained.

Constructor & Destructor Documentation

◆ TextBox() [1/7]

TextBox ( const std::string &  text = {},
const AlignFlags text_align = default_text_align(),
const TextFlags flags = {} 
)
explicitnoexcept
Parameters
[in]textThe text to display.
[in]text_alignAlignment for the text.
[in]flagsTextBox flags.

◆ TextBox() [2/7]

TextBox ( const std::string &  text,
const TextFlags flags,
const AlignFlags text_align = default_text_align() 
)
explicitnoexcept
Parameters
[in]textThe text to display.
[in]text_alignAlignment for the text.
[in]flagsTextBox flags.

◆ TextBox() [3/7]

TextBox ( const std::string &  text,
const Rect rect,
const AlignFlags text_align = default_text_align(),
const TextFlags flags = {} 
)
noexcept
Parameters
[in]textThe text to display.
[in]rectRectangle for the widget.
[in]text_alignAlignment for the text.
[in]flagsTextBox flags.

◆ TextBox() [4/7]

TextBox ( Frame parent,
const std::string &  text = {},
const AlignFlags text_align = default_text_align(),
const TextFlags flags = {} 
)
explicitnoexcept
Parameters
[in]parentThe parent Frame.
[in]textThe text to display.
[in]text_alignAlignment for the text.
[in]flagsTextBox flags.

◆ TextBox() [5/7]

TextBox ( Frame parent,
const std::string &  text,
const Rect rect,
const AlignFlags text_align = default_text_align(),
const TextFlags flags = {} 
)
noexcept
Parameters
[in]parentThe parent Frame.
[in]textThe text to display.
[in]rectRectangle for the widget.
[in]text_alignAlignment for the text.
[in]flagsTextBox flags.

◆ TextBox() [6/7]

TextBox ( const TextBox )
delete

◆ TextBox() [7/7]

TextBox ( TextBox &&  )
default

◆ ~TextBox()

~TextBox ( )
overridenoexcept

Member Function Documentation

◆ add_validator_function()

void add_validator_function ( ValidatorCallback  callback)

Add a callback to be invoked to validate the input.

Anytime the text is changed, the callback will be invoked with the new text for validation.

To enable this, you must set input_validation_enabled() to true.

◆ append()

size_t append ( const std::string &  str)

Move the cursor to the end and insert.

The is the same as doing:

insert(str);
Parameters
strThe string to append.

◆ clear()

void clear ( )
overridevirtual

Clear the text value.

Reimplemented from TextWidget.

◆ continue_show_cursor()

void continue_show_cursor ( )
protected

If the cursor is shown, keep is shown some more.

◆ cursor()

EGT_NODISCARD size_t cursor ( ) const

Get the cursor position.

◆ cursor_backward()

void cursor_backward ( size_t  count = 1)

Move the cursor backward by the specified count from the current position.

Parameters
countThe number of characters to move.

◆ cursor_begin()

void cursor_begin ( )

Move the cursor to the beginning.

◆ cursor_end()

void cursor_end ( )

Move the cursor to the end.

◆ cursor_forward()

void cursor_forward ( size_t  count = 1)

Move the cursor forward by the specified count from the current position.

Parameters
countThe number of characters to move.

◆ cursor_set()

void cursor_set ( size_t  pos)

Set the cursor to the specific position.

Parameters
posThe new cursor position.

◆ default_text_align() [1/2]

static AlignFlags default_text_align ( )
static

Change text align.

◆ default_text_align() [2/2]

static void default_text_align ( const AlignFlags align)
static

Change default text align.

◆ deserialize()

void deserialize ( const std::string &  name,
const std::string &  value,
const Serializer::Attributes attrs 
)
overridevirtual

Deserialize widget properties.

Reimplemented from Widget.

◆ draw()

void draw ( Painter painter,
const Rect rect 
)
overridevirtual

Draw the widget.

To change how a widget is drawn, this function can be overloaded and changed in a derived class, or it can be changed dynamically with the Theme.

To optimize drawing, a Widget may use the Rect parameter to limit what needs to be redrawn, which may be smaller than the widget's box(), but will never be outside the widget's box().

Painter will always be supplied in a default state to this function, so there is no need to do any cleanup or state saving inside this draw() function.

Warning
Normally this should not be called directly and instead the EventLoop will call this function with an already established Painter when the Widget needs to be drawn.
See also
Color, Palette, and Theme and Drawing
Parameters
[in]painterInstance of the Painter for the Screen.
[in]rectThe rectangle to draw.

Implements Widget.

◆ handle()

void handle ( Event event)
overridevirtual

Handle an event.

This handles global events that usually do not originate at the widget. For example, a pointer event. All events are defined by egt::EventId.

The default implementation in the Widget class, will dispatch the event to any third party handlers that have been registered with on_event(). What this means is if you expect other handlers to receive the events then this must be called from derived classes. Or, manually call invoke_handlers().

Override this function in a derived class to handle events.

See also
Events
Parameters
eventThe Event that occurred.

Reimplemented from Widget.

◆ handle_key()

void handle_key ( const Key key)
protected

Process key events.

◆ hide_cursor()

void hide_cursor ( )
protected

Hide/disable the visibility of the cursor.

◆ input_validation_enabled()

void input_validation_enabled ( bool  enabled)

Enable or disable input validation.

Invoke the validator callbacks. If one of them returns false, the input is rejected.

◆ insert()

size_t insert ( const std::string &  str)

Insert text at the cursor.

Parameters
strThe string to insert.
Returns
The number of characters inserted.

◆ max_length() [1/2]

EGT_NODISCARD size_t max_length ( ) const
inline

Get the max length of allowed text.

◆ max_length() [2/2]

void max_length ( size_t  len)

Set the maximum allowed length of the text.

Parameters
lenThe maximum length of the text.

◆ min_size_hint()

EGT_NODISCARD Size min_size_hint ( ) const
overridevirtual

Get a minimum size hint for the Widget.

This is used by sizers to pick minimum and default dimensions when no other force is used.

Reimplemented from Widget.

◆ operator=() [1/2]

TextBox& operator= ( const TextBox )
delete

◆ operator=() [2/2]

TextBox& operator= ( TextBox &&  )
default

◆ selected_text()

EGT_NODISCARD std::string selected_text ( ) const

Get, or copy, the selected text.

Returns
The selected text, or an empty string if there is no selection.

◆ selection()

void selection ( size_t  pos,
size_t  length 
)

Set the selection of text.

Parameters
posThe starting position.
lengthThe length of the selection.

◆ selection_all()

void selection_all ( )

Select all of the text.

◆ selection_clear()

void selection_clear ( )

Clear any selection.

Note
This does not delete text, it just clears the selection. To delete the selected text call delete_selection().

◆ selection_delete()

void selection_delete ( )

Delete the selected text.

◆ selection_length()

EGT_NODISCARD size_t selection_length ( ) const
inline

Get the length of the selection.

◆ selection_start()

EGT_NODISCARD size_t selection_start ( ) const
inline

Get the start position of the selection.

◆ serialize()

void serialize ( Serializer serializer) const
overridevirtual

Serialize the widget to the specified serializer.

Reimplemented from Widget.

◆ show_cursor()

void show_cursor ( )
protected

Show/enable the visibility of the cursor.

◆ text() [1/3]

virtual const EGT_NODISCARD std::string& text
inline

Get the text of the Label.

◆ text() [2/3]

virtual void text

Set the text.

Parameters
strThe text string to set.

◆ text() [3/3]

void text ( const std::string &  str)
overridevirtual

Set the text.

Parameters
strThe text string to set.

Reimplemented from TextWidget.

◆ text_flags()

const EGT_NODISCARD TextFlags& text_flags ( ) const
inline

Get a const ref of the flags.

◆ validate_input()

bool validate_input ( const std::string &  str)
protected

Validate the input against the validator pattern.

◆ width_to_len()

EGT_NODISCARD size_t width_to_len ( const std::string &  str) const
protected

Given text, return the number of UTF8 characters that will fit on a single line inside of the widget.

Member Data Documentation

◆ m_cursor_pos

size_t m_cursor_pos {0}
protected

The current position of the cursor.

This is a UTF-8 offset.

◆ m_select_len

size_t m_select_len {0}
protected

Selection length.

◆ m_select_start

size_t m_select_start {0}
protected

Selection start position.

This is a UTF-8 offset.

◆ m_timer

PeriodicTimer m_timer
protected

Timer for blinking the cursor.

◆ m_validate_input

bool m_validate_input {false}
protected

Validation of the input.

◆ m_validator_callbacks

ValidatorCallbackArray m_validator_callbacks
protected

Callbacks invoked to validate the input.

egt::v1::TextBox::insert
size_t insert(const std::string &str)
Insert text at the cursor.
egt::v1::TextBox::TextBox
TextBox(const std::string &text={}, const AlignFlags &text_align=default_text_align(), const TextFlags &flags={}) noexcept
egt::v1::TextBox::TextFlag::word_wrap
@ word_wrap
Wrap at word boundaries instead of character boundaries. Must be flag::multiline.
egt::v1::TextBox::cursor_end
void cursor_end()
Move the cursor to the end.
egt::v1::TextBox::TextFlag::multiline
@ multiline
Enable multi-line text.