le2d v0.4.7
2D game engine framework
 
Loading...
Searching...
No Matches
line_input.hpp
Go to the documentation of this file.
1#pragma once
2#include "le2d/primitive.hpp"
5#include <gsl/pointers>
6
7namespace le {
9class LineInput {
10 public:
11 explicit LineInput(gsl::not_null<IFont*> font, TextHeight height = TextHeight::Default);
12
13 [[nodiscard]] auto get_string() const -> std::string_view { return m_line; }
14 [[nodiscard]] auto get_height() const -> TextHeight { return m_atlas->get_height(); }
15 [[nodiscard]] auto get_cursor() const -> int { return m_cursor; }
16 [[nodiscard]] auto get_cursor_x() const -> float { return m_cursor_x; }
17 [[nodiscard]] auto get_size() const -> glm::vec2 { return m_size; }
18 [[nodiscard]] auto get_glyph_layouts() const -> std::span<kvf::ttf::GlyphLayout const> { return m_glyph_layouts; }
19
20 [[nodiscard]] auto get_atlas() const -> IFontAtlas& { return *m_atlas; }
21 [[nodiscard]] auto get_texture() const -> ITexture const& { return get_atlas().get_texture(); }
22
23 [[nodiscard]] auto to_primitive() const -> Primitive;
24
25 void set_string(std::string line);
26 void append(std::string_view str);
27
28 void write(char ch);
29 void backspace();
31
32 void set_cursor(int cursor);
33 void move_cursor(int delta);
34
35 protected:
36 void update();
37
38 private:
39 void update_cursor_x();
40
41 gsl::not_null<IFontAtlas*> m_atlas;
42
43 std::vector<kvf::ttf::GlyphLayout> m_glyph_layouts{};
44 TextGeometry m_geometry{};
45
46 std::string m_line{};
47 glm::vec2 m_size{};
48 int m_cursor{};
49 float m_cursor_x{};
50 float m_next_glyph_x{};
51};
52} // namespace le
Opaque interface for a Font Atlas.
Definition font.hpp:8
Concrete drawable Texture.
Definition texture.hpp:31
Interactive text input for a single line.
Definition line_input.hpp:9
LineInput(gsl::not_null< IFont * > font, TextHeight height=TextHeight::Default)
void backspace()
void delete_front()
auto get_height() const -> TextHeight
Definition line_input.hpp:14
auto get_cursor_x() const -> float
Definition line_input.hpp:16
auto get_size() const -> glm::vec2
Definition line_input.hpp:17
auto get_atlas() const -> IFontAtlas &
Definition line_input.hpp:20
auto get_glyph_layouts() const -> std::span< kvf::ttf::GlyphLayout const >
Definition line_input.hpp:18
void set_cursor(int cursor)
void move_cursor(int delta)
auto get_texture() const -> ITexture const &
Definition line_input.hpp:21
auto to_primitive() const -> Primitive
void write(char ch)
auto get_cursor() const -> int
Definition line_input.hpp:15
void set_string(std::string line)
void append(std::string_view str)
auto get_string() const -> std::string_view
Definition line_input.hpp:13
Drawable geometry for text.
Definition text_geometry.hpp:9
Definition texture.hpp:9
Definition animation.hpp:8
TextHeight
Strongly typed integer for text height.
Definition text_height.hpp:6
Draw primitive.
Definition primitive.hpp:10