Browse Source

Separate text cursor from selection visuals (#3181)

pull/3105/merge
lampsitter 1 year ago
committed by GitHub
parent
commit
cd917e49f2
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 11
      crates/egui/src/style.rs
  2. 7
      crates/egui/src/widgets/text_edit/builder.rs

11
crates/egui/src/style.rs

@ -508,7 +508,8 @@ pub struct Visuals {
pub resize_corner_size: f32,
pub text_cursor_width: f32,
/// The color and width of the text cursor
pub text_cursor: Stroke,
/// show where the text cursor would be if you clicked
pub text_cursor_preview: bool,
@ -784,7 +785,7 @@ impl Visuals {
popup_shadow: Shadow::small_dark(),
resize_corner_size: 12.0,
text_cursor_width: 2.0,
text_cursor: Stroke::new(2.0, Color32::from_rgb(192, 222, 255)),
text_cursor_preview: false,
clip_rect_margin: 3.0, // should be at least half the size of the widest frame stroke + max WidgetVisuals::expansion
button_frame: true,
@ -817,6 +818,7 @@ impl Visuals {
panel_fill: Color32::from_gray(248),
popup_shadow: Shadow::small_light(),
text_cursor: Stroke::new(2.0, Color32::from_rgb(0, 83, 125)),
..Self::dark()
}
}
@ -1351,7 +1353,7 @@ impl Visuals {
popup_shadow,
resize_corner_size,
text_cursor_width,
text_cursor,
text_cursor_preview,
clip_rect_margin,
button_frame,
@ -1409,8 +1411,9 @@ impl Visuals {
});
ui_color(ui, hyperlink_color, "hyperlink_color");
stroke_ui(ui, text_cursor, "Text Cursor");
ui.add(Slider::new(resize_corner_size, 0.0..=20.0).text("resize_corner_size"));
ui.add(Slider::new(text_cursor_width, 0.0..=4.0).text("text_cursor_width"));
ui.checkbox(text_cursor_preview, "Preview text cursor on hover");
ui.add(Slider::new(clip_rect_margin, 0.0..=20.0).text("clip_rect_margin"));

7
crates/egui/src/widgets/text_edit/builder.rs

@ -1138,7 +1138,7 @@ fn paint_cursor_end(
galley: &Galley,
cursor: &Cursor,
) -> Rect {
let stroke = ui.visuals().selection.stroke;
let stroke = ui.visuals().text_cursor;
let mut cursor_pos = galley.pos_from_cursor(cursor).translate(pos.to_vec2());
cursor_pos.max.y = cursor_pos.max.y.at_least(cursor_pos.min.y + row_height); // Handle completely empty galleys
@ -1147,10 +1147,7 @@ fn paint_cursor_end(
let top = cursor_pos.center_top();
let bottom = cursor_pos.center_bottom();
painter.line_segment(
[top, bottom],
(ui.visuals().text_cursor_width, stroke.color),
);
painter.line_segment([top, bottom], (stroke.width, stroke.color));
if false {
// Roof/floor:

Loading…
Cancel
Save