correctly display single line selection
This commit is contained in:
@@ -168,9 +168,54 @@ main :: proc() {
|
|||||||
}
|
}
|
||||||
raw_data(line)[len(line)] = 0
|
raw_data(line)[len(line)] = 0
|
||||||
|
|
||||||
cstr := strings.unsafe_string_to_cstring(string(line[:]))
|
|
||||||
pos := r.Vector2{0, font_size * f32(line_index)}
|
if selection.active &&
|
||||||
r.DrawTextEx(font, cstr, pos, font_size, 0, r.WHITE)
|
line_index == selection.start_line &&
|
||||||
|
line_index == selection.end_line {
|
||||||
|
selection_begin := min(selection.start_char, selection.end_char)
|
||||||
|
selection_end := max(selection.start_char, selection.end_char)
|
||||||
|
prefix := line[:selection_begin]
|
||||||
|
suffix := line[selection_end + 1:] if selection_end + 1 < len(line) else []u8{}
|
||||||
|
// need to copy these into separate buffers for zero value
|
||||||
|
x: f32 = 0.0
|
||||||
|
if len(prefix) != 0 {
|
||||||
|
cstr := strings.clone_to_cstring(string(prefix), context.temp_allocator)
|
||||||
|
measurements := r.MeasureTextEx(font, cstr, font_size, 0)
|
||||||
|
pos := r.Vector2{x, font_size * f32(line_index)}
|
||||||
|
r.DrawTextEx(font, cstr, pos, font_size, 0, r.WHITE)
|
||||||
|
x += measurements.x
|
||||||
|
}
|
||||||
|
|
||||||
|
selected_str := string(line[selection_begin:selection_end + 1])
|
||||||
|
cstr :=
|
||||||
|
strings.clone_to_cstring(selected_str, context.temp_allocator) if len(suffix) != 0 else strings.unsafe_string_to_cstring(selected_str)
|
||||||
|
measurements := r.MeasureTextEx(font, cstr, font_size, 0)
|
||||||
|
pos := r.Vector2{x, font_size * f32(line_index)}
|
||||||
|
r.DrawRectangle(
|
||||||
|
i32(pos.x),
|
||||||
|
i32(pos.y),
|
||||||
|
i32(measurements.x),
|
||||||
|
i32(measurements.y),
|
||||||
|
r.WHITE,
|
||||||
|
)
|
||||||
|
r.DrawTextEx(font, cstr, pos, font_size, 0, r.BLACK)
|
||||||
|
x += measurements.x
|
||||||
|
|
||||||
|
if len(suffix) != 0 {
|
||||||
|
cstr := strings.unsafe_string_to_cstring(string(suffix))
|
||||||
|
// cstr := strings.clone_to_cstring(string(suffix), context.temp_allocator)
|
||||||
|
pos := r.Vector2{x, font_size * f32(line_index)}
|
||||||
|
r.DrawTextEx(font, cstr, pos, font_size, 0, r.WHITE)
|
||||||
|
}
|
||||||
|
} else if selection.active && line_index == selection.start_line {
|
||||||
|
} else if selection.active && line_index == selection.end_line {
|
||||||
|
} else if selection.active && selection.start_line < line_index && line_index < selection.end_line {
|
||||||
|
} else {
|
||||||
|
// No selection active
|
||||||
|
cstr := strings.unsafe_string_to_cstring(string(line[:]))
|
||||||
|
pos := r.Vector2{0, font_size * f32(line_index)}
|
||||||
|
r.DrawTextEx(font, cstr, pos, font_size, 0, r.WHITE)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
render_cursor(&cursor)
|
render_cursor(&cursor)
|
||||||
|
|||||||
Reference in New Issue
Block a user