1.10
Classes | Public Types | Public Member Functions | Static Public Member Functions | Protected Types | Protected Member Functions | Static Protected Member Functions | Protected Attributes | List of all members
TextBox Class Reference

Input text box. More...

#include <text.h>

Inheritance diagram for TextBox:
Inheritance graph
[legend]

Public Types

enum class  TextFlag : uint32_t {
  fit_to_width = detail::bit(0) , multiline = detail::bit(1) , word_wrap = detail::bit(2) , no_virt_keyboard = detail::bit(3) ,
  horizontal_scrollable = detail::bit(4) , vertical_scrollable = detail::bit(5)
}
 Text flags. More...
 
using TextFlags = egt::Flags< TextFlag >
 Text flags.
 
using ValidatorCallback = std::function< bool(const std::string &)>
 Validator callback type.
 
- Public Types inherited from Widget
enum class  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) ,
  component = detail::bit(12) , user_drag = detail::bit(13) , user_track_drag = detail::bit(14)
}
 Common flags used for various widget properties. More...
 
using Flags = egt::Flags< Widget::Flag >
 Widget flags.
 
using WalkCallback = std::function< bool(Widget *widget, int level)>
 Callback definition used by walk().
 
using WidgetId = uint64_t
 Type used to identify a unique Widget ID.
 
- Public Types inherited from Object
using EventCallback = std::function< void(Event &event)>
 Event handler callback function.
 
using FilterFlags = FlagsBase< EventId >
 Event handler EventId filter.
 
using RegisterHandle = uint64_t
 Handle type.
 

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

Static Public Member Functions

static AlignFlags default_text_align ()
 Change text align.
 
static void default_text_align (const AlignFlags &align)
 Change default text align.
 
- 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.
 

Protected Types

using ValidatorCallbackArray = std::vector< ValidatorCallback >
 Type array used for validator callbacks.
 
- Protected Types inherited from Widget
using ChildDrawCallback = std::function< void(Painter &painter, Widget *widget)>
 Helper type that defines the special draw child callback.
 
using SubordinatesArray = std::list< std::shared_ptr< Widget > >
 Helper type for an array of subordinate widgets.
 
- Protected Types inherited from Object
using CallbackArray = std::vector< CallbackMeta >
 Helper type for an array of callbacks.
 

Protected Member Functions

 TextBox (Serializer::Properties &props, bool is_derived) noexcept
 
size_t beginning_of_line () const
 Get the position of the beginning of the current line.
 
size_t beginning_of_line (size_t cursor_pos) const
 Get the position of the beginning of the line at cursor_pos.
 
void change_cursor (size_t pos, bool save_column=true)
 Change the value of m_cursor_pos.
 
void clear_selection (TextRects &rects)
 Clear the TextRectFlag::selected flag from all TextRects in rects.
 
void compute_layout (TextRects &rects)
 Compute the text layout from the tokens contained in the TextRects.
 
void consolidate (TextRects &rects)
 Merge adjacent TextRect items, when possible.
 
cairo_t * context () const
 Get the cairo context to compute text extents, hence the text layout.
 
void continue_show_cursor ()
 If the cursor is shown, keep is shown some more.
 
void cursor_set (size_t pos, bool save_column)
 Set the cursor position.
 
void damage_cursor ()
 Damage the cursor but only if visible.
 
void damage_text (const Rect &rect)
 Damage the text but only if visible.
 
size_t down () const
 Get the position in the next line at the same column, if possible.
 
size_t down (size_t cursor_pos) const
 Get the position in the line after cursor_pos at the same column, if possible.
 
void draw_sliders (Painter &painter, const Rect &rect)
 Draw sliders.
 
void draw_text (Painter &painter, const Rect &rect)
 Draw the text based on the m_rects TextRects.
 
size_t end_of_line () const
 Get the position of the end of the current line.
 
size_t end_of_line (size_t cursor_pos) const
 Get the position of the end of the line at cursor_pos.
 
void get_cursor_rect ()
 Update m_cursor_rect based on the current position of the cursor.
 
virtual void handle_key (const Key &key)
 Process key events.
 
