Selection color from accent color

Signed-off-by: Slendi <slendi@socopon.com>
This commit is contained in:
2025-10-10 11:22:43 +03:00
parent 0629283aa5
commit f728d61f23
6 changed files with 116 additions and 68 deletions

View File

@@ -307,11 +307,11 @@ auto ImGui::text_input(std::size_t id, std::pmr::string &str, Rectangle rec,
if (m_focused_id == 0)
m_focused_id = id;
if (options.font_size > rec.height) {
if (style().font_size > rec.height) {
TraceLog(LOG_WARNING,
std::format("Text size for text input {} is bigger than height ({} "
"> {}). Clipping will occur.",
id, options.font_size, rec.height)
id, style().font_size, rec.height)
.c_str());
}
@@ -545,7 +545,7 @@ auto ImGui::text_input(std::size_t id, std::pmr::string &str, Rectangle rec,
&& (!state.preedit_text.empty() || !state.preedit_cursor_hidden);
if (m_font.has_value() && m_text_renderer) {
int const font_px = static_cast<int>(options.font_size);
int const font_px = static_cast<int>(style().font_size);
std::string_view const prefix_view(str.data(), caret_byte);
prefix_metrics
= m_text_renderer->measure_text(*m_font, prefix_view, font_px);
@@ -616,21 +616,21 @@ auto ImGui::text_input(std::size_t id, std::pmr::string &str, Rectangle rec,
DrawRectangleLinesEx(rec, 1.0f, border_col);
float const text_top = rec.y + VERTICAL_PADDING;
float const baseline_y = text_top + options.font_size;
float const baseline_y = text_top + style().font_size;
float const max_caret_height
= std::max(0.0f, rec.height - 2.0f * VERTICAL_PADDING);
float caret_height = options.font_size * (1.0f + CARET_DESCENT_FRACTION);
float caret_height = style().font_size * (1.0f + CARET_DESCENT_FRACTION);
caret_height = std::min(caret_height,
max_caret_height > 0.0f ? max_caret_height : caret_height);
if (caret_height <= 0.0f)
caret_height = options.font_size;
float caret_top = baseline_y - options.font_size;
caret_height = style().font_size;
float caret_top = baseline_y - style().font_size;
float const min_top = rec.y + VERTICAL_PADDING;
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;
= baseline_y + style().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);
@@ -650,12 +650,12 @@ auto ImGui::text_input(std::size_t id, std::pmr::string &str, Rectangle rec,
BeginScissorMode(rec.x, rec.y, rec.width, rec.height);
{
if (m_font.has_value() && m_text_renderer) {
int const font_px = static_cast<int>(options.font_size);
int const font_px = static_cast<int>(style().font_size);
Vector2 const base_pos {
rec.x + HORIZONTAL_PADDING - state.scroll_offset.x,
baseline_y,
};
Color const &text_color = options.text_color;
Color const &text_color = style().text_color;
std::string_view const left_view(str.data(), caret_byte);
std::string_view const right_view(
str.data() + caret_byte, str.size() - caret_byte);
@@ -679,10 +679,12 @@ auto ImGui::text_input(std::size_t id, std::pmr::string &str, Rectangle rec,
selection_metrics.x,
caret_height,
};
Color const highlight { 120, 160, 255, 100 };
Color const highlight { style().selection_color };
DrawRectangleRec(sel_rect, highlight);
}
Color const &preedit_color { options.preedit_color };
Color const &preedit_color { selection_metrics.x > 0.0f
? style().selection_text_color
: style().preedit_color };
m_text_renderer->draw_text(*m_font,
std::string_view(
state.preedit_text.data(), state.preedit_text.size()),