TermOx
Classes | Public Member Functions | Public Attributes | Protected Member Functions | List of all members
ox::Text_view Class Reference

Non-interactive box to display a given Glyph_string. More...

#include <text_view.hpp>

Inheritance diagram for ox::Text_view:
ox::Widget ox::detail::Textbox_base ox::Textbox ox::Log

Classes

struct  Parameters
 

Public Member Functions

 Text_view (Glyph_string text=U"", Align alignment=Align::Left, Wrap wrap=Wrap::Word, Brush insert_brush=Brush{})
 Construct a Text_view with initial Glyph_string text. More...
 
 Text_view (Parameters p)
 
void set_text (Glyph_string text)
 Replace the current contents with text. More...
 
auto text () -> Glyph_string &
 Return the entire contents of the Text_view. More...
 
auto text () const -> Glyph_string const &
 Return the entire contents of the Text_view.
 
void set_alignment (Align type)
 Set the Alignment, changing how the contents are displayed. More...
 
auto alignment () const -> Align
 Return the currently used Alignment.
 
void set_wrap (Wrap w)
 Set the type of text wrapping at line boundaries.
 
auto wrap () const -> Wrap
 Return the currently set text Wrap type.
 
void insert (Glyph_string text, int index)
 Inserts text starting at index into the current contents. More...
 
void append (Glyph_string text)
 Inserts text to the end of the current contents. More...
 
void erase (int index, int length=Glyph_string::npos)
 Remove Glyphs from contents starting at index, for length Glyphs.
 
void pop_back ()
 Remove the last Glyph from the current contents. No-op if this->empty();.
 
void clear ()
 Remove all Glyphs from the this text display. More...
 
virtual void scroll_up (int n=1)
 Scroll the display up by n lines. More...
 
virtual void scroll_down (int n=1)
 Scroll the display down by n lines. More...
 
auto row_length (int y) const -> int
 Return the length of the line at row y. More...
 
auto display_height () const -> int
 Return the number of lines currently displayed.
 
auto line_count () const -> int
 Return the total number of lines in display_state_.
 
void set_top_line (int n)
 Set the top line, by row index.
 
auto index_at (Point position) const -> int
 Return the index into the contents from a physical Point on the Widget. More...
 
auto display_position (int index) const -> Point
 Return the position of the Glyph at index. More...
 
void update () override
 Add call to Text_view::update_display() before posting Paint_event.
 
- Public Member Functions inherited from ox::Widget
 Widget (std::string name="", Focus_policy focus_policy_=Focus_policy::None, Size_policy width_policy_=Size_policy{}, Size_policy height_policy_=Size_policy{}, Brush brush_=Brush{}, Glyph wallpaper=U' ', bool brush_paints_wallpaper=true, Cursor cursor=Cursor{})
 Create an empty Widget.
 
 Widget (Parameters p)
 Create an empty Widget.
 
 Widget (Widget const &)=delete
 
 Widget (Widget &&)=delete
 
Widgetoperator= (Widget const &)=delete
 
Widgetoperator= (Widget &&)=delete
 
void set_name (std::string name)
 Set the identifying name of the Widget.
 
auto name () const -> std::string const &
 Return the name of the Widget.
 
auto unique_id () const -> std::uint16_t
 Return the ID number unique to this Widget.
 
void set_wallpaper (Glyph g)
 Used to fill in empty space that is not filled in by paint_event().
 
auto get_wallpaper () const -> Glyph
 Return the currently in use wallpaper or std::nullopt if none.
 
void enable (bool enable=true)
 Enable this Widget and send an Enable_event to itself. More...
 
void disable (bool disable=true)
 Disable this Widget and send a Disable_event to itself. More...
 
auto is_enabled () const -> bool
 Check whether the Widget is enabled.
 
auto parent () const -> Widget *
 Return the Widget's parent pointer. More...
 
auto top_left () const -> Point
 Return the global top left corner of this widget.
 
auto area () const -> Area
 Return the area the widget occupies.
 
virtual auto is_layout_type () const -> bool
 
void install_event_filter (Widget &filter)
 Install another Widget as an Event filter. More...
 
void remove_event_filter (Widget &filter)
 Remove a Widget from the Event filter list. More...
 
auto get_event_filters () const -> std::set< Widget * > const &
 Return the list of Event filter Widgets.
 
void enable_animation (std::chrono::milliseconds interval)
 Enable animation on this Widget. More...
 