void hide_cursor ()
 Hide/disable the visibility of the cursor.
 
void init_sliders ()
 Init sliders.
 
bool internal_drag () const override
 
void invalidate_text_rect ()
 Invalidate the cache used by text_rect()
 
void move_hslider ()
 Move the horizontal slider, if needed, to track the cursor.
 
void move_sliders ()
 Move sliders, if needed, to track the cursor.
 
void move_vslider ()
 Move the vertical slider, if needed, to track the cursor.
 
size_t point2pos (const Point &p) const
 Convert point coordinates to position in text for cursor or selection.
 
void prepare_text (TextRects &rects)
 Tokenize and compute the layout of a text; fill TextRects accordingly.
 
void refresh_text_area ()
 Compute the new text layout and cursor rectangle.
 
void resize_sliders ()
 Resize the sliders whenever the widget size changes.
 
void selection_damage ()
 Compute damage rectangles for selection updates.
 
void set_selection (TextRects &rects)
 Add the TextRectFlag::selected flag to TextRects based on the m_select_start and m_select_len values.
 
void show_cursor ()
 Show/enable the visibility of the cursor.
 
void tag_default_aligned_line (TextRects &prev, TextRects::iterator &prev_pos, TextRects &next, TextRects::iterator &next_pos)
 Damage the merged rectangle of two text lines if they are not equal.
 
void tag_left_aligned_line (TextRects &prev, TextRects::iterator &prev_pos, TextRects &next, TextRects::iterator &next_pos)
 Damage the merge rectangle of two text lines, excluding their common prefix.
 
void tag_line (TextRects &prev, TextRects::iterator &prev_pos, TextRects &next, TextRects::iterator &next_pos)
 Damage the differences between two text lines, based on the text alignment.
 
void tag_line_selection (const TextRects &prev, TextRects::const_iterator &prev_pos, const TextRects &next, TextRects::const_iterator &next_pos)
 Damage the differences between two selected text lines.
 
void tag_right_aligned_line (TextRects &prev, TextRects::iterator &prev_pos, TextRects &next, TextRects::iterator &next_pos)
 Damage the merge rectangle of two text lines, excluding their common suffix.
 
void tag_text (TextRects &prev, TextRects &next)
 Damage the differences between two texts.
 
void tag_text_selection (const TextRects &prev, const TextRects &next)
 Damage the differences between two selected texts.
 
EGT_NODISCARD Rect text_area () const
 Return the rectangle boundaries where the text can be drawn.
 
EGT_NODISCARD Rect text_boundaries () const
 Get the rectangle of the text boundaries.
 
EGT_NODISCARD Rect text_rect () const
 Get the rectangle of a text.
 
EGT_NODISCARD Size text_size () const
 
EGT_NODISCARD Size text_size (const std::string &text) const
 Get the size of a text.
 
void tokenize (TextRects &rects)
 Split the text into atomic tokens that fill the TextRects parameter.
 
size_t up () const
 Get the position in the previous line at the same column, if possible.
 
size_t up (size_t cursor_pos) const
 Get the position in the line befor cursor_pos at the same column, if possible.
 
void update_hslider ()
 Update the horizontal slider.
 
void update_sliders ()
 Update the horizontal and vertical sliders as needed.
 
void update_vslider ()
 Update the vertical slider.
 
bool validate_input (const std::string &str)
 Validate the input against the validator pattern.
 
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.
 
- Protected Member Functions inherited from TextWidget
 TextWidget (Serializer::Properties &props, bool is_derived) noexcept
 
EGT_NODISCARD Size text_size (const std::string &text) const
 Get the size of the text.
 
- Protected Member Functions inherited from Widget
 Widget (Serializer::Properties &props, bool is_derived) noexcept
 
bool accept_drag () const
 Tell the start_drag() method whether the widget accepts 'pointer_drag*' events.
 
void add_component (Widget &widget)
 Add a component.
 
void add_damage (const Rect &rect)
 Add damage to the damage array.
 
virtual void begin_draw ()
 Cause the widget to draw itself and all of its children.
 
void begin_draw (Widget *parent)
 Call the begin_draw() method of the parent.
 
