Skip to content

Commit

Permalink
Make the line left of indented regions optional (emilk#2636)
Browse files Browse the repository at this point in the history
* Make the line left of indented regions optional

Controlled with Visuals::indent_has_left_vline

* Add line to changelog

* Fix doclink
  • Loading branch information
emilk authored and lictex committed Jan 28, 2023
1 parent d5438af commit ba1ae53
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 15 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 🔧
* `Frame::paint` now takes an extra `&Context` argument ([#2564](https://github.com/emilk/egui/pull/2564)).
Expand Down
9 changes: 9 additions & 0 deletions crates/egui/src/style.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
}
Expand Down Expand Up @@ -1297,6 +1301,7 @@ impl Visuals {
clip_rect_margin,
button_frame,
collapsing_header_frame,
indent_has_left_vline,

striped,
} = self;
Expand Down Expand Up @@ -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?");

Expand Down
37 changes: 22 additions & 15 deletions crates/egui/src/ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1795,24 +1795,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());
Expand Down

0 comments on commit ba1ae53

Please sign in to comment.