Make the line left of indented regions optional (#2636)
* Make the line left of indented regions optional Controlled with Visuals::indent_has_left_vline * Add line to changelog * Fix doclink
This commit is contained in:
parent
ce62b61e15
commit
fe7ff66266
3 changed files with 32 additions and 15 deletions
|
@ -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 `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 `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)).
|
* 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 🔧
|
### Changed 🔧
|
||||||
* Improved plot grid appearance ([#2412](https://github.com/emilk/egui/pull/2412)).
|
* Improved plot grid appearance ([#2412](https://github.com/emilk/egui/pull/2412)).
|
||||||
|
|
|
@ -497,6 +497,9 @@ pub struct Visuals {
|
||||||
/// Show a background behind collapsing headers.
|
/// Show a background behind collapsing headers.
|
||||||
pub collapsing_header_frame: bool,
|
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
|
/// Wether or not Grids and Tables should be striped by default
|
||||||
/// (have alternating rows differently colored).
|
/// (have alternating rows differently colored).
|
||||||
pub striped: bool,
|
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
|
clip_rect_margin: 3.0, // should be at least half the size of the widest frame stroke + max WidgetVisuals::expansion
|
||||||
button_frame: true,
|
button_frame: true,
|
||||||
collapsing_header_frame: false,
|
collapsing_header_frame: false,
|
||||||
|
indent_has_left_vline: true,
|
||||||
|
|
||||||
striped: false,
|
striped: false,
|
||||||
}
|
}
|
||||||
|
@ -1297,6 +1301,7 @@ impl Visuals {
|
||||||
clip_rect_margin,
|
clip_rect_margin,
|
||||||
button_frame,
|
button_frame,
|
||||||
collapsing_header_frame,
|
collapsing_header_frame,
|
||||||
|
indent_has_left_vline,
|
||||||
|
|
||||||
striped,
|
striped,
|
||||||
} = self;
|
} = self;
|
||||||
|
@ -1354,6 +1359,10 @@ impl Visuals {
|
||||||
|
|
||||||
ui.checkbox(button_frame, "Button has a frame");
|
ui.checkbox(button_frame, "Button has a frame");
|
||||||
ui.checkbox(collapsing_header_frame, "Collapsing header 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?");
|
ui.checkbox(striped, "By default, add stripes to grids and tables?");
|
||||||
|
|
||||||
|
|
|
@ -1789,25 +1789,32 @@ impl Ui {
|
||||||
};
|
};
|
||||||
let ret = add_contents(&mut child_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;
|
let end_with_horizontal_line = self.spacing().indent_ends_with_horizontal_line;
|
||||||
|
|
||||||
|
if left_vline || end_with_horizontal_line {
|
||||||
if end_with_horizontal_line {
|
if end_with_horizontal_line {
|
||||||
child_ui.add_space(4.0);
|
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 stroke = self.visuals().widgets.noninteractive.bg_stroke;
|
||||||
let left_top = child_rect.min - 0.5 * indent * Vec2::X;
|
let left_top = child_rect.min - 0.5 * indent * Vec2::X;
|
||||||
let left_top = self.painter().round_pos_to_pixels(left_top);
|
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 = pos2(left_top.x, child_ui.min_rect().bottom() - 2.0);
|
||||||
let left_bottom = self.painter().round_pos_to_pixels(left_bottom);
|
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);
|
self.painter.line_segment([left_top, left_bottom], stroke);
|
||||||
|
}
|
||||||
|
|
||||||
if end_with_horizontal_line {
|
if end_with_horizontal_line {
|
||||||
let fudge = 2.0; // looks nicer with button rounding in collapsing headers
|
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);
|
let right_bottom = pos2(child_ui.min_rect().right() - fudge, left_bottom.y);
|
||||||
self.painter
|
self.painter
|
||||||
.line_segment([left_bottom, right_bottom], stroke);
|
.line_segment([left_bottom, right_bottom], stroke);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
let response = self.allocate_rect(child_ui.min_rect(), Sense::hover());
|
let response = self.allocate_rect(child_ui.min_rect(), Sense::hover());
|
||||||
InnerResponse::new(ret, response)
|
InnerResponse::new(ret, response)
|
||||||
|
|
Loading…
Reference in a new issue