EGT_NODISCARD detail::Range< SubordinatesArray > & children ()
 Return the array of child widgets.
 
EGT_NODISCARD const detail::Range< SubordinatesArray > & children () const
 Return the array of child widgets.
 
EGT_NODISCARD bool component () const
 Get the component status.
 
void component (bool value)
 Set the component flag.
 
EGT_NODISCARD detail::Range< SubordinatesArray > & components ()
 Return the array of components widgets.
 
EGT_NODISCARD const detail::Range< SubordinatesArray > & components () const
 Return the array of components widgets.
 
virtual void damage_from_subordinate (const Rect &rect)
 Special variation of damage() that is to be called explicitly by subordinate widgets.
 
void deserialize_leaf (Serializer::Properties &props)
 Deserialize widget properties that require to call overridden methods.
 
Widgetfind_screen ()
 Starting from this Widget, find the Widget that has a Screen.
 
EGT_NODISCARD const Widgetfind_screen () const
 Starting from this Widget, find the Widget that has a Screen.
 
Widget::Flagsflags ()
 Get a modifiable ref of the flags.
 
EGT_NODISCARD const Widget::Flagsflags () const
 Get a const ref of the flags.
 
virtual bool internal_track_drag () const
 
EGT_NODISCARD Rect local_box () const
 Get the local box which is the same size as box(), but with the origin zeroed.
 
EGT_NODISCARD bool parent_in_layout ()
 Indicate if our parent is computing the layout.
 
void parent_layout ()
 Call our parent to do a layout.
 
virtual Point point_from_subordinate (const Widget &subordinate) const
 
EGT_NODISCARD detail::Range< SubordinatesArray > & range_from_widget (const Widget &widget)
 Return either components() or children() depending on widget.component()
 
EGT_NODISCARD const detail::Range< SubordinatesArray > & range_from_widget (const Widget &widget) const
 Return either components() or children() depending on widget.component()
 
void remove_component (Widget *widget)
 Remove a component.
 
virtual void set_parent (Widget *parent)
 Set this widget's parent.
 
void special_child_draw (Painter &painter, Widget *widget)
 Special draw function that can be invoked when drawing each child.
 
EGT_NODISCARD ChildDrawCallback special_child_draw_callback () const
 Get the special child draw callback.
 
void special_child_draw_callback (ChildDrawCallback func)
 Set the special child draw callback.
 
EGT_NODISCARD ChildDrawCallback special_child_draw_callback (Widget *parent) const
 Get the child draw callback of the parent.
 
void start_drag (Event &event)
 Handle 'pointer_drag_start' events and decide whether they are caught by this widget.
 
virtual Point to_panel (const Point &p)
 Convert a local point to the coordinate system of the current panel.
 
virtual EGT_NODISCARD Point to_subordinate (const Point &p) const
 Convert a point with an origin of the current widget to subordinate origin.
 
EGT_NODISCARD Rect to_subordinate (Rect rect) const
 
virtual EGT_NODISCARD bool top_level () const
 Is this widget a top level widget?
 
bool track_drag () const
 Tell the continue_drag() method whether the widget tracks 'pointer_drag*' events once they have crossed out the widget boundaries.
 
void update_subordinates_ranges ()
 Update the 'm_children' and 'm_components' members.
 
size_t zorder (const Widget *widget) const
 Get the zorder of the widget.
 
void zorder (const Widget *widget, size_t rank)
 Set the zorder of the widget.
 
void zorder_bottom (const Widget *widget)
 Move the specified widget zorder to the bottom of the current list of widgets with the same parent.
 
void zorder_down (const Widget *widget)
 Move the specified widget zorder down relative to other widgets with the same parent.
 
void zorder_top (const Widget *widget)
 Move the specified widget zorder to the top of the current list of widgets with the same parent.
 
void zorder_up (const Widget *widget)
 Move the specified widget zorder up relative to other widgets with the same parent.
 

Static Protected Member Functions

static void get_line (const TextRects &rects, TextRects::iterator &pos, std::string &line, Rect &rect)
 Get the std::string and Rect from pos to the first follwing TextRect in rects with a different height, or till the end of rects if any.
 
