TermOx
textline_base.hpp
1 #ifndef TERMOX_WIDGET_WIDGETS_DETAIL_TEXTLINE_BASE_HPP
2 #define TERMOX_WIDGET_WIDGETS_DETAIL_TEXTLINE_BASE_HPP
3 #include <termox/system/key.hpp>
4 #include <termox/system/mouse.hpp>
5 #include <termox/widget/align.hpp>
6 #include <termox/widget/area.hpp>
7 #include <termox/widget/widget.hpp>
8 #include <termox/widget/widgets/detail/textline_core.hpp>
9 
10 namespace ox::detail {
11 
13 
14 class Textline_base : public ox::Widget {
15  public:
16  enum class Action { None, Clear };
17 
18  struct Parameters {
19  ox::Glyph_string initial = U"";
20  ox::Align align = ox::Align::Left;
21  Action focus_in_action = Action::None;
22  };
23 
24  public:
25  Textline_base(ox::Glyph_string initial = U"",
26  ox::Align align = ox::Align::Left,
27  Action focus_in_action = Action::None);
28 
30 
31  public:
33  void set_text(ox::Glyph_string x);
34 
36  [[nodiscard]] auto text() const noexcept -> ox::Glyph_string const&;
37 
39  void set_alignment(ox::Align x);
40 
42  [[nodiscard]] auto alignment() const noexcept -> ox::Align;
43 
45  void set_focus_in_action(Action x);
46 
48  void clear_on_focus();
49 
51  void nothing_on_focus();
52 
54  [[nodiscard]] auto focus_in_action() const noexcept -> Action;
55 
57  void set_cursor_to_index(int i);
58 
59  protected:
60  Textline_core core_;
61 
62  protected:
63  auto paint_event(ox::Painter& p) -> bool override;
64 
65  auto key_press_event(ox::Key k) -> bool override;
66 
67  auto mouse_press_event(ox::Mouse const& m) -> bool override;
68 
69  auto resize_event(ox::Area new_size, ox::Area old_size) -> bool override;
70 
71  auto focus_in_event() -> bool override;
72 
73  auto focus_out_event() -> bool override;
74 
75  private:
76  Action focus_in_action_;
77  Glyph_string stored_text_; // stored on focus_in
78 };
79 
80 } // namespace ox::detail
81 #endif // TERMOX_WIDGET_WIDGETS_DETAIL_TEXTLINE_BASE_HPP
Holds a collection of Glyphs with a similar interface to std::string.
Definition: glyph_string.hpp:19
Contains functions to paint Glyphs to a Widget's screen area.
Definition: painter.hpp:21
Definition: widget.hpp:31
Implements single line text Cursor navigation and deletion, no text input.
Definition: textline_base.hpp:14
auto text() const noexcept -> ox::Glyph_string const &
Return the full text contents.
Definition: textline_base.cpp:35
auto resize_event(ox::Area new_size, ox::Area old_size) -> bool override
Handles Resize_event objects.
Definition: textline_base.cpp:110
auto focus_out_event() -> bool override
Handles Focus_out_event objects.
Definition: textline_base.cpp:127
void set_text(ox::Glyph_string x)
Clear and reset the text being displayed.
Definition: textline_base.cpp:29
auto paint_event(ox::Painter &p) -> bool override
Handles Paint_event objects.
Definition: textline_base.cpp:68
void nothing_on_focus()
Does nothing on focus in event.
Definition: textline_base.cpp:55
auto key_press_event(ox::Key k) -> bool override
Handles Key_press_event objects.
Definition: textline_base.cpp:87
void set_cursor_to_index(int i)
Set the Cursor to the Glyph in text at index .
Definition: textline_base.cpp:62
auto alignment() const noexcept -> ox::Align
Return the current alignment.
Definition: textline_base.cpp:46
auto mouse_press_event(ox::Mouse const &m) -> bool override
Handles Mouse_press_event objects.
Definition: textline_base.cpp:103
void set_focus_in_action(Action x)
Set the Action that occurs on focus in events.
Definition: textline_base.cpp:51
auto focus_in_action() const noexcept -> Action
Return the currently used focus in event Action.
Definition: textline_base.cpp:57
auto focus_in_event() -> bool override
Handles Focus_in_event objects.
Definition: textline_base.cpp:117
void clear_on_focus()
Clear the text on focus in event, restoring if nothing edited.
Definition: textline_base.cpp:53
void set_alignment(ox::Align x)
Set either Left or Right Alignment, asserts with other alignments.
Definition: textline_base.cpp:40
Provides a view of a Glyph_string and cursor position over a fixed length.
Definition: textline_core.hpp:10
Definition: textline_base.hpp:18