Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Separate text cursor from selection visuals #3181

Merged
merged 1 commit into from
Aug 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions crates/egui/src/style.rs
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,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 @@ -767,7 +768,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 @@ -800,6 +801,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 @@ -1334,7 +1336,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 @@ -1392,8 +1394,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
Loading