static void get_line_selection (const TextRects &rects, TextRects::const_iterator &pos, Rect &rect)
 Compute the merged Rect for the selected TextRects on the same line as pos.
 
static DefaultDim half_screens (DefaultDim size, DefaultDim screen_size)
 Return the lowest multiple of 'screen_size' / 2, greater than 'size'.
 
static std::string longest_prefix (const std::string &s1, const std::string &s2)
 Compute the longest common prefix between two strings.
 
static std::string longest_suffix (const std::string &s1, const std::string &s2)
 Compute the longest common suffix between two strings.
 

Protected Attributes

Canvas m_canvas
 The canvas that provides a cairo context to compute the text layout.
 
cairo_t * m_cr {nullptr}
 Cairo context.
 
size_t m_cursor_pos {0}
 The current position of the cursor.
 
Rect m_cursor_rect
 
TextRects m_rects
 
size_t m_saved_column {0}
 Save the column of the cursor when it was moved for the last time, except when the cursor is moved with the UP and DOWN keys.
 
size_t m_select_drag_start {0}
 Selection drag start.
 
size_t m_select_len {0}
 Selection length.
 
size_t m_select_origin {0}
 Selection origin.
 
size_t m_select_start {0}
 Selection start position.
 
Rect m_text_rect
 The cache for text_rect().
 
bool m_text_rect_valid {false}
 
PeriodicTimer m_timer
 Timer for blinking the cursor.
 
bool m_validate_input {false}
 Validation of the input.
 
ValidatorCallbackArray m_validator_callbacks
 Callbacks invoked to validate the input.
 
- Protected Attributes inherited from TextWidget
std::string m_text
 The text.
 
AlignFlags m_text_align {AlignFlag::center}
 Alignment of the text.
 
- Protected Attributes inherited from Widget
Rect m_box
 Bounding box.
 
detail::Range< SubordinatesArraym_children
 Array of child widgets in the order they were added.
 
detail::Range< SubordinatesArraym_components
 Array of component widgets in the order they were added.
 
SubordinatesArray::iterator m_components_begin
 Iterator for the beginning of components which are positionned after children in the subordinates array.
 
Screen::DamageArray m_damage
 The damage array for this widget.
 
bool m_in_draw {false}
 Status for whether this widget is currently drawing.
 
bool m_in_layout {false}
 Status for whether this widget is currently performing layout.
 
Size m_min_size
 Minimum size of the widget when not an empty value.
 
Widgetm_parent {nullptr}
 Pointer to this widget's parent.
 
ChildDrawCallback m_special_child_draw_callback
 Used internally for calling the special child draw function.
 
SubordinatesArray m_subordinates
 Array of subordinates widgets split in child widgets and component widgets.
 
Rect m_user_requested_box
 Keep track of the box requested by the user.
 
WidgetId m_widgetid {0}
 Unique ID of this widget.
 
- Protected Attributes inherited from Object
detail::CopyOnWriteAllocate< CallbackArraym_callbacks
 Array of callbacks.
 
RegisterHandle m_handle_counter {0}
 Counter used to generate unique handles for each callback registration.
 
std::string m_name
 A user defined name for the Object.
 

Additional Inherited Members

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

Detailed Description

Input text box.

Supported Features:

Example

TextBox textbox;
Input text box.
Definition text.h:134
void text_flags(const TextFlags &text_flags)
Set the text flags.
Definition text.h:278
@ word_wrap
Wrap at word boundaries instead of character boundaries. Must be flag::multiline.
@ multiline
Enable multi-line text. expand_vertical align flag must be set, be careful to not set top or bottom l...

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 class 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. expand_vertical align flag must be set, be careful to not set top or bottom later.

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.

horizontal_scrollable 

Horizontal scrollable.

vertical_scrollable 

Vertical scrollable.

Constructor & Destructor Documentation

◆ TextBox() [1/9]

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/9]

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/9]

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/9]

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/9]

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/9]

TextBox ( Serializer::Properties props)
inlineexplicitnoexcept
Parameters
[in]propslist of widget argument and its properties.

◆ TextBox() [7/9]

