Signed-off-by: Slendi <slendi@socopon.com>
This commit is contained in:
2025-10-10 02:50:34 +03:00
parent 47ffde7996
commit 52fe62c3b1
5 changed files with 66 additions and 27 deletions

View File

@@ -7,8 +7,11 @@
#include "TextRenderer.hpp"
constexpr float DEFAULT_FONT_SIZE { 16 };
struct TextInputOptions {
bool multiline { false };
float font_size { DEFAULT_FONT_SIZE };
};
struct ImGui {
@@ -19,7 +22,7 @@ struct ImGui {
ImGui(ImGui &&) = default;
auto operator=(ImGui &&) -> ImGui & = default;
void begin(std::pmr::vector<u32> const input_runes, bool ctrl, bool shift);
void begin(u32 const rune, bool ctrl, bool shift);
void end();
// Bit 0 -> Submitted
@@ -36,11 +39,13 @@ struct ImGui {
private:
struct TextInputState {
int current_rune_idx { 0 };
Vector2 scroll_offset; // y not used if multiline == false
Vector2 cursor_position; // y not used if multiline == false
};
std::unordered_map<std::size_t, TextInputState> m_ti_states;
std::size_t m_focused {};
std::pmr::vector<u32> m_input_runes {}; // 0123 <-> hjkl arrow keys
std::size_t m_focused_id {};
u32 m_rune {}; // 1234 <-> hjkl arrow keys
bool m_ctrl {};
bool m_shift {};
@@ -48,14 +53,14 @@ private:
};
struct ImGuiGuard {
ImGuiGuard(ImGui *imgui, std::pmr::vector<u32> const input_runes, bool ctrl,
bool shift)
ImGuiGuard(std::shared_ptr<ImGui> imgui, u32 const rune, bool const ctrl,
bool const shift)
: m_imgui(imgui)
{
m_imgui->begin(input_runes, ctrl, shift);
m_imgui->begin(rune, ctrl, shift);
}
~ImGuiGuard() { m_imgui->end(); }
private:
ImGui *m_imgui { nullptr };
std::shared_ptr<ImGui> m_imgui { nullptr };
};