Remove caret inset

Signed-off-by: Slendi <slendi@socopon.com>
This commit is contained in:
2025-10-10 03:25:29 +03:00
parent 30b558f649
commit 18614ccee9

View File

@@ -114,7 +114,6 @@ auto encode_utf8(u32 cp) -> std::string
constexpr float HORIZONTAL_PADDING = 6.0f;
constexpr float VERTICAL_PADDING = 4.0f;
constexpr float CARET_WIDTH = 2.0f;
constexpr float CARET_INSET = 1.0f;
constexpr double CARET_BLINK_INTERVAL = 0.5;
constexpr float CARET_DESCENT_FRACTION = 0.25f;
@@ -362,7 +361,8 @@ auto ImGui::text_input(std::size_t id, std::pmr::string &str, Rectangle rec,
state.caret_visible = true;
state.caret_timer += dt;
if (state.caret_timer >= CARET_BLINK_INTERVAL) {
int toggles = static_cast<int>(state.caret_timer / CARET_BLINK_INTERVAL);
int toggles = static_cast<int>(
state.caret_timer / CARET_BLINK_INTERVAL);
state.caret_timer
= std::fmod(state.caret_timer, CARET_BLINK_INTERVAL);
if (toggles % 2 == 1)
@@ -422,7 +422,8 @@ auto ImGui::text_input(std::size_t id, std::pmr::string &str, Rectangle rec,
float const max_top = rec.y + rec.height - VERTICAL_PADDING - caret_height;
caret_top = std::clamp(caret_top, min_top, max_top);
float caret_bottom = caret_top + caret_height;
float const desired_bottom = baseline_y + options.font_size * CARET_DESCENT_FRACTION;
float const desired_bottom
= baseline_y + options.font_size * CARET_DESCENT_FRACTION;
if (caret_bottom < desired_bottom) {
float const adjust = desired_bottom - caret_bottom;
caret_top = std::min(caret_top + adjust, max_top);
@@ -443,8 +444,7 @@ auto ImGui::text_input(std::size_t id, std::pmr::string &str, Rectangle rec,
if (m_focused_id == id && state.caret_visible) {
float const caret_x = std::round(rec.x + HORIZONTAL_PADDING
+ state.cursor_position.x - state.scroll_offset.x
+ CARET_INSET);
+ state.cursor_position.x - state.scroll_offset.x);
Rectangle caret_rect {
caret_x,
caret_top,