TextBox ( Serializer::Properties props,
bool  is_derived 
)
explicitprotectednoexcept

◆ TextBox() [8/9]

TextBox ( const TextBox )
delete

◆ TextBox() [9/9]

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);
size_t insert(const std::string &str)
Insert text at the cursor.
void cursor_end()
Move the cursor to the end.
Parameters
strThe string to append.

◆ beginning_of_line() [1/2]

size_t beginning_of_line ( ) const
inlineprotected

Get the position of the beginning of the current line.

◆ beginning_of_line() [2/2]

size_t beginning_of_line ( size_t  cursor_pos) const
protected

Get the position of the beginning of the line at cursor_pos.

◆ change_cursor()

void change_cursor ( size_t  pos,
bool  save_column = true 
)
protected

Change the value of m_cursor_pos.

◆ clear()

void clear ( )
overridevirtual

Clear the text value.

Reimplemented from TextWidget.

◆ clear_selection()

void clear_selection ( TextRects rects)
protected

Clear the TextRectFlag::selected flag from all TextRects in rects.

◆ compute_layout()

void compute_layout ( TextRects rects)
protected

Compute the text layout from the tokens contained in the TextRects.

◆ consolidate()

void consolidate ( TextRects rects)
protected

Merge adjacent TextRect items, when possible.

◆ context()

cairo_t * context ( ) const
inlineprotected

Get the cairo context to compute text extents, hence the text layout.

◆ 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() [1/2]

void cursor_set ( size_t  pos)

Set the cursor to the specific position.

Parameters
posThe new cursor position.

◆ cursor_set() [2/2]

void cursor_set ( size_t  pos,
bool  save_column 
)
protected

Set the cursor position.

◆ damage_cursor()

void damage_cursor ( )
inlineprotected

Damage the cursor but only if visible.

The cursor may cross the content area; hence intersect with the box.

◆ damage_text()

void damage_text ( const Rect rect)
inlineprotected

Damage the text but only if visible.

◆ 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.

◆ down() [1/2]

size_t down ( ) const
inlineprotected

Get the position in the next line at the same column, if possible.

◆ down() [2/2]

size_t down ( size_t  cursor_pos) const
protected

Get the position in the line after cursor_pos at the same column, if possible.

◆ 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.

Reimplemented from Widget.

◆ draw_sliders()

void draw_sliders ( Painter painter,
const Rect rect 
)
protected

Draw sliders.

◆ draw_text()

void draw_text ( Painter painter,
const Rect rect 
)
protected

Draw the text based on the m_rects TextRects.

◆ end_of_line() [1/2]

size_t end_of_line ( ) const
inlineprotected

Get the position of the end of the current line.

◆ end_of_line() [2/2]

size_t end_of_line ( size_t  cursor_pos) const
protected

Get the position of the end of the line at cursor_pos.

◆ get_cursor_rect()

void get_cursor_rect ( )
protected

Update m_cursor_rect based on the current position of the cursor.

◆ get_line()

static void get_line ( const TextRects rects,
TextRects::iterator &  pos,
std::string &  line,
Rect rect 
)
staticprotected

Get the std::string and Rect from pos to the first follwing TextRect in rects with a different height, or till the end of rects if any.

◆ get_line_selection()

static void get_line_selection ( const TextRects rects,
TextRects::const_iterator &  pos,
Rect rect 
)
staticprotected

Compute the merged Rect for the selected TextRects on the same line as pos.

◆ half_screens()

static DefaultDim half_screens ( DefaultDim  size,
DefaultDim  screen_size 
)
staticprotected

Return the lowest multiple of 'screen_size' / 2, greater than 'size'.

◆ 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()

virtual void handle_key ( const Key key)
protectedvirtual

Process key events.

◆ hide_cursor()

void hide_cursor ( )
protected

Hide/disable the visibility of the cursor.

◆ init_sliders()

void init_sliders ( )
protected

Init sliders.

◆ 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.

◆ internal_drag()

bool internal_drag ( ) const
inlineoverrideprotectedvirtual

Reimplemented from Widget.

◆ invalidate_text_rect()

