Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion egui_node_graph2/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ workspace = ".."
persistence = ["serde", "slotmap/serde", "smallvec/serde", "egui/persistence"]

[dependencies]
egui = "0.30"
egui = "0.33"
slotmap = { version = "1.0" }
smallvec = { version = "1.10.0" }
serde = { version = "1.0", optional = true, features = ["derive"] }
Expand Down
98 changes: 43 additions & 55 deletions egui_node_graph2/src/editor_ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ pub struct GraphNodeWidget<'a, NodeData, DataType, ValueType> {
pub node_id: NodeId,
pub ongoing_drag: Option<(NodeId, AnyParameterId)>,
pub selected: bool,
pub pan: egui::Vec2,
pub pan: Vec2,
}

impl<NodeData, DataType, ValueType, NodeTemplate, UserResponse, UserState, CategoryType>
Expand Down Expand Up @@ -498,6 +498,7 @@ where
2.0,
bg_color,
Stroke::new(3.0, stroke_color),
StrokeKind::Outside,
);

self.selected_nodes = node_rects
Expand Down Expand Up @@ -542,7 +543,7 @@ where
}

// Deselect and deactivate finder if the editor background is clicked,
// *or* if the the mouse clicks off the ui
// *or* if the mouse clicks off the ui
if click_on_background || (mouse.any_click() && !cursor_in_editor) {
self.selected_nodes = Vec::new();
self.node_finder = None;
Expand Down Expand Up @@ -573,7 +574,7 @@ fn draw_connection(
dst_pos: Pos2,
color: Color32,
) {
let connection_stroke = egui::Stroke {
let connection_stroke = Stroke {
width: 5.0 * pan_zoom.zoom,
color,
};
Expand Down Expand Up @@ -617,11 +618,14 @@ where
ui: &mut Ui,
user_state: &mut UserState,
) -> Vec<NodeResponse<UserResponse, NodeData>> {
let mut child_ui = ui.child_ui_with_id_source(
Rect::from_min_size(*self.position + self.pan, Self::MAX_NODE_SIZE.into()),
Layout::default(),
self.node_id,
None,
let mut child_ui = ui.new_child(
UiBuilder::new()
.layout(Default::default())
.max_rect(Rect::from_min_size(
*self.position + self.pan,
Self::MAX_NODE_SIZE.into(),
))
.id_salt(self.node_id),
);

Self::show_graph_node(self, pan_zoom, &mut child_ui, user_state)
Expand All @@ -635,7 +639,7 @@ where
ui: &mut Ui,
user_state: &mut UserState,
) -> Vec<NodeResponse<UserResponse, NodeData>> {
let margin = egui::vec2(15.0, 5.0) * pan_zoom.zoom;
let margin = vec2(15.0, 5.0) * pan_zoom.zoom;
let mut responses = Vec::<NodeResponse<UserResponse, NodeData>>::new();

let background_color;
Expand Down Expand Up @@ -666,7 +670,7 @@ where
inner_rect.max.x = inner_rect.max.x.max(inner_rect.min.x);
inner_rect.max.y = inner_rect.max.y.max(inner_rect.min.y);

let mut child_ui = ui.child_ui(inner_rect, *ui.layout(), None);
let mut child_ui = ui.new_child(UiBuilder::new().max_rect(inner_rect).layout(*ui.layout()));

// Get interaction rect from memory, it may expand after the window response on resize.
let interaction_rect = ui
Expand Down Expand Up @@ -756,8 +760,7 @@ where
let max_connections = self.graph[param_id]
.max_connections
.map(NonZeroU32::get)
.unwrap_or(std::u32::MAX)
as usize;
.unwrap_or(u32::MAX) as usize;
let port_height = port_height(
max_connections != 1,
self.graph.connections(param_id).len(),
Expand Down Expand Up @@ -863,8 +866,7 @@ where

let port_rect = Rect::from_center_size(
port_pos,
egui::vec2(10.0, port_height(wide_port, connections, max_connections))
* pan_zoom.zoom,
vec2(10.0, port_height(wide_port, connections, max_connections)) * pan_zoom.zoom,
);

let port_full = connections == max_connections;
Expand Down Expand Up @@ -1014,7 +1016,7 @@ where
let max_connections = self.graph[*param]
.max_connections
.map(NonZeroU32::get)
.unwrap_or(std::u32::MAX) as usize;
.unwrap_or(u32::MAX) as usize;
draw_port(
pan_zoom,
ui,
Expand Down Expand Up @@ -1065,63 +1067,49 @@ where

let (shape, outline) = {
let rounding_radius = 4.0 * pan_zoom.zoom;
let rounding = Rounding::same(rounding_radius);
let rounding = CornerRadius::from(rounding_radius);

let titlebar_height = title_height + margin.y;
let titlebar_rect =
Rect::from_min_size(outer_rect.min, vec2(outer_rect.width(), titlebar_height));
let titlebar = Shape::Rect(RectShape {
rect: titlebar_rect,
rounding,
fill: self.graph[self.node_id]
.user_data
.titlebar_color(ui, self.node_id, self.graph, user_state)
.unwrap_or_else(|| background_color.lighten(0.8)),
stroke: Stroke::NONE,
blur_width: 0.0,
fill_texture_id: Default::default(),
uv: Rect::ZERO,
});
let title_bar_color = self.graph[self.node_id]
.user_data
.titlebar_color(ui, self.node_id, self.graph, user_state)
.unwrap_or_else(|| background_color.lighten(0.8));

let titlebar = Shape::Rect(
RectShape::filled(titlebar_rect, rounding, title_bar_color)
.with_texture(Default::default(), Rect::ZERO),
);

let body_rect = Rect::from_min_size(
outer_rect.min + vec2(0.0, titlebar_height - rounding_radius),
vec2(outer_rect.width(), outer_rect.height() - titlebar_height),
);
let body = Shape::Rect(RectShape {
rect: body_rect,
rounding: Rounding::ZERO,
fill: background_color,
stroke: Stroke::NONE,
blur_width: 0.0,
fill_texture_id: Default::default(),
uv: Rect::ZERO,
});
let body = Shape::Rect(
RectShape::filled(body_rect, CornerRadius::ZERO, background_color)
.with_texture(Default::default(), Rect::ZERO),
);

let bottom_body_rect = Rect::from_min_size(
body_rect.min + vec2(0.0, body_rect.height() - titlebar_height * 0.5),
vec2(outer_rect.width(), titlebar_height),
);
let bottom_body = Shape::Rect(RectShape {
rect: bottom_body_rect,
rounding,
fill: background_color,
stroke: Stroke::NONE,
blur_width: 0.0,
fill_texture_id: Default::default(),
uv: Rect::ZERO,
});
let bottom_body = Shape::Rect(
RectShape::filled(bottom_body_rect, rounding, background_color)
.with_texture(Default::default(), Rect::ZERO),
);

let node_rect = titlebar_rect.union(body_rect).union(bottom_body_rect);
let outline = if self.selected {
Shape::Rect(RectShape {
rect: node_rect.expand(1.0 * pan_zoom.zoom),
rounding,
fill: Color32::WHITE.lighten(0.8),
stroke: Stroke::NONE,
blur_width: 0.0,
fill_texture_id: Default::default(),
uv: Rect::ZERO,
})
Shape::Rect(
RectShape::filled(
node_rect.expand(1.0 * pan_zoom.zoom),
rounding,
Color32::WHITE.lighten(0.8),
)
.with_texture(Default::default(), Rect::ZERO),
)
} else {
Shape::Noop
};
Expand Down
4 changes: 2 additions & 2 deletions egui_node_graph2/src/graph_impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -241,14 +241,14 @@ impl<NodeData> Node<NodeData> {
pub fn inputs<'a, DataType, DataValue>(
&'a self,
graph: &'a Graph<NodeData, DataType, DataValue>,
) -> impl Iterator<Item = &InputParam<DataType, DataValue>> + 'a {
) -> impl Iterator<Item = &'a InputParam<DataType, DataValue>> + 'a {
self.input_ids().map(|id| graph.get_input(id))
}

pub fn outputs<'a, DataType, DataValue>(
&'a self,
graph: &'a Graph<NodeData, DataType, DataValue>,
) -> impl Iterator<Item = &OutputParam<DataType>> + 'a {
) -> impl Iterator<Item = &'a OutputParam<DataType>> + 'a {
self.output_ids().map(|id| graph.get_output(id))
}

Expand Down
2 changes: 1 addition & 1 deletion egui_node_graph2/src/node_finder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ where

let mut query_submit = resp.lost_focus() && ui.input(|i| i.key_pressed(Key::Enter));

let max_height = ui.input(|i| i.screen_rect.height() * 0.5);
let max_height = ui.input(|i| i.content_rect().height() * 0.5);
let scroll_area_width = resp.rect.width() - 30.0;

let all_kinds = all_kinds.all_kinds();
Expand Down
42 changes: 29 additions & 13 deletions egui_node_graph2/src/scale.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use egui::epaint::Shadow;
use egui::{style::WidgetVisuals, Margin, Rounding, Stroke, Style, Vec2};
use egui::{style::WidgetVisuals, CornerRadius, Margin, Stroke, Style, Vec2};

// Copied from https://github.com/gzp-crey/shine

Expand All @@ -25,19 +25,35 @@ impl Scale for Vec2 {

impl Scale for Margin {
fn scale(&mut self, amount: f32) {
self.left *= amount;
self.right *= amount;
self.top *= amount;
self.bottom *= amount;
self.left = (self.left as f32 * amount)
.round()
.clamp(i8::MIN as f32, i8::MAX as f32) as i8;
self.right = (self.right as f32 * amount)
.round()
.clamp(i8::MIN as f32, i8::MAX as f32) as i8;
self.top = (self.top as f32 * amount)
.round()
.clamp(i8::MIN as f32, i8::MAX as f32) as i8;
self.bottom = (self.bottom as f32 * amount)
.round()
.clamp(i8::MIN as f32, i8::MAX as f32) as i8;
}
}

impl Scale for Rounding {
impl Scale for CornerRadius {
fn scale(&mut self, amount: f32) {
self.ne *= amount;
self.nw *= amount;
self.se *= amount;
self.sw *= amount;
self.ne = (self.ne as f32 * amount)
.round()
.clamp(0f32, u8::MAX as f32) as u8;
self.nw = (self.nw as f32 * amount)
.round()
.clamp(0f32, u8::MAX as f32) as u8;
self.se = (self.se as f32 * amount)
.round()
.clamp(0f32, u8::MAX as f32) as u8;
self.sw = (self.sw as f32 * amount)
.round()
.clamp(0f32, u8::MAX as f32) as u8;
}
}

Expand All @@ -49,15 +65,15 @@ impl Scale for Stroke {

impl Scale for Shadow {
fn scale(&mut self, amount: f32) {
self.spread *= amount.clamp(0.4, 1.);
self.spread = (self.spread as f32 * amount.clamp(0.4, 1.)) as u8;
}
}

impl Scale for WidgetVisuals {
fn scale(&mut self, amount: f32) {
self.bg_stroke.scale(amount);
self.fg_stroke.scale(amount);
self.rounding.scale(amount);
self.corner_radius.scale(amount);
self.expansion *= amount.clamp(0.4, 1.);
}
}
Expand Down Expand Up @@ -102,7 +118,7 @@ impl Scale for Style {
self.visuals.resize_corner_size *= amount;
self.visuals.text_cursor.stroke.width *= amount;
self.visuals.clip_rect_margin *= amount;
self.visuals.window_rounding.scale(amount);
self.visuals.window_corner_radius.scale(amount);
self.visuals.window_shadow.scale(amount);
self.visuals.popup_shadow.scale(amount);
}
Expand Down
4 changes: 2 additions & 2 deletions egui_node_graph2/src/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ pub trait DataTypeTrait<UserState>: PartialEq + Eq {
/// }
/// }
/// ```
fn name(&self) -> std::borrow::Cow<str>;
fn name(&'_ self) -> std::borrow::Cow<'_, str>;
}

/// This trait must be implemented for the `NodeData` generic parameter of the
Expand Down Expand Up @@ -251,7 +251,7 @@ pub trait NodeTemplateTrait: Clone {
/// The return type is Cow<str> to allow returning owned or borrowed values
/// more flexibly. Refer to the documentation for `DataTypeTrait::name` for
/// more information
fn node_finder_label(&self, user_state: &mut Self::UserState) -> std::borrow::Cow<str>;
fn node_finder_label(&'_ self, user_state: &mut Self::UserState) -> std::borrow::Cow<'_, str>;

/// Vec of categories to which the node belongs.
///
Expand Down
2 changes: 1 addition & 1 deletion egui_node_graph2_example/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ rust-version = "1.56"
crate-type = ["cdylib", "rlib"]

[dependencies]
eframe = "0.30"
eframe = "0.33"
egui_node_graph2 = { path = "../egui_node_graph2" }
anyhow = "1.0"
serde = { version = "1.0", optional = true }
Expand Down
4 changes: 2 additions & 2 deletions egui_node_graph2_example/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -411,8 +411,8 @@ impl eframe::App for NodeGraphExample {
/// Put your widgets into a `SidePanel`, `TopPanel`, `CentralPanel`, `Window` or `Area`.
fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) {
egui::TopBottomPanel::top("top").show(ctx, |ui| {
egui::menu::bar(ui, |ui| {
egui::widgets::global_dark_light_mode_switch(ui);
egui::MenuBar::new().ui(ui, |ui| {
egui::widgets::global_theme_preference_switch(ui);
});
});
let graph_response = egui::CentralPanel::default()
Expand Down