mod connections;
mod response;
mod show;
pub mod stages;
mod state;
use egui::Id;
use crate::{
misc::viewport::ViewportSize,
viewport::{CanvasPos, Grid, Viewport},
Pos, RenderedSocket,
};
pub use connections::ConnectionsUi;
pub use response::GraphResponse;
pub use show::{GraphUi, NodeResponse, NodeUi};
use state::EditorState;
pub struct GraphEditor<Stage> {
id: Id,
stage: Stage,
}
impl GraphEditor<stages::Settings> {
#[inline]
pub fn new(id_salt: impl core::hash::Hash) -> Self {
Self {
id: Id::new(id_salt),
stage: stages::Settings {
show_grid: false,
look_at: None,
can_connect_socket: true,
viewport: ViewportSize::default(),
},
}
}
#[inline]
#[must_use]
pub fn look_at(mut self, pos: Pos) -> Self {
self.stage.look_at = Some(pos);
self
}
#[inline]
#[must_use]
pub fn show_grid(mut self, show_grid: bool) -> Self {
self.stage.show_grid = show_grid;
self
}
#[inline]
#[must_use]
pub fn can_connect_socket(mut self, can_connect_socket: bool) -> Self {
self.stage.can_connect_socket = can_connect_socket;
self
}
#[inline]
#[must_use]
pub fn view_aspect(mut self, view_aspect: f32) -> Self {
self.stage.viewport = self.stage.viewport.view_aspect(view_aspect);
self
}
#[inline]
#[must_use]
pub fn width(mut self, width: f32) -> Self {
self.stage.viewport = self.stage.viewport.width(width);
self
}
#[inline]
#[must_use]
pub fn height(mut self, height: f32) -> Self {
self.stage.viewport = self.stage.viewport.height(height);
self
}
}