void enable_animation (FPS fps)
 Enable animation with a frames-per-second value.
 
void disable_animation ()
 Turn off animation, no more Timer_events will be sent to this Widget. More...
 
auto is_animated () const -> bool
 Return true if this Widget has animation enabled.
 
auto get_children ()
 Get a range containing Widget& to each child.
 
auto get_children () const
 Get a const range containing Widget& to each child.
 
auto get_descendants () const -> std::vector< Widget * >
 Return container of all descendants of self_.
 
void paint_wallpaper_with_brush (bool paints=true)
 Set if the brush is applied to the wallpaper Glyph.
 
auto paints_wallpaper_with_brush () const -> bool
 If true, the brush will apply to the wallpaper Glyph.
 
auto generate_wallpaper () const -> Glyph
 Return the wallpaper Glyph. More...
 
auto get_child_offset () const -> std::size_t
 Return the index of the first child displayed by this Widget.
 
auto child_count () const -> std::size_t
 Return the number of children held by this Widget.
 
virtual auto enable_event () -> bool
 Handles Enable_event objects.
 
virtual auto disable_event () -> bool
 Handles Disable_event objects.
 
virtual auto child_added_event (Widget &child) -> bool
 Handles Child_added_event objects.
 
virtual auto child_removed_event (Widget &child) -> bool
 Handles Child_removed_event objects.
 
virtual auto child_polished_event (Widget &child) -> bool
 Handles Child_polished_event objects.
 
virtual auto move_event (Point new_position, Point old_position) -> bool
 Handles Move_event objects.
 
virtual auto resize_event (Area new_size, Area old_size) -> bool
 Handles Resize_event objects.
 
virtual auto mouse_press_event (Mouse const &m) -> bool
 Handles Mouse_press_event objects.
 
virtual auto mouse_release_event (Mouse const &m) -> bool
 Handles Mouse_release_event objects.
 
virtual auto mouse_wheel_event (Mouse const &m) -> bool
 Handles Mouse_wheel_event objects.
 
virtual auto mouse_move_event (Mouse const &m) -> bool
 Handles Mouse_move_event objects.
 
virtual auto key_press_event (Key k) -> bool
 Handles Key_press_event objects.
 
virtual auto key_release_event (Key k) -> bool
 Handles Key_release_event objects. More...
 
virtual auto focus_in_event () -> bool
 Handles Focus_in_event objects.
 
virtual auto focus_out_event () -> bool
 Handles Focus_out_event objects.
 
virtual auto delete_event () -> bool
 Handles Delete_event objects.
 
virtual auto timer_event () -> bool
 Handles Timer_event objects.
 
virtual auto enable_event_filter (Widget &receiver) -> bool
 Handles Enable_event objects filtered from other Widgets.
 
virtual auto disable_event_filter (Widget &receiver) -> bool
 Handles Disable_event objects filtered from other Widgets.
 
virtual auto child_added_event_filter (Widget &receiver, Widget &child) -> bool
 Handles Child_added_event objects filtered from other Widgets.
 
virtual auto child_removed_event_filter (Widget &receiver, Widget &child) -> bool
 Handles Child_removed_event objects filtered from other Widgets.
 
virtual auto child_polished_event_filter (Widget &receiver, Widget &child) -> bool
 Handles Child_polished_event objects filtered from other Widgets.
 
virtual auto move_event_filter (Widget &receiver, Point new_position, Point old_position) -> bool
 Handles Move_event objects filtered from other Widgets.
 
virtual auto resize_event_filter (Widget &receiver, Area new_size, Area old_size) -> bool
 Handles Resize_event objects filtered from other Widgets.
 
virtual auto mouse_press_event_filter (Widget &receiver, Mouse const &m) -> bool
 Handles Mouse_press_event objects filtered from other Widgets.
 
virtual auto mouse_release_event_filter (Widget &receiver, Mouse const &m) -> bool
 Handles Mouse_release_event objects filtered from other Widgets.
 
virtual auto mouse_wheel_event_filter (Widget &receiver, Mouse const &m) -> bool
 Handles Mouse_wheel_event objects filtered from other Widgets.
 
virtual auto mouse_move_event_filter (Widget &receiver, Mouse const &m) -> bool
 Handles Mouse_move_event objects filtered from other Widgets.
 
virtual auto key_press_event_filter (Widget &receiver, Key k) -> bool
 Handles Key_press_event objects filtered from other Widgets.
 
