TermOx
textbox.hpp
1 #ifndef TERMOX_WIDGET_WIDGETS_TEXTBOX_HPP
2 #define TERMOX_WIDGET_WIDGETS_TEXTBOX_HPP
3 #include <memory>
4 
5 #include <termox/painter/glyph_string.hpp>
6 #include <termox/system/key.hpp>
7 #include <termox/system/mouse.hpp>
8 #include <termox/widget/widgets/detail/textbox_base.hpp>
9 
10 namespace ox {
11 
13 
15 class Textbox : public detail::Textbox_base {
16  public:
17  struct Parameters {
18  Glyph_string text = U"";
19  Align alignment = Align::Left;
20  Wrap wrap = Wrap::Word;
21  Brush insert_brush = Brush{};
22  int scroll_speed = 1;
23  bool text_input = true;
24  };
25 
26  public:
28  explicit Textbox(Glyph_string text = U"",
29  Align alignment = Align::Left,
30  Wrap wrap = Wrap::Word,
32  int scroll_speed = 1,
33  bool text_input = true);
34 
35  explicit Textbox(Parameters p);
36 
37  public:
39 
40  void set_scroll_speed(int x) noexcept;
41 
43  [[nodiscard]] auto scroll_speed() const noexcept -> int;
44 
46  void enable_text_input() noexcept;
47 
49  void disable_text_input() noexcept;
50 
52  [[nodiscard]] auto has_text_input() const noexcept -> bool;
53 
54  protected:
56  auto key_press_event(Key k) -> bool override;
57 
59  auto mouse_press_event(Mouse const& m) -> bool override;
60 
62  auto mouse_wheel_event(Mouse const& m) -> bool override;
63 
64  private:
65  int scroll_speed_;
66  bool takes_input_;
67 };
68 
70 [[nodiscard]] auto textbox(Glyph_string text = U"",
71  Align alignment = Align::Left,
72  Wrap wrap = Wrap::Word,
74  int scroll_speed = 1,
75  bool text_input = true) -> std::unique_ptr<Textbox>;
76 
78 [[nodiscard]] auto textbox(Textbox::Parameters p) -> std::unique_ptr<Textbox>;
79 
80 } // namespace ox
81 #endif // TERMOX_WIDGET_WIDGETS_TEXTBOX_HPP
Holds the look of any paintable object with Traits and Colors.
Definition: brush.hpp:13
Holds a collection of Glyphs with a similar interface to std::string.
Definition: glyph_string.hpp:19
auto alignment() const -> Align
Return the currently used Alignment.
Definition: text_view.cpp:53
Brush insert_brush
Brush to be applied to all new incoming Glyphs, but not existing Glyphs.
Definition: text_view.hpp:33
auto wrap() const -> Wrap
Return the currently set text Wrap type.
Definition: text_view.cpp:61
auto text() -> Glyph_string &
Return the entire contents of the Text_view.
Definition: text_view.cpp:43
Interactive Glyph_string display with text wrapping, alignment, etc...
Definition: textbox.hpp:15
auto scroll_speed() const noexcept -> int
Return the current scroll wheel speed.
Definition: textbox.cpp:32
void set_scroll_speed(int x) noexcept
Set the number of lines scrolled vertically on scroll wheel events.
Definition: textbox.cpp:30
auto mouse_press_event(Mouse const &m) -> bool override
Move the cursor to the pressed, or nearest cell, that contains a Glyph.
Definition: textbox.cpp:99
void enable_text_input() noexcept
Enable the Textbox to take keyboard input.
Definition: textbox.cpp:34
auto key_press_event(Key k) -> bool override
Either input a Glyph from the Key, or move the cursor on arrow presses.
Definition: textbox.cpp:40
auto has_text_input() const noexcept -> bool
Return true if currently takes text keyboard input.
Definition: textbox.cpp:38
auto mouse_wheel_event(Mouse const &m) -> bool override
Scroll.
Definition: textbox.cpp:106
Textbox(Glyph_string text=U"", Align alignment=Align::Left, Wrap wrap=Wrap::Word, Brush insert_brush=Brush{}, int scroll_speed=1, bool text_input=true)
Construct a Textbox with initial contents and strong focus.
Definition: textbox.cpp:12
void disable_text_input() noexcept
Disable the Textbox from taking keyboard input.
Definition: textbox.cpp:36
Implements cursor movement on top of a Text_view, for use by Textbox.
Definition: textbox_base.hpp:14
Definition: textbox.hpp:17