void invalidate_text_rect ( )
protected

Invalidate the cache used by text_rect()

◆ longest_prefix()

static std::string longest_prefix ( const std::string &  s1,
const std::string &  s2 
)
staticprotected

Compute the longest common prefix between two strings.

◆ longest_suffix()

static std::string longest_suffix ( const std::string &  s1,
const std::string &  s2 
)
staticprotected

Compute the longest common suffix between two strings.

◆ 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.

◆ move_hslider()

void move_hslider ( )
protected

Move the horizontal slider, if needed, to track the cursor.

◆ move_sliders()

void move_sliders ( )
protected

Move sliders, if needed, to track the cursor.

◆ move_vslider()

void move_vslider ( )
protected

Move the vertical slider, if needed, to track the cursor.

◆ operator=() [1/2]

TextBox & operator= ( const TextBox )
delete

◆ operator=() [2/2]

TextBox & operator= ( TextBox &&  )
default

◆ point2pos()

size_t point2pos ( const Point p) const
protected

Convert point coordinates to position in text for cursor or selection.

◆ prepare_text()

void prepare_text ( TextRects rects)
protected

Tokenize and compute the layout of a text; fill TextRects accordingly.

◆ refresh_text_area()

void refresh_text_area ( )
protected

Compute the new text layout and cursor rectangle.

◆ resize()

void resize ( const Size size)
overridevirtual

Resize the widget.

Changes the width and height of the Widget.

Parameters
[in]sizeThe new size of the Widget.
Note
This will cause a redraw of the Widget.

Reimplemented from Widget.

◆ resize_sliders()

void resize_sliders ( )
protected

Resize the sliders whenever the widget size changes.

◆ 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_backward()

void selection_backward ( size_t  count = 1)

Extend the selection to the left if the cursor is at its end, otherwise reduce the selection from the right.

In both cases, the selection length is updated by the specified count.

Parameters
countThe number of characters to move.

◆ 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_cursor()

EGT_NODISCARD size_t selection_cursor ( )

Get the position of the moving end of the selection, as opposed to its origin (the fixed end of the selection).

Set the selection origin, if needed.

◆ selection_damage()

void selection_damage ( )
protected

Compute damage rectangles for selection updates.

◆ selection_delete()

void selection_delete ( )

Delete the selected text.

◆ selection_forward()

void selection_forward ( size_t  count = 1)

Extend the selection to the right if the cursor is at its beginning, otherwise reduce the selection from the left.

In both cases, the selection length is updated by the specified count.

Parameters
countThe number of characters to move.

◆ selection_length()

EGT_NODISCARD size_t selection_length ( ) const
inline

Get the length of the selection.

◆ selection_move()

void selection_move ( size_t  count,
bool  save_column = true 
)

Move the selection cursor to count character(s):

  • to the left, if count is negative
  • to the right, if count is positive Do nothing if count is zero.

Also, set the selection origin (its fixed end), if needed. In all cases, the cursor is positioned to the new selection cursor.

◆ 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.

◆ set_selection()

void set_selection ( TextRects rects)
protected

Add the TextRectFlag::selected flag to TextRects based on the m_select_start and m_select_len values.

Split TextRects if needed.

◆ show_cursor()

void show_cursor ( )
protected

Show/enable the visibility of the cursor.

◆ tag_default_aligned_line()

void tag_default_aligned_line ( TextRects prev,
TextRects::iterator &  prev_pos,
TextRects next,
TextRects::iterator &  next_pos 
)
protected

Damage the merged rectangle of two text lines if they are not equal.

◆ tag_left_aligned_line()

void tag_left_aligned_line ( TextRects prev,
TextRects::iterator &  prev_pos,
TextRects next,
TextRects::iterator &  next_pos 
)
protected

Damage the merge rectangle of two text lines, excluding their common prefix.

◆ tag_line()

void tag_line ( TextRects prev,
TextRects::iterator &  prev_pos,
TextRects next,
TextRects::iterator &  next_pos 
)
protected

Damage the differences between two text lines, based on the text alignment.

◆ tag_line_selection()

