#[derive(Debug, Clone)]
pub struct SettingsInteraction {
pub(crate) dragging_enabled: bool,
pub(crate) hover_enabled: bool,
pub(crate) node_clicking_enabled: bool,
pub(crate) node_selection_enabled: bool,
pub(crate) node_selection_multi_enabled: bool,
pub(crate) edge_clicking_enabled: bool,
pub(crate) edge_selection_enabled: bool,
pub(crate) edge_selection_multi_enabled: bool,
}
impl Default for SettingsInteraction {
fn default() -> Self {
Self {
dragging_enabled: true,
hover_enabled: true,
node_clicking_enabled: false,
node_selection_enabled: false,
node_selection_multi_enabled: false,
edge_clicking_enabled: false,
edge_selection_enabled: false,
edge_selection_multi_enabled: false,
}
}
}
impl SettingsInteraction {
pub fn new() -> Self {
Self::default()
}
pub fn with_dragging_enabled(mut self, enabled: bool) -> Self {
self.dragging_enabled = enabled;
self
}
pub fn with_hover_enabled(mut self, enabled: bool) -> Self {
self.hover_enabled = enabled;
self
}
pub fn with_node_clicking_enabled(mut self, enabled: bool) -> Self {
self.node_clicking_enabled = enabled;
self
}
pub fn with_node_selection_enabled(mut self, enabled: bool) -> Self {
self.node_selection_enabled = enabled;
self
}
pub fn with_node_selection_multi_enabled(mut self, enabled: bool) -> Self {
self.node_selection_multi_enabled = enabled;
self
}
pub fn with_edge_clicking_enabled(mut self, enabled: bool) -> Self {
self.edge_clicking_enabled = enabled;
self
}
pub fn with_edge_selection_enabled(mut self, enabled: bool) -> Self {
self.edge_selection_enabled = enabled;
self
}
pub fn with_edge_selection_multi_enabled(mut self, enabled: bool) -> Self {
self.edge_selection_multi_enabled = enabled;
self
}
}
#[derive(Debug, Clone)]
pub struct SettingsNavigation {
pub(crate) fit_to_screen_enabled: bool,
pub(crate) zoom_and_pan_enabled: bool,
pub(crate) fit_to_screen_padding: f32,
pub(crate) zoom_speed: f32,
}
impl Default for SettingsNavigation {
fn default() -> Self {
Self {
fit_to_screen_padding: 0.1,
zoom_speed: 0.1,
fit_to_screen_enabled: true,
zoom_and_pan_enabled: false,
}
}
}
impl SettingsNavigation {
pub fn new() -> Self {
Self::default()
}
pub fn with_fit_to_screen_enabled(mut self, enabled: bool) -> Self {
self.fit_to_screen_enabled = enabled;
self
}
pub fn with_zoom_and_pan_enabled(mut self, enabled: bool) -> Self {
self.zoom_and_pan_enabled = enabled;
self
}
pub fn with_fit_to_screen_padding(mut self, padding: f32) -> Self {
self.fit_to_screen_padding = padding;
self
}
pub fn with_zoom_speed(mut self, speed: f32) -> Self {
self.zoom_speed = speed;
self
}
}
#[derive(Clone, Default)]
pub struct SettingsStyle {
pub(crate) labels_always: bool,
pub(crate) node_stroke_hook: Option<NodeStrokeHook>,
pub(crate) edge_stroke_hook: Option<EdgeStrokeHook>,
}
impl core::fmt::Debug for SettingsStyle {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
f.debug_struct("SettingsStyle")
.field("labels_always", &self.labels_always)
.field(
"node_stroke_hook",
&self.node_stroke_hook.as_ref().map(|_| "<hook>"),
)
.field(
"edge_stroke_hook",
&self.edge_stroke_hook.as_ref().map(|_| "<hook>"),
)
.finish()
}
}
impl SettingsStyle {
pub fn new() -> Self {
Self::default()
}
pub fn with_labels_always(mut self, always: bool) -> Self {
self.labels_always = always;
self
}
pub fn with_node_stroke_hook<F>(mut self, f: F) -> Self
where
F: Fn(bool, bool, Option<egui::Color32>, egui::Stroke, &egui::Style) -> egui::Stroke
+ Send
+ Sync
+ 'static,
{
self.node_stroke_hook = Some(std::sync::Arc::new(f));
self
}
pub fn with_edge_stroke_hook<F>(mut self, f: F) -> Self
where
F: Fn(bool, usize, egui::Stroke, &egui::Style) -> egui::Stroke + Send + Sync + 'static,
{
self.edge_stroke_hook = Some(std::sync::Arc::new(f));
self
}
}
pub type NodeStrokeHook = std::sync::Arc<
dyn Fn(bool, bool, Option<egui::Color32>, egui::Stroke, &egui::Style) -> egui::Stroke
+ Send
+ Sync,
>;
pub type EdgeStrokeHook =
std::sync::Arc<dyn Fn(bool, usize, egui::Stroke, &egui::Style) -> egui::Stroke + Send + Sync>;