Signed-off-by: Slendi <slendi@socopon.com>
This commit is contained in:
2025-10-16 19:48:02 +03:00
parent a67b787386
commit d368760f78
20 changed files with 9358 additions and 108 deletions

View File

@@ -121,18 +121,6 @@ auto clamp_preedit_index(int value, usize text_size) -> usize
return std::min(as_size, text_size);
}
auto slice_bytes(std::string_view text, usize begin, usize end)
-> std::string_view
{
if (begin > text.size())
begin = text.size();
if (end > text.size())
end = text.size();
if (end < begin)
end = begin;
return std::string_view(text.data() + begin, end - begin);
}
constexpr float HORIZONTAL_PADDING = 6.0f;
constexpr float VERTICAL_PADDING = 4.0f;
constexpr double CARET_BLINK_INTERVAL = 0.5;
@@ -228,9 +216,9 @@ void ImGui::ime_delete_surrounding(
if (it == m_ti_states.end())
return;
auto &state { it->second };
usize caret_byte = std::min(state.caret_byte, str.size());
usize start = before > caret_byte ? 0 : caret_byte - before;
usize end = std::min(caret_byte + after, str.size());
usize caret_byte { std::min(state.caret_byte, str.size()) };
usize start { before > caret_byte ? 0 : caret_byte - before };
usize end { std::min(caret_byte + after, str.size()) };
if (end > start) {
str.erase(start, end - start);
state.caret_byte = start;
@@ -289,10 +277,8 @@ void ImGui::ime_clear_preedit()
size_t utf8_length(std::string_view const &s)
{
size_t count = 0;
for (unsigned char c : s)
if ((c & 0xC0) != 0x80)
++count;
size_t count = std::count_if(
s.begin(), s.end(), [](auto const &c) { return (c & 0xC0) != 0x80; });
return count;
}
@@ -554,9 +540,9 @@ auto ImGui::text_input(usize id, std::pmr::string &str, Rectangle rec,
if (!options.multiline) {
std::string clip2;
clip2.reserve(m_clipboard.size());
for (auto ch : m_clipboard)
if (ch != '\n' && ch != '\r')
clip2.push_back(ch);
std::copy_if(m_clipboard.begin(), m_clipboard.end(),
clip2.begin(),
[](char ch) { return ch != '\n' && ch != '\r'; });
str.insert(caret_byte, clip2);
state.current_rune_idx += (int)utf8_length(clip2);
} else {
@@ -763,8 +749,8 @@ auto ImGui::text_input(usize id, std::pmr::string &str, Rectangle rec,
if (m_focused_id == id && state.caret_visible) {
float const caret_x = std::floor(origin + caret_offset + 0.5f);
Vector2 p0 { caret_x, std::floor(caret_top + 0.5f) };
Vector2 p1 { caret_x,
Vector2 const p0 { caret_x, std::floor(caret_top + 0.5f) };
Vector2 const p1 { caret_x,
std::floor((caret_top + caret_height) + 0.5f) };
DrawLineV(p0, p1, text_color);
}
@@ -784,15 +770,12 @@ auto ImGui::text_input(usize id, std::pmr::string &str, Rectangle rec,
auto ImGui::list_view(usize id, Rectangle bounds, usize elements,
std::function<Vector2(usize i)> draw_cb, ListViewOptions options) -> bool
{
auto &state { m_lv_states[id] };
auto const &state { m_lv_states[id] };
bool submitted { false };
bool select_next = m_next_lv_next;
m_next_lv_next = false;
bool select_previous = m_next_lv_previous;
m_next_lv_previous = false;
bool select_clear = m_next_lv_clear;
m_next_lv_clear = false;
BeginScissorMode(bounds.x, bounds.y, bounds.width, bounds.height);