virtual auto key_release_event_filter (Widget &receiver, Key k) -> bool
 Handles Key_release_event objects filtered from other Widgets.
 
virtual auto focus_in_event_filter (Widget &receiver) -> bool
 Handles Focus_in_event objects filtered from other Widgets.
 
virtual auto focus_out_event_filter (Widget &receiver) -> bool
 Handles Focus_out_event objects filtered from other Widgets.
 
virtual auto delete_event_filter (Widget &receiver) -> bool
 Handles Delete_event objects filtered from other Widgets.
 
virtual auto paint_event_filter (Widget &receiver, Painter &p) -> bool
 Handles Paint_event objects filtered from other Widgets.
 
virtual auto timer_event_filter (Widget &receiver) -> bool
 Handles Timer_event objects filtered from other Widgets.
 
void set_top_left (Point p)
 Should only be used by Move_event send() function.
 
void set_area (Area a)
 Should only be used by Resize_event send() function.
 
void set_parent (Widget *parent)
 Should only be used by Layout.
 

Public Attributes

Brush insert_brush
 Brush to be applied to all new incoming Glyphs, but not existing Glyphs. More...
 
sl::Signal< void(int n)> scrolled_up
 Emitted when text is scrolled up. Sends number of lines scrolled by.
 
sl::Signal< void(int n)> scrolled_down
 Emitted when text is scrolled down. Sends number of lines scrolled by.
 
sl::Signal< void(int n)> scrolled_to
 Emitted when text is scrolled, sends the top line.
 
sl::Signal< void(Glyph_string const &)> contents_modified
 Emitted when contents are modified. Sends a reference to the contents.
 
sl::Signal< void(int)> line_count_changed
 Emitted when total line count changes.
 
- Public Attributes inherited from ox::Widget
Signal< void()> enabled
 
Signal< void()> disabled
 
Signal< void(Widget &)> child_added
 
Signal< void(Widget &)> child_removed
 
Signal< void(Widget &)> child_polished
 
Signal< void(Point, Point)> moved
 
Signal< void(Area, Area)> resized
 
Signal< void(Mouse const &)> mouse_pressed
 
Signal< void(Mouse const &)> mouse_released
 
Signal< void(Mouse const &)> mouse_wheel_scrolled
 
Signal< void(Mouse const &)> mouse_moved
 
Signal< void(Key)> key_pressed
 
Signal< void(Key)> key_released
 
Signal< void()> focused_in
 
Signal< void()> focused_out
 
Signal< void()> deleted
 
Signal< void(Painter &)> painted
 
Signal< void()> timer
 
Signal< bool(Widget &)> enabled_filter
 
Signal< bool(Widget &)> disabled_filter
 
Signal< bool(Widget &, Widget &)> child_added_filter
 
Signal< bool(Widget &, Widget &)> child_removed_filter
 
Signal< bool(Widget &, Widget &)> child_polished_filter
 
Signal< bool(Widget &, Point, Point)> moved_filter
 
Signal< bool(Widget &, Area, Area)> resized_filter
 
Signal< bool(Widget &, Mouse const &)> mouse_pressed_filter
 
Signal< bool(Widget &, Mouse const &)> mouse_released_filter
 
Signal< bool(Widget &, Mouse const &)> mouse_wheel_scrolled_filter
 
Signal< bool(Widget &, Mouse const &)> mouse_moved_filter
 
Signal< bool(Widget &, Key)> key_pressed_filter
 
Signal< bool(Widget &, Key)> key_released_filter
 
Signal< bool(Widget &)> focused_in_filter
 
Signal< bool(Widget &)> focused_out_filter
 
Signal< bool(Widget &)> deleted_filter
 
Signal< bool(Widget &, Painter &)> painted_filter
 
Signal< bool(Widget &)> timer_filter
 
Focus_policy focus_policy
 Describes how focus is given to this Widget.
 
Cursor cursor
 Provides information on where the cursor is and if it is enabled.
 
Size_policy width_policy
 Describes how the width of this Widget should be modified by a Layout.
 
Size_policy height_policy
 Describes how the height of this Widget should be modified by a Layout.
 
Brush brush
 A Brush that is applied to every Glyph painted by this Widget.
 
sl::Lifetime lifetime
 Slots can track this object's lifetime to disable Slot invocations.
 

Protected Member Functions

