From cd917e49f210b14b6961379e672fa60f84a78fe6 Mon Sep 17 00:00:00 2001 From: lampsitter <96946613+lampsitter@users.noreply.github.com> Date: Wed, 9 Aug 2023 11:07:40 +0200 Subject: [PATCH] Separate text cursor from selection visuals (#3181) --- crates/egui/src/style.rs | 11 +++++++---- crates/egui/src/widgets/text_edit/builder.rs | 7 ++----- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/crates/egui/src/style.rs b/crates/egui/src/style.rs index 09eb5835bc7..4a8dba7c0d6 100644 --- a/crates/egui/src/style.rs +++ b/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")); diff --git a/crates/egui/src/widgets/text_edit/builder.rs b/crates/egui/src/widgets/text_edit/builder.rs index c9eaa1d4b70..e92bf9dbcb5 100644 --- a/crates/egui/src/widgets/text_edit/builder.rs +++ b/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: