mirror of
https://github.com/eliasstepanik/egui_node_graph.git
synced 2026-01-11 22:08:28 +00:00
Merge latest main. Resolve conflicts and apply thread suggestions
This commit is contained in:
commit
568a5aeb82
@ -15,7 +15,7 @@ workspace = ".."
|
|||||||
persistence = ["serde", "slotmap/serde", "smallvec/serde", "egui/persistence"]
|
persistence = ["serde", "slotmap/serde", "smallvec/serde", "egui/persistence"]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
egui = { version = "0.16" }
|
egui = { version = "0.18" }
|
||||||
slotmap = { version = "1.0" }
|
slotmap = { version = "1.0" }
|
||||||
smallvec = { version = "1.7.0" }
|
smallvec = { version = "1.7.0" }
|
||||||
serde = { version = "1.0", optional = true, features = ["derive"] }
|
serde = { version = "1.0", optional = true, features = ["derive"] }
|
||||||
|
|||||||
@ -60,7 +60,6 @@ where
|
|||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn draw_graph_editor(
|
pub fn draw_graph_editor(
|
||||||
&mut self,
|
&mut self,
|
||||||
ctx: &CtxRef,
|
|
||||||
ui: &mut Ui,
|
ui: &mut Ui,
|
||||||
all_kinds: impl NodeTemplateIter<Item = NodeTemplate>,
|
all_kinds: impl NodeTemplateIter<Item = NodeTemplate>,
|
||||||
) -> GraphResponse<UserResponse> {
|
) -> GraphResponse<UserResponse> {
|
||||||
@ -70,8 +69,7 @@ where
|
|||||||
let editor_rect = ui.max_rect();
|
let editor_rect = ui.max_rect();
|
||||||
ui.allocate_rect(editor_rect, Sense::hover());
|
ui.allocate_rect(editor_rect, Sense::hover());
|
||||||
|
|
||||||
let mouse = &ctx.input().pointer;
|
let cursor_pos = ui.ctx().input().pointer.hover_pos().unwrap_or(Pos2::ZERO);
|
||||||
let cursor_pos = mouse.hover_pos().unwrap_or(Pos2::ZERO);
|
|
||||||
let mut cursor_in_editor = editor_rect.contains(cursor_pos);
|
let mut cursor_in_editor = editor_rect.contains(cursor_pos);
|
||||||
|
|
||||||
// Gets filled with the port locations as nodes are drawn
|
// Gets filled with the port locations as nodes are drawn
|
||||||
@ -123,7 +121,7 @@ where
|
|||||||
if let Some(pos) = node_finder.position {
|
if let Some(pos) = node_finder.position {
|
||||||
node_finder_area = node_finder_area.current_pos(pos);
|
node_finder_area = node_finder_area.current_pos(pos);
|
||||||
}
|
}
|
||||||
node_finder_area.show(ctx, |ui| {
|
node_finder_area.show(ui.ctx(), |ui| {
|
||||||
if let Some(node_kind) = node_finder.show(ui, all_kinds) {
|
if let Some(node_kind) = node_finder.show(ui, all_kinds) {
|
||||||
let new_node = self.graph.add_node(
|
let new_node = self.graph.add_node(
|
||||||
node_kind.node_graph_label(),
|
node_kind.node_graph_label(),
|
||||||
@ -236,6 +234,9 @@ where
|
|||||||
|
|
||||||
/* Mouse input handling */
|
/* Mouse input handling */
|
||||||
|
|
||||||
|
// This locks the context, so don't hold on to it for too long.
|
||||||
|
let mouse = &ui.ctx().input().pointer;
|
||||||
|
|
||||||
if mouse.any_released() && self.connection_in_progress.is_some() {
|
if mouse.any_released() && self.connection_in_progress.is_some() {
|
||||||
self.connection_in_progress = None;
|
self.connection_in_progress = None;
|
||||||
}
|
}
|
||||||
@ -243,12 +244,12 @@ where
|
|||||||
if mouse.button_down(PointerButton::Secondary) && cursor_in_editor{
|
if mouse.button_down(PointerButton::Secondary) && cursor_in_editor{
|
||||||
self.node_finder = Some(NodeFinder::new_at(cursor_pos));
|
self.node_finder = Some(NodeFinder::new_at(cursor_pos));
|
||||||
}
|
}
|
||||||
if ctx.input().key_pressed(Key::Escape) {
|
if ui.ctx().input().key_pressed(Key::Escape) {
|
||||||
self.node_finder = None;
|
self.node_finder = None;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ctx.input().pointer.middle_down() {
|
if ui.ctx().input().pointer.middle_down() {
|
||||||
self.pan_zoom.pan += ctx.input().pointer.delta();
|
self.pan_zoom.pan += ui.ctx().input().pointer.delta();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Deselect and deactivate finder if the editor backround is clicked,
|
// Deselect and deactivate finder if the editor backround is clicked,
|
||||||
@ -481,25 +482,26 @@ where
|
|||||||
// does not support drawing rectangles with asymmetrical round corners.
|
// does not support drawing rectangles with asymmetrical round corners.
|
||||||
|
|
||||||
let (shape, outline) = {
|
let (shape, outline) = {
|
||||||
let corner_radius = 4.0;
|
let rounding_radius = 4.0;
|
||||||
|
let rounding = Rounding::same(rounding_radius);
|
||||||
|
|
||||||
let titlebar_height = title_height + margin.y;
|
let titlebar_height = title_height + margin.y;
|
||||||
let titlebar_rect =
|
let titlebar_rect =
|
||||||
Rect::from_min_size(outer_rect.min, vec2(outer_rect.width(), titlebar_height));
|
Rect::from_min_size(outer_rect.min, vec2(outer_rect.width(), titlebar_height));
|
||||||
let titlebar = Shape::Rect(RectShape {
|
let titlebar = Shape::Rect(RectShape {
|
||||||
rect: titlebar_rect,
|
rect: titlebar_rect,
|
||||||
corner_radius,
|
rounding,
|
||||||
fill: titlebar_color,
|
fill: titlebar_color,
|
||||||
stroke: Stroke::none(),
|
stroke: Stroke::none(),
|
||||||
});
|
});
|
||||||
|
|
||||||
let body_rect = Rect::from_min_size(
|
let body_rect = Rect::from_min_size(
|
||||||
outer_rect.min + vec2(0.0, titlebar_height - corner_radius),
|
outer_rect.min + vec2(0.0, titlebar_height - rounding_radius),
|
||||||
vec2(outer_rect.width(), outer_rect.height() - titlebar_height),
|
vec2(outer_rect.width(), outer_rect.height() - titlebar_height),
|
||||||
);
|
);
|
||||||
let body = Shape::Rect(RectShape {
|
let body = Shape::Rect(RectShape {
|
||||||
rect: body_rect,
|
rect: body_rect,
|
||||||
corner_radius: 0.0,
|
rounding: Rounding::none(),
|
||||||
fill: background_color,
|
fill: background_color,
|
||||||
stroke: Stroke::none(),
|
stroke: Stroke::none(),
|
||||||
});
|
});
|
||||||
@ -510,7 +512,7 @@ where
|
|||||||
);
|
);
|
||||||
let bottom_body = Shape::Rect(RectShape {
|
let bottom_body = Shape::Rect(RectShape {
|
||||||
rect: bottom_body_rect,
|
rect: bottom_body_rect,
|
||||||
corner_radius,
|
rounding,
|
||||||
fill: background_color,
|
fill: background_color,
|
||||||
stroke: Stroke::none(),
|
stroke: Stroke::none(),
|
||||||
});
|
});
|
||||||
@ -521,7 +523,7 @@ where
|
|||||||
.union(body_rect)
|
.union(body_rect)
|
||||||
.union(bottom_body_rect)
|
.union(bottom_body_rect)
|
||||||
.expand(1.0),
|
.expand(1.0),
|
||||||
corner_radius: 4.0,
|
rounding,
|
||||||
fill: Color32::WHITE.lighten(0.8),
|
fill: Color32::WHITE.lighten(0.8),
|
||||||
stroke: Stroke::none(),
|
stroke: Stroke::none(),
|
||||||
})
|
})
|
||||||
|
|||||||
@ -41,7 +41,7 @@ where
|
|||||||
|
|
||||||
let frame = Frame::dark_canvas(ui.style())
|
let frame = Frame::dark_canvas(ui.style())
|
||||||
.fill(background_color)
|
.fill(background_color)
|
||||||
.margin(vec2(5.0, 5.0));
|
.inner_margin(vec2(5.0, 5.0));
|
||||||
|
|
||||||
// The archetype that will be returned.
|
// The archetype that will be returned.
|
||||||
let mut submitted_archetype = None;
|
let mut submitted_archetype = None;
|
||||||
@ -55,19 +55,21 @@ where
|
|||||||
|
|
||||||
let mut query_submit = resp.lost_focus() && ui.input().key_down(Key::Enter);
|
let mut query_submit = resp.lost_focus() && ui.input().key_down(Key::Enter);
|
||||||
|
|
||||||
Frame::default().margin(vec2(10.0, 10.0)).show(ui, |ui| {
|
Frame::default()
|
||||||
for kind in all_kinds.all_kinds() {
|
.inner_margin(vec2(10.0, 10.0))
|
||||||
let kind_name = kind.node_finder_label().to_string();
|
.show(ui, |ui| {
|
||||||
if kind_name.contains(self.query.as_str()) {
|
for kind in all_kinds.all_kinds() {
|
||||||
if ui.selectable_label(false, kind_name).clicked() {
|
let kind_name = kind.node_finder_label().to_string();
|
||||||
submitted_archetype = Some(kind);
|
if kind_name.contains(self.query.as_str()) {
|
||||||
} else if query_submit {
|
if ui.selectable_label(false, kind_name).clicked() {
|
||||||
submitted_archetype = Some(kind);
|
submitted_archetype = Some(kind);
|
||||||
query_submit = false;
|
} else if query_submit {
|
||||||
|
submitted_archetype = Some(kind);
|
||||||
|
query_submit = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
});
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@ -9,7 +9,7 @@ rust-version = "1.56"
|
|||||||
crate-type = ["cdylib", "rlib"]
|
crate-type = ["cdylib", "rlib"]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
eframe = "0.16.0"
|
eframe = "0.18.0"
|
||||||
egui_node_graph = { path = "../egui_node_graph" }
|
egui_node_graph = { path = "../egui_node_graph" }
|
||||||
anyhow = "1.0"
|
anyhow = "1.0"
|
||||||
|
|
||||||
|
|||||||
@ -1,9 +1,6 @@
|
|||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
|
||||||
use eframe::{
|
use eframe::egui::{self, DragValue, TextStyle};
|
||||||
egui::{self, DragValue},
|
|
||||||
epi,
|
|
||||||
};
|
|
||||||
use egui_node_graph::*;
|
use egui_node_graph::*;
|
||||||
|
|
||||||
// ========= First, define your user data types =============
|
// ========= First, define your user data types =============
|
||||||
@ -352,15 +349,15 @@ impl Default for NodeGraphExample {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl epi::App for NodeGraphExample {
|
impl eframe::App for NodeGraphExample {
|
||||||
fn name(&self) -> &str {
|
|
||||||
"Egui node graph example"
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Called each time the UI needs repainting, which may be many times per second.
|
/// Called each time the UI needs repainting, which may be many times per second.
|
||||||
/// Put your widgets into a `SidePanel`, `TopPanel`, `CentralPanel`, `Window` or `Area`.
|
/// Put your widgets into a `SidePanel`, `TopPanel`, `CentralPanel`, `Window` or `Area`.
|
||||||
fn update(&mut self, ctx: &egui::CtxRef, _frame: &epi::Frame) {
|
fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) {
|
||||||
let graph_response = self.state.draw_graph_editor(ctx, AllMyNodeTemplates);
|
let graph_response = egui::Window::new("Graph")
|
||||||
|
.show(ctx, |ui| {
|
||||||
|
self.state.draw_graph_editor(ui, AllMyNodeTemplates)
|
||||||
|
})
|
||||||
|
.unwrap().inner.unwrap();
|
||||||
for node_response in graph_response.node_responses {
|
for node_response in graph_response.node_responses {
|
||||||
// Here, we ignore all other graph events. But you may find
|
// Here, we ignore all other graph events. But you may find
|
||||||
// some use for them. For example, by playing a sound when a new
|
// some use for them. For example, by playing a sound when a new
|
||||||
@ -384,7 +381,7 @@ impl epi::App for NodeGraphExample {
|
|||||||
egui::pos2(10.0, 10.0),
|
egui::pos2(10.0, 10.0),
|
||||||
egui::Align2::LEFT_TOP,
|
egui::Align2::LEFT_TOP,
|
||||||
text,
|
text,
|
||||||
egui::TextStyle::Button,
|
TextStyle::Button.resolve(&ctx.style()),
|
||||||
egui::Color32::WHITE,
|
egui::Color32::WHITE,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -5,7 +5,14 @@
|
|||||||
// When compiling natively:
|
// When compiling natively:
|
||||||
#[cfg(not(target_arch = "wasm32"))]
|
#[cfg(not(target_arch = "wasm32"))]
|
||||||
fn main() {
|
fn main() {
|
||||||
let app = egui_node_graph_example::NodeGraphExample::default();
|
use eframe::egui::Visuals;
|
||||||
let native_options = eframe::NativeOptions::default();
|
|
||||||
eframe::run_native(Box::new(app), native_options);
|
eframe::run_native(
|
||||||
|
"Egui node graph example",
|
||||||
|
eframe::NativeOptions::default(),
|
||||||
|
Box::new(|cc| {
|
||||||
|
cc.egui_ctx.set_visuals(Visuals::dark());
|
||||||
|
Box::new(egui_node_graph_example::NodeGraphExample::default())
|
||||||
|
}),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user