Text input

Signed-off-by: Slendi <slendi@socopon.com>
This commit is contained in:
2025-10-10 03:19:01 +03:00
parent 52fe62c3b1
commit 804c420744
3 changed files with 463 additions and 21 deletions

View File

@@ -2,12 +2,13 @@
#include <bitset>
#include <memory>
#include <optional>
#include <raylib.h>
#include "TextRenderer.hpp"
constexpr float DEFAULT_FONT_SIZE { 16 };
constexpr float DEFAULT_FONT_SIZE { 24 };
struct TextInputOptions {
bool multiline { false };
@@ -30,6 +31,8 @@ struct ImGui {
auto text_input(std::size_t id, std::pmr::string &str, Rectangle rec,
TextInputOptions options = {}) -> std::bitset<2>;
void set_font(FontHandle font);
[[nodiscard]] inline auto id(std::string_view const str) -> std::size_t
{
std::hash<std::string_view> hasher;
@@ -41,6 +44,8 @@ private:
int current_rune_idx { 0 };
Vector2 scroll_offset; // y not used if multiline == false
Vector2 cursor_position; // y not used if multiline == false
bool caret_visible { true };
double caret_timer { 0.0 };
};
std::unordered_map<std::size_t, TextInputState> m_ti_states;
@@ -49,6 +54,7 @@ private:
bool m_ctrl {};
bool m_shift {};
std::optional<FontHandle> m_font {};
std::shared_ptr<TextRenderer> m_text_renderer {};
};