void tag_line_selection ( const TextRects prev,
TextRects::const_iterator &  prev_pos,
const TextRects next,
TextRects::const_iterator &  next_pos 
)
protected

Damage the differences between two selected text lines.

◆ tag_right_aligned_line()

void tag_right_aligned_line ( TextRects prev,
TextRects::iterator &  prev_pos,
TextRects next,
TextRects::iterator &  next_pos 
)
protected

Damage the merge rectangle of two text lines, excluding their common suffix.

◆ tag_text()

void tag_text ( TextRects prev,
TextRects next 
)
protected

Damage the differences between two texts.

◆ tag_text_selection()

void tag_text_selection ( const TextRects prev,
const TextRects next 
)
protected

Damage the differences between two selected texts.

◆ text() [1/3]

virtual EGT_NODISCARD const std::string & text ( ) const
inlinevirtual

Get the text of the Label.

Reimplemented from TextWidget.

◆ text() [2/3]

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

Set the text.

Parameters
strThe text string to set.

Reimplemented from TextWidget.

◆ text() [3/3]

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

Set the text.

Parameters
strThe text string to set.

Reimplemented from TextWidget.

◆ text_area()

EGT_NODISCARD Rect text_area ( ) const
protected

Return the rectangle boundaries where the text can be drawn.

◆ text_boundaries()

EGT_NODISCARD Rect text_boundaries ( ) const
protected

Get the rectangle of the text boundaries.

◆ text_flags() [1/2]

EGT_NODISCARD const TextFlags & text_flags ( ) const
inline

Get a const ref of the flags.

◆ text_flags() [2/2]

void text_flags ( const TextFlags text_flags)
inline

Set the text flags.

Parameters
[in]text_flagsText flags.

◆ text_offset() [1/2]

EGT_NODISCARD Point text_offset ( ) const

Get the position offset of the drawn text as compared to the whole text.

◆ text_offset() [2/2]

void text_offset ( const Point p)

Set the position offset of the drawn text as compared to the whole text.

◆ text_rect()

EGT_NODISCARD Rect text_rect ( ) const
protected

Get the rectangle of a text.

◆ text_size() [1/2]

EGT_NODISCARD Size text_size ( ) const
protected

◆ text_size() [2/2]

EGT_NODISCARD Size text_size ( const std::string &  text) const
protected

Get the size of a text.

◆ tokenize()

void tokenize ( TextRects rects)
protected

Split the text into atomic tokens that fill the TextRects parameter.

◆ up() [1/2]

size_t up ( ) const
inlineprotected

Get the position in the previous line at the same column, if possible.

◆ up() [2/2]

size_t up ( size_t  cursor_pos) const
protected

Get the position in the line befor cursor_pos at the same column, if possible.

◆ update_hslider()

void update_hslider ( )
protected

Update the horizontal slider.

◆ update_sliders()

void update_sliders ( )
protected

Update the horizontal and vertical sliders as needed.

◆ update_vslider()

void update_vslider ( )
protected

Update the vertical slider.

◆ 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_canvas

Canvas m_canvas
protected

The canvas that provides a cairo context to compute the text layout.

◆ m_cr

cairo_t* m_cr {nullptr}
protected

Cairo context.

◆ m_cursor_pos

size_t m_cursor_pos {0}
protected

The current position of the cursor.

This is a UTF-8 offset.

◆ m_cursor_rect

Rect m_cursor_rect
protected

◆ m_rects

TextRects m_rects
protected

◆ m_saved_column

size_t m_saved_column {0}
protected

Save the column of the cursor when it was moved for the last time, except when the cursor is moved with the UP and DOWN keys.

◆ m_select_drag_start

size_t m_select_drag_start {0}
protected

Selection drag start.

◆ m_select_len

size_t m_select_len {0}
protected

Selection length.

◆ m_select_origin

size_t m_select_origin {0}
protected

Selection origin.

◆ m_select_start

size_t m_select_start {0}
protected

Selection start position.

This is a UTF-8 offset.

◆ m_text_rect

Rect m_text_rect
mutableprotected

The cache for text_rect().

◆ m_text_rect_valid

bool m_text_rect_valid {false}
mutableprotected

◆ 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.