le2d v0.4.7
2D game engine framework
 
Loading...
Searching...
No Matches
input_text.hpp
Go to the documentation of this file.
1#pragma once
3#include "le2d/event.hpp"
6#include <kvf/time.hpp>
7
8namespace le {
12 char cursor_symbol{'|'};
13 kvf::Color cursor_color{kvf::white_v};
14 kvf::Seconds blink_period{1s};
15};
16
17namespace drawable {
19class InputText : public RenderInstance, public IDrawable {
20 public:
22
23 explicit InputText(gsl::not_null<IFont*> font, Params const& params = {});
24
25 [[nodiscard]] auto get_size() const -> glm::vec2 { return m_size; }
26 [[nodiscard]] auto get_font() const -> IFont& { return *m_font; }
27 [[nodiscard]] auto get_atlas() const -> IFontAtlas& { return m_line_input.get_atlas(); }
28
29 [[nodiscard]] auto is_interactive() const -> bool { return m_interactive; }
30 void set_interactive(bool interactive);
31
32 [[nodiscard]] auto get_string() const -> std::string_view { return m_line_input.get_string(); }
33 void set_string(std::string line);
34 void append(std::string_view str);
35 void write(char ch);
36 void backspace();
38 void clear();
39
40 [[nodiscard]] auto get_cursor() const -> int { return m_line_input.get_cursor(); }
41 void set_cursor(int cursor);
42 void move_cursor(int const delta) { set_cursor(get_cursor() + delta); }
43 void cursor_left() { move_cursor(-1); }
44 void cursor_right() { move_cursor(+1); }
45 void cursor_home() { set_cursor(0); }
46 void cursor_end() { set_cursor(int(get_string().size())); }
47
48 void on_key(event::Key const& key);
50
51 void tick(kvf::Seconds dt);
52 void draw(IRenderer& renderer) const override;
53
54 private:
55 void update();
56 void reset_blink();
57
58 gsl::not_null<IFont*> m_font;
59
60 LineInput m_line_input;
61 TextGeometry m_cursor{};
62 kvf::Color m_cursor_color;
63 kvf::Seconds m_blink_period;
64
65 float m_cursor_offset_x{};
66
67 glm::vec2 m_size{};
68
69 kvf::Seconds m_elapsed{};
70 float m_cursor_alpha{1.0f};
71 bool m_interactive{true};
72};
73} // namespace drawable
74} // namespace le
Interface for drawable types.
Definition drawable.hpp:6
Opaque interface for a Font Atlas.
Definition font.hpp:8
Opaque interface for a Font.
Definition font.hpp:23
Definition renderer.hpp:15
Interactive text input for a single line.
Definition line_input.hpp:9
auto get_atlas() const -> IFontAtlas &
Definition line_input.hpp:20
auto get_cursor() const -> int
Definition line_input.hpp:15
auto get_string() const -> std::string_view
Definition line_input.hpp:13
Drawable geometry for text.
Definition text_geometry.hpp:9
Interactive input text with cursor.
Definition input_text.hpp:19
void set_string(std::string line)
void on_key(event::Key const &key)
void draw(IRenderer &renderer) const override
void cursor_left()
Definition input_text.hpp:43
auto get_size() const -> glm::vec2
Definition input_text.hpp:25
InputText(gsl::not_null< IFont * > font, Params const &params={})
auto get_cursor() const -> int
Definition input_text.hpp:40
auto get_font() const -> IFont &
Definition input_text.hpp:26
void move_cursor(int const delta)
Definition input_text.hpp:42
void set_cursor(int cursor)
void set_interactive(bool interactive)
void cursor_home()
Definition input_text.hpp:45
void on_codepoint(event::Codepoint codepoint)
void cursor_right()
Definition input_text.hpp:44
void append(std::string_view str)
void tick(kvf::Seconds dt)
void cursor_end()
Definition input_text.hpp:46
auto get_atlas() const -> IFontAtlas &
Definition input_text.hpp:27
auto get_string() const -> std::string_view
Definition input_text.hpp:32
auto is_interactive() const -> bool
Definition input_text.hpp:29
kvf::Codepoint Codepoint
Definition event.hpp:37
Definition animation.hpp:8
TextHeight
Strongly typed integer for text height.
Definition text_height.hpp:6
Input Text creation parameters.
Definition input_text.hpp:10
kvf::Seconds blink_period
Definition input_text.hpp:14
kvf::Color cursor_color
Definition input_text.hpp:13
char cursor_symbol
Definition input_text.hpp:12
TextHeight height
Definition input_text.hpp:11
Instance data for instanced rendering.
Definition render_instance.hpp:7
Definition event.hpp:39