Skip to content

Commit

Permalink
Update egui
Browse files Browse the repository at this point in the history
  • Loading branch information
zakarumych committed Jul 6, 2024
1 parent 0106647 commit 5df3334
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 26 deletions.
10 changes: 5 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
workspace = { members = ["demo"] }
[package]
name = "egui-snarl"
version = "0.3.0"
version = "0.4.0"
edition = "2021"
description = "Node-graphs for egui"
license = "MIT OR Apache-2.0"
Expand All @@ -13,16 +13,16 @@ categories = ["gui", "visualization"]
serde = ["dep:serde", "egui/serde", "slab/serde"]

[dependencies]
egui = { version = "0.27" }
egui = { version = "0.28" }
slab = { version = "0.4" }
serde = { version = "1.0", features = ["derive"], optional = true }
tiny-fn = { version = "0.1.6" }

egui-probe = { version = "0.3", features = ["derive"], optional = true }
egui-probe = { version = "0.5", features = ["derive"], optional = true }

[dev-dependencies]
eframe = { version = "0.27", features = ["serde", "persistence"] }
egui_extras = { version = "0.27", features = ["all_loaders"] }
eframe = { version = "0.28", features = ["serde", "persistence"] }
egui_extras = { version = "0.28", features = ["all_loaders"] }
syn = { version = "2.0", features = ["extra-traits"] }
serde_json = { version = "1.0" }

Expand Down
8 changes: 4 additions & 4 deletions demo/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ name = "demo"
path = "../examples/demo.rs"

[dependencies]
egui = { version = "0.27" }
egui-probe = { version = "0.3", features = ["derive"] }
eframe = { version = "0.27", features = ["serde", "persistence"] }
egui_extras = { version = "0.27", features = ["all_loaders"] }
egui = { version = "0.28" }
egui-probe = { version = "0.5", features = ["derive"] }
eframe = { version = "0.28", features = ["serde", "persistence"] }
egui_extras = { version = "0.28", features = ["all_loaders"] }
syn = { version = "2.0", features = ["extra-traits"] }
serde = { version = "1.0", features = ["derive"] }
serde_json = { version = "1.0" }
Expand Down
3 changes: 0 additions & 3 deletions demo/src/main.rs

This file was deleted.

2 changes: 1 addition & 1 deletion examples/demo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1030,7 +1030,7 @@ fn main() -> eframe::Result<()> {
eframe::run_native(
"egui-snarl demo",
native_options,
Box::new(|cx| Box::new(DemoApp::new(cx))),
Box::new(|cx| Ok(Box::new(DemoApp::new(cx)))),
)
}

Expand Down
22 changes: 16 additions & 6 deletions src/ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1017,12 +1017,12 @@ impl<T> Snarl<T> {
let mut pin_hovered = None;

// Rect for node + frame margin.
let node_frame_rect = node_frame.total_margin().expand_rect(node_rect);
let node_frame_rect = node_rect + node_frame.total_margin();

if snarl_state.selected_nodes().contains(&node) {
let select_style = style.select_style(snarl_state.scale(), ui);

let select_rect = select_style.margin.expand_rect(node_frame_rect);
let select_rect = node_frame_rect + select_style.margin;

ui.painter().rect(
select_rect,
Expand All @@ -1045,7 +1045,11 @@ impl<T> Snarl<T> {
.collect::<Vec<_>>();

// Interact with node frame.
let r = ui.interact(node_frame_rect, node_id, Sense::click_and_drag());
let r = ui.interact(
node_frame_rect,
node_id.with("frame"),
Sense::click_and_drag(),
);

if !input.modifiers.shift
&& !input.modifiers.command
Expand Down Expand Up @@ -1093,20 +1097,22 @@ impl<T> Snarl<T> {
let node_ui = &mut ui.child_ui_with_id_source(
node_frame_rect,
Layout::top_down(Align::Center),
("node", node_id),
node_id,
None,
);

let r = node_frame.show(node_ui, |ui| {
// Render header frame.
let mut header_rect = node_rect;

let mut header_frame_rect = header_frame.total_margin().expand_rect(header_rect);
let mut header_frame_rect = header_rect + header_frame.total_margin();

// Show node's header
let header_ui = &mut ui.child_ui_with_id_source(
header_frame_rect,
Layout::top_down(Align::Center),
"header",
None,
);

header_frame.show(header_ui, |ui: &mut Ui| {
Expand All @@ -1131,7 +1137,7 @@ impl<T> Snarl<T> {
header_rect = ui.min_rect();
});

header_frame_rect = header_frame.total_margin().expand_rect(header_rect);
header_frame_rect = header_rect + header_frame.total_margin();

ui.advance_cursor_after_rect(Rect::from_min_max(
header_rect.min,
Expand Down Expand Up @@ -1185,6 +1191,7 @@ impl<T> Snarl<T> {
payload_rect,
Layout::top_down(Align::Min),
"inputs",
None,
);

inputs_ui.set_clip_rect(payload_clip_rect.intersect(viewport));
Expand Down Expand Up @@ -1305,6 +1312,7 @@ impl<T> Snarl<T> {
payload_rect,
Layout::top_down(Align::Max),
"outputs",
None,
);

outputs_ui.set_clip_rect(payload_clip_rect.intersect(viewport));
Expand Down Expand Up @@ -1439,6 +1447,7 @@ impl<T> Snarl<T> {
body_rect,
Layout::left_to_right(Align::Min),
"body",
None,
);
body_ui.set_clip_rect(payload_clip_rect.intersect(viewport));

Expand Down Expand Up @@ -1483,6 +1492,7 @@ impl<T> Snarl<T> {
footer_rect,
Layout::left_to_right(Align::Min),
"footer",
None,
);
footer_ui.set_clip_rect(payload_clip_rect.intersect(viewport));

Expand Down
6 changes: 3 additions & 3 deletions src/ui/pin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ pub fn draw_pin(
points,
closed: true,
fill: fill,
stroke: stroke,
stroke: stroke.into(),
}));
}
PinShape::Square => {
Expand All @@ -227,7 +227,7 @@ pub fn draw_pin(
points,
closed: true,
fill: fill,
stroke: stroke,
stroke: stroke.into(),
}));
}

Expand All @@ -249,7 +249,7 @@ pub fn draw_pin(
points,
closed: true,
fill,
stroke,
stroke: stroke.into(),
}));
}

Expand Down
6 changes: 3 additions & 3 deletions src/ui/wire.rs
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ fn draw_bezier_5(shapes: &mut Vec<Shape>, points: &[Pos2; 6], stroke: Stroke) {
points: path,
closed: false,
fill: Color32::TRANSPARENT,
stroke,
stroke: stroke.into(),
});

shapes.push(shape);
Expand All @@ -315,7 +315,7 @@ fn draw_bezier_3(shapes: &mut Vec<Shape>, points: &[Pos2; 4], stroke: Stroke) {
points: path,
closed: false,
fill: Color32::TRANSPARENT,
stroke,
stroke: stroke.into(),
});

shapes.push(shape);
Expand Down Expand Up @@ -746,7 +746,7 @@ fn draw_axis_aligned(
points: path,
closed: false,
fill: Color32::TRANSPARENT,
stroke,
stroke: stroke.into(),
});

shapes.push(shape);
Expand Down
9 changes: 8 additions & 1 deletion src/ui/zoom.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use egui::{
epaint::Shadow,
style::{Interaction, ScrollStyle, Spacing, WidgetVisuals, Widgets},
style::{Interaction, ScrollStyle, Spacing, TextCursorStyle, WidgetVisuals, Widgets},
FontId, Frame, Margin, Rounding, Stroke, Style, Vec2, Visuals,
};

Expand Down Expand Up @@ -102,6 +102,13 @@ impl Zoom for Widgets {
}
}

impl Zoom for TextCursorStyle {
#[inline(always)]
fn zoom(&mut self, zoom: f32) {
self.stroke.zoom(zoom);
}
}

impl Zoom for Visuals {
#[inline(always)]
fn zoom(&mut self, zoom: f32) {
Expand Down

0 comments on commit 5df3334

Please sign in to comment.