auto paint_event (Painter &p) -> bool override
 Paint the portion of contents that is currently visible on screen.
 
auto line_at (int index) const -> int
 Return the line number that contains index.
 
auto top_line () const -> int
 Return the line number that is being displayed at the top of the Widget.
 
auto bottom_line () const -> int
 Return line number that is being displayed at the bottom of the Widget.
 
auto last_line () const -> int
 Return the index into display_state_ of the last line.
 
auto first_index_at (int line) const -> int
 Return the index of the first Glyph at line number line.
 
auto last_index_at (int line) const -> int
 Returns one past the last index of the last Glyph at line number line.
 
auto line_length (int line) const -> int
 Return the number of Glyphs contained at line index line.
 
auto end_index () const -> int
 Return the index of the last Glyph in contents.
 
void update_display (int from_line=0)
 Recalculate the text layout via display_state_. More...
 

Additional Inherited Members

- Protected Types inherited from ox::Widget
using Children_t = std::vector< std::unique_ptr< Widget > >
 
- Protected Attributes inherited from ox::Widget
Children_t children_
 
std::size_t child_offset_ = 0
 

Detailed Description

Non-interactive box to display a given Glyph_string.

Provides operations to change the text, wrap words on spaces, change the alignment of the text and scroll through the text, among others.

Constructor & Destructor Documentation

◆ Text_view()

ox::Text_view::Text_view ( Glyph_string  text = U"",
Align  alignment = Align::Left,
Wrap  wrap = Wrap::Word,
Brush  insert_brush = Brush{} 
)
explicit

Construct a Text_view with initial Glyph_string text.

By default, wraps text, and has left alignment.

Member Function Documentation

◆ append()

void ox::Text_view::append ( Glyph_string  text)

Inserts text to the end of the current contents.

Applys insert_brush to each Glyph inserted.

◆ clear()

void ox::Text_view::clear ( )

Remove all Glyphs from the this text display.

this->empty() is true after call.

◆ display_position()

auto ox::Text_view::display_position ( int  index) const -> Point

Return the position of the Glyph at index.

If index is not currently displayed on screen, return the closest Glyph position to index that is displayed on screen.

◆ index_at()

auto ox::Text_view::index_at ( Point  position) const -> int

Return the index into the contents from a physical Point on the Widget.

If position is past any text on the corresponding line, then return index of the last Glyph on that line. If Point is past displayed lines, return the index of the last Glyph in contents.

◆ insert()

void ox::Text_view::insert ( Glyph_string  text,
int  index 
)

Inserts text starting at index into the current contents.

Applys insert_brush to each Glyph added. Index can be one past the current length of the contents, to append. No-op if index is larger than one past the current length of contents.

◆ row_length()

auto ox::Text_view::row_length ( int  y) const -> int

Return the length of the line at row y.

Index 0 is the top of the Widget.

◆ scroll_down()

void ox::Text_view::scroll_down ( int  n = 1)
virtual

Scroll the display down by n lines.

Bottoms out at the last line displaying at the top of the display.

Reimplemented in ox::detail::Textbox_base.

◆ scroll_up()

void ox::Text_view::scroll_up ( int  n = 1)
virtual

Scroll the display up by n lines.

Tops out at the first line displayed at the top of the display.

Reimplemented in ox::detail::Textbox_base.

◆ set_alignment()

void ox::Text_view::set_alignment ( Align  type)

Set the Alignment, changing how the contents are displayed.

Not fully implemented at the moment, Left alignment is currently supported.

◆ set_text()

void ox::Text_view::set_text ( Glyph_string  text)

Replace the current contents with text.

Reset the display to show the first line at the top of the screen and the cursor at the first Glyph, or where the first Glyph would be.

◆ text()

auto ox::Text_view::text ( ) -> Glyph_string&

Return the entire contents of the Text_view.

Provided as a non-const reference so contents can be modified without limitation from the Text_view interface. Be sure to call Text_view::update() after modifying the contents directly.

◆ update_display()

void ox::Text_view::update_display ( int  from_line = 0)
protected

Recalculate the text layout via display_state_.

This updates display_state_, depends on the Widget's dimensions, if word wrap is enabled, and the contents.

Member Data Documentation

◆ insert_brush

Brush ox::Text_view::insert_brush

Brush to be applied to all new incoming Glyphs, but not existing Glyphs.

Widget::brush is applied after this Brush.


The documentation for this class was generated from the following files: