Skip to content

Commit

Permalink
Separate text cursor from selection visuals (#3181)
Browse files Browse the repository at this point in the history
  • Loading branch information
lampsitter authored Aug 9, 2023
1 parent 0e5f93b commit cd917e4
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
11 changes: 7 additions & 4 deletions crates/egui/src/style.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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()
}
}
Expand Down Expand Up @@ -1351,7 +1353,7 @@ impl Visuals {
popup_shadow,

resize_corner_size,
text_cursor_width,
text_cursor,
text_cursor_preview,
clip_rect_margin,
button_frame,
Expand Down Expand Up @@ -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"));

Expand Down
7 changes: 2 additions & 5 deletions crates/egui/src/widgets/text_edit/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand Down

0 comments on commit cd917e4

Please sign in to comment.