Add show_separator_line to SidePanel and TopBottomPanel

So as not to force it onto all users since #2261
This commit is contained in:
Emil Ernerfeldt 2022-12-05 12:58:26 +01:00
parent aa503008ae
commit df01db2df1

View file

@ -97,6 +97,7 @@ pub struct SidePanel {
id: Id, id: Id,
frame: Option<Frame>, frame: Option<Frame>,
resizable: bool, resizable: bool,
show_separator_line: bool,
default_width: f32, default_width: f32,
width_range: RangeInclusive<f32>, width_range: RangeInclusive<f32>,
} }
@ -119,6 +120,7 @@ impl SidePanel {
id: id.into(), id: id.into(),
frame: None, frame: None,
resizable: true, resizable: true,
show_separator_line: true,
default_width: 200.0, default_width: 200.0,
width_range: 96.0..=f32::INFINITY, width_range: 96.0..=f32::INFINITY,
} }
@ -140,6 +142,14 @@ impl SidePanel {
self self
} }
/// Show a separator line, even when not interacting with it?
///
/// Default: `true`.
pub fn show_separator_line(mut self, show_separator_line: bool) -> Self {
self.show_separator_line = show_separator_line;
self
}
/// The initial wrapping width of the [`SidePanel`]. /// The initial wrapping width of the [`SidePanel`].
pub fn default_width(mut self, default_width: f32) -> Self { pub fn default_width(mut self, default_width: f32) -> Self {
self.default_width = default_width; self.default_width = default_width;
@ -202,6 +212,7 @@ impl SidePanel {
id, id,
frame, frame,
resizable, resizable,
show_separator_line,
default_width, default_width,
width_range, width_range,
} = self; } = self;
@ -288,9 +299,11 @@ impl SidePanel {
ui.style().visuals.widgets.active.bg_stroke ui.style().visuals.widgets.active.bg_stroke
} else if resize_hover { } else if resize_hover {
ui.style().visuals.widgets.hovered.bg_stroke ui.style().visuals.widgets.hovered.bg_stroke
} else { } else if show_separator_line {
// TOOD(emilk): distinguish resizable from non-resizable // TOOD(emilk): distinguish resizable from non-resizable
ui.style().visuals.widgets.noninteractive.bg_stroke ui.style().visuals.widgets.noninteractive.bg_stroke
} else {
Stroke::none()
}; };
// TODO(emilk): draw line on top of all panels in this ui when https://github.com/emilk/egui/issues/1516 is done // TODO(emilk): draw line on top of all panels in this ui when https://github.com/emilk/egui/issues/1516 is done
let resize_x = side.opposite().side_x(rect); let resize_x = side.opposite().side_x(rect);
@ -525,6 +538,7 @@ pub struct TopBottomPanel {
id: Id, id: Id,
frame: Option<Frame>, frame: Option<Frame>,
resizable: bool, resizable: bool,
show_separator_line: bool,
default_height: Option<f32>, default_height: Option<f32>,
height_range: RangeInclusive<f32>, height_range: RangeInclusive<f32>,
} }
@ -547,6 +561,7 @@ impl TopBottomPanel {
id: id.into(), id: id.into(),
frame: None, frame: None,
resizable: false, resizable: false,
show_separator_line: true,
default_height: None, default_height: None,
height_range: 20.0..=f32::INFINITY, height_range: 20.0..=f32::INFINITY,
} }
@ -568,6 +583,14 @@ impl TopBottomPanel {
self self
} }
/// Show a separator line, even when not interacting with it?
///
/// Default: `true`.
pub fn show_separator_line(mut self, show_separator_line: bool) -> Self {
self.show_separator_line = show_separator_line;
self
}
/// The initial height of the [`SidePanel`]. /// The initial height of the [`SidePanel`].
/// Defaults to [`style::Spacing::interact_size`].y. /// Defaults to [`style::Spacing::interact_size`].y.
pub fn default_height(mut self, default_height: f32) -> Self { pub fn default_height(mut self, default_height: f32) -> Self {
@ -633,6 +656,7 @@ impl TopBottomPanel {
id, id,
frame, frame,
resizable, resizable,
show_separator_line,
default_height, default_height,
height_range, height_range,
} = self; } = self;
@ -724,9 +748,11 @@ impl TopBottomPanel {
ui.style().visuals.widgets.active.bg_stroke ui.style().visuals.widgets.active.bg_stroke
} else if resize_hover { } else if resize_hover {
ui.style().visuals.widgets.hovered.bg_stroke ui.style().visuals.widgets.hovered.bg_stroke
} else { } else if show_separator_line {
// TOOD(emilk): distinguish resizable from non-resizable // TOOD(emilk): distinguish resizable from non-resizable
ui.style().visuals.widgets.noninteractive.bg_stroke ui.style().visuals.widgets.noninteractive.bg_stroke
} else {
Stroke::none()
}; };
// TODO(emilk): draw line on top of all panels in this ui when https://github.com/emilk/egui/issues/1516 is done // TODO(emilk): draw line on top of all panels in this ui when https://github.com/emilk/egui/issues/1516 is done
let resize_y = side.opposite().side_y(rect); let resize_y = side.opposite().side_y(rect);