mirror of
https://github.com/emilk/egui.git
synced 2026-09-01 14:20:04 -04:00
Allow cursors to be linked for plots (#1722)
* Allow cursors to be linked * Link cursors in demo * Refactor cursor memory to deal with removal of plots * Refactor PlotItem::on_hover to produce a list of cursors * Use a separate `LinkedCursorsGroup` type to link cursors. * Refactor `Cursor`. * Inline `push_argument_ruler` and `push_value_ruler`. * Update documentation * Update doc reference
This commit is contained in:
@@ -459,16 +459,24 @@ struct LinkedAxisDemo {
|
||||
link_x: bool,
|
||||
link_y: bool,
|
||||
group: plot::LinkedAxisGroup,
|
||||
cursor_group: plot::LinkedCursorsGroup,
|
||||
link_cursor_x: bool,
|
||||
link_cursor_y: bool,
|
||||
}
|
||||
|
||||
impl Default for LinkedAxisDemo {
|
||||
fn default() -> Self {
|
||||
let link_x = true;
|
||||
let link_y = false;
|
||||
let link_cursor_x = true;
|
||||
let link_cursor_y = false;
|
||||
Self {
|
||||
link_x,
|
||||
link_y,
|
||||
group: plot::LinkedAxisGroup::new(link_x, link_y),
|
||||
cursor_group: plot::LinkedCursorsGroup::new(link_cursor_x, link_cursor_y),
|
||||
link_cursor_x,
|
||||
link_cursor_y,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -514,18 +522,27 @@ impl LinkedAxisDemo {
|
||||
});
|
||||
self.group.set_link_x(self.link_x);
|
||||
self.group.set_link_y(self.link_y);
|
||||
ui.horizontal(|ui| {
|
||||
ui.label("Linked cursors:");
|
||||
ui.checkbox(&mut self.link_cursor_x, "X");
|
||||
ui.checkbox(&mut self.link_cursor_y, "Y");
|
||||
});
|
||||
self.cursor_group.set_link_x(self.link_cursor_x);
|
||||
self.cursor_group.set_link_y(self.link_cursor_y);
|
||||
ui.horizontal(|ui| {
|
||||
Plot::new("linked_axis_1")
|
||||
.data_aspect(1.0)
|
||||
.width(250.0)
|
||||
.height(250.0)
|
||||
.link_axis(self.group.clone())
|
||||
.link_cursor(self.cursor_group.clone())
|
||||
.show(ui, LinkedAxisDemo::configure_plot);
|
||||
Plot::new("linked_axis_2")
|
||||
.data_aspect(2.0)
|
||||
.width(150.0)
|
||||
.height(250.0)
|
||||
.link_axis(self.group.clone())
|
||||
.link_cursor(self.cursor_group.clone())
|
||||
.show(ui, LinkedAxisDemo::configure_plot);
|
||||
});
|
||||
Plot::new("linked_axis_3")
|
||||
@@ -533,6 +550,7 @@ impl LinkedAxisDemo {
|
||||
.width(250.0)
|
||||
.height(150.0)
|
||||
.link_axis(self.group.clone())
|
||||
.link_cursor(self.cursor_group.clone())
|
||||
.show(ui, LinkedAxisDemo::configure_plot)
|
||||
.response
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user