diff --git a/CHANGELOG.md b/CHANGELOG.md index c737a6a77a96..3fb594b6163a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -23,6 +23,7 @@ NOTE: [`epaint`](crates/epaint/CHANGELOG.md), [`eframe`](crates/eframe/CHANGELOG * Add `Button::rounding` to enable round buttons ([#2616](https://github.com/emilk/egui/pull/2616)). * Add `WidgetVisuals::optional_bg_color` - set it to `Color32::TRANSPARENT` to hide button backgrounds ([#2621](https://github.com/emilk/egui/pull/2621)). * Add `Context::screen_rect` and `Context::set_cursor_icon` ([#2625](https://github.com/emilk/egui/pull/2625)). +* You can turn off the vertical line left of indented regions with `Visuals::indent_has_left_vline` ([#2636](https://github.com/emilk/egui/pull/2636)). ### Changed 🔧 * Improved plot grid appearance ([#2412](https://github.com/emilk/egui/pull/2412)). diff --git a/crates/egui/src/style.rs b/crates/egui/src/style.rs index 3078595d5c5c..d90e9c1ac8f1 100644 --- a/crates/egui/src/style.rs +++ b/crates/egui/src/style.rs @@ -497,6 +497,9 @@ pub struct Visuals { /// Show a background behind collapsing headers. pub collapsing_header_frame: bool, + /// Draw a vertical lien left of indented region, in e.g. [`crate::CollapsingHeader`]. + pub indent_has_left_vline: bool, + /// Wether or not Grids and Tables should be striped by default /// (have alternating rows differently colored). pub striped: bool, @@ -752,6 +755,7 @@ impl Visuals { clip_rect_margin: 3.0, // should be at least half the size of the widest frame stroke + max WidgetVisuals::expansion button_frame: true, collapsing_header_frame: false, + indent_has_left_vline: true, striped: false, } @@ -1297,6 +1301,7 @@ impl Visuals { clip_rect_margin, button_frame, collapsing_header_frame, + indent_has_left_vline, striped, } = self; @@ -1354,6 +1359,10 @@ impl Visuals { ui.checkbox(button_frame, "Button has a frame"); ui.checkbox(collapsing_header_frame, "Collapsing header has a frame"); + ui.checkbox( + indent_has_left_vline, + "Paint a vertical line to the left of indented regions", + ); ui.checkbox(striped, "By default, add stripes to grids and tables?"); diff --git a/crates/egui/src/ui.rs b/crates/egui/src/ui.rs index 07b8e2e85bbd..50739c560d12 100644 --- a/crates/egui/src/ui.rs +++ b/crates/egui/src/ui.rs @@ -1789,24 +1789,31 @@ impl Ui { }; let ret = add_contents(&mut child_ui); + let left_vline = self.visuals().indent_has_left_vline; let end_with_horizontal_line = self.spacing().indent_ends_with_horizontal_line; - if end_with_horizontal_line { - child_ui.add_space(4.0); - } + if left_vline || end_with_horizontal_line { + if end_with_horizontal_line { + child_ui.add_space(4.0); + } - // draw a faint line on the left to mark the indented section - let stroke = self.visuals().widgets.noninteractive.bg_stroke; - let left_top = child_rect.min - 0.5 * indent * Vec2::X; - let left_top = self.painter().round_pos_to_pixels(left_top); - let left_bottom = pos2(left_top.x, child_ui.min_rect().bottom() - 2.0); - let left_bottom = self.painter().round_pos_to_pixels(left_bottom); - self.painter.line_segment([left_top, left_bottom], stroke); - if end_with_horizontal_line { - let fudge = 2.0; // looks nicer with button rounding in collapsing headers - let right_bottom = pos2(child_ui.min_rect().right() - fudge, left_bottom.y); - self.painter - .line_segment([left_bottom, right_bottom], stroke); + let stroke = self.visuals().widgets.noninteractive.bg_stroke; + let left_top = child_rect.min - 0.5 * indent * Vec2::X; + let left_top = self.painter().round_pos_to_pixels(left_top); + let left_bottom = pos2(left_top.x, child_ui.min_rect().bottom() - 2.0); + let left_bottom = self.painter().round_pos_to_pixels(left_bottom); + + if left_vline { + // draw a faint line on the left to mark the indented section + self.painter.line_segment([left_top, left_bottom], stroke); + } + + if end_with_horizontal_line { + let fudge = 2.0; // looks nicer with button rounding in collapsing headers + let right_bottom = pos2(child_ui.min_rect().right() - fudge, left_bottom.y); + self.painter + .line_segment([left_bottom, right_bottom], stroke); + } } let response = self.allocate_rect(child_ui.min_rect(), Sense::hover());