diff --git a/egui_node_graph2/Cargo.toml b/egui_node_graph2/Cargo.toml index fe81c2b..a9be9bc 100644 --- a/egui_node_graph2/Cargo.toml +++ b/egui_node_graph2/Cargo.toml @@ -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"] } diff --git a/egui_node_graph2/src/editor_ui.rs b/egui_node_graph2/src/editor_ui.rs index 9c3323b..9c2aa25 100644 --- a/egui_node_graph2/src/editor_ui.rs +++ b/egui_node_graph2/src/editor_ui.rs @@ -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 @@ -498,6 +498,7 @@ where 2.0, bg_color, Stroke::new(3.0, stroke_color), + StrokeKind::Outside, ); self.selected_nodes = node_rects @@ -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; @@ -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, }; @@ -617,11 +618,14 @@ where ui: &mut Ui, user_state: &mut UserState, ) -> Vec> { - 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) @@ -635,7 +639,7 @@ where ui: &mut Ui, user_state: &mut UserState, ) -> Vec> { - 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::>::new(); let background_color; @@ -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 @@ -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(), @@ -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; @@ -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, @@ -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 }; diff --git a/egui_node_graph2/src/graph_impls.rs b/egui_node_graph2/src/graph_impls.rs index a117b95..9ab0e3e 100644 --- a/egui_node_graph2/src/graph_impls.rs +++ b/egui_node_graph2/src/graph_impls.rs @@ -241,14 +241,14 @@ impl Node { pub fn inputs<'a, DataType, DataValue>( &'a self, graph: &'a Graph, - ) -> impl Iterator> + 'a { + ) -> impl Iterator> + 'a { self.input_ids().map(|id| graph.get_input(id)) } pub fn outputs<'a, DataType, DataValue>( &'a self, graph: &'a Graph, - ) -> impl Iterator> + 'a { + ) -> impl Iterator> + 'a { self.output_ids().map(|id| graph.get_output(id)) } diff --git a/egui_node_graph2/src/node_finder.rs b/egui_node_graph2/src/node_finder.rs index c0a6b2f..332f355 100644 --- a/egui_node_graph2/src/node_finder.rs +++ b/egui_node_graph2/src/node_finder.rs @@ -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(); diff --git a/egui_node_graph2/src/scale.rs b/egui_node_graph2/src/scale.rs index 2f4120d..87f9d7b 100644 --- a/egui_node_graph2/src/scale.rs +++ b/egui_node_graph2/src/scale.rs @@ -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 @@ -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; } } @@ -49,7 +65,7 @@ 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; } } @@ -57,7 +73,7 @@ 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.); } } @@ -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); } diff --git a/egui_node_graph2/src/traits.rs b/egui_node_graph2/src/traits.rs index 694c090..6a29e1e 100644 --- a/egui_node_graph2/src/traits.rs +++ b/egui_node_graph2/src/traits.rs @@ -84,7 +84,7 @@ pub trait DataTypeTrait: PartialEq + Eq { /// } /// } /// ``` - fn name(&self) -> std::borrow::Cow; + fn name(&'_ self) -> std::borrow::Cow<'_, str>; } /// This trait must be implemented for the `NodeData` generic parameter of the @@ -251,7 +251,7 @@ pub trait NodeTemplateTrait: Clone { /// The return type is Cow 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; + fn node_finder_label(&'_ self, user_state: &mut Self::UserState) -> std::borrow::Cow<'_, str>; /// Vec of categories to which the node belongs. /// diff --git a/egui_node_graph2_example/Cargo.toml b/egui_node_graph2_example/Cargo.toml index 5d0c83d..d5b4f7d 100644 --- a/egui_node_graph2_example/Cargo.toml +++ b/egui_node_graph2_example/Cargo.toml @@ -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 } diff --git a/egui_node_graph2_example/src/app.rs b/egui_node_graph2_example/src/app.rs index e5daf74..40e4ca0 100644 --- a/egui_node_graph2_example/src/app.rs +++ b/egui_node_graph2_example/src/app.rs @@ -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()