Merge pull request #23 from gmorenz/egui-0.18

Update to egui 0.18
This commit is contained in:
setzer22 2022-05-24 11:32:50 +02:00 committed by GitHub
commit 8f0394aa05
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 42 additions and 37 deletions

View File

@ -15,7 +15,7 @@ workspace = ".."
persistence = ["serde", "slotmap/serde", "smallvec/serde", "egui/persistence"]
[dependencies]
egui = { version = "0.16" }
egui = { version = "0.18" }
slotmap = { version = "1.0" }
smallvec = { version = "1.7.0" }
serde = { version = "1.0", optional = true, features = ["derive"] }

View File

@ -60,11 +60,10 @@ where
#[must_use]
pub fn draw_graph_editor(
&mut self,
ctx: &CtxRef,
ctx: &Context,
all_kinds: impl NodeTemplateIter<Item = NodeTemplate>,
) -> GraphResponse<UserResponse> {
let mouse = &ctx.input().pointer;
let cursor_pos = mouse.hover_pos().unwrap_or(Pos2::ZERO);
let cursor_pos = ctx.input().pointer.hover_pos().unwrap_or(Pos2::ZERO);
// Gets filled with the port locations as nodes are drawn
let mut port_locations = PortLocations::new();
@ -224,6 +223,9 @@ where
/* Mouse input handling */
// This locks the context, so don't hold on to it for too long.
let mouse = &ctx.input().pointer;
if mouse.any_released() && self.connection_in_progress.is_some() {
self.connection_in_progress = None;
}
@ -467,25 +469,26 @@ where
// does not support drawing rectangles with asymmetrical round corners.
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_rect =
Rect::from_min_size(outer_rect.min, vec2(outer_rect.width(), titlebar_height));
let titlebar = Shape::Rect(RectShape {
rect: titlebar_rect,
corner_radius,
rounding,
fill: titlebar_color,
stroke: Stroke::none(),
});
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),
);
let body = Shape::Rect(RectShape {
rect: body_rect,
corner_radius: 0.0,
rounding: Rounding::none(),
fill: background_color,
stroke: Stroke::none(),
});
@ -496,7 +499,7 @@ where
);
let bottom_body = Shape::Rect(RectShape {
rect: bottom_body_rect,
corner_radius,
rounding,
fill: background_color,
stroke: Stroke::none(),
});
@ -507,7 +510,7 @@ where
.union(body_rect)
.union(bottom_body_rect)
.expand(1.0),
corner_radius: 4.0,
rounding,
fill: Color32::WHITE.lighten(0.8),
stroke: Stroke::none(),
})

View File

@ -41,7 +41,7 @@ where
let frame = Frame::dark_canvas(ui.style())
.fill(background_color)
.margin(vec2(5.0, 5.0));
.inner_margin(vec2(5.0, 5.0));
// The archetype that will be returned.
let mut submitted_archetype = None;
@ -55,19 +55,21 @@ where
let mut query_submit = resp.lost_focus() && ui.input().key_down(Key::Enter);
Frame::default().margin(vec2(10.0, 10.0)).show(ui, |ui| {
for kind in all_kinds.all_kinds() {
let kind_name = kind.node_finder_label().to_string();
if kind_name.contains(self.query.as_str()) {
if ui.selectable_label(false, kind_name).clicked() {
submitted_archetype = Some(kind);
} else if query_submit {
submitted_archetype = Some(kind);
query_submit = false;
Frame::default()
.inner_margin(vec2(10.0, 10.0))
.show(ui, |ui| {
for kind in all_kinds.all_kinds() {
let kind_name = kind.node_finder_label().to_string();
if kind_name.contains(self.query.as_str()) {
if ui.selectable_label(false, kind_name).clicked() {
submitted_archetype = Some(kind);
} else if query_submit {
submitted_archetype = Some(kind);
query_submit = false;
}
}
}
}
});
});
});
});

View File

@ -9,7 +9,7 @@ rust-version = "1.56"
crate-type = ["cdylib", "rlib"]
[dependencies]
eframe = "0.16.0"
eframe = "0.18.0"
egui_node_graph = { path = "../egui_node_graph" }
anyhow = "1.0"

View File

@ -1,9 +1,6 @@
use std::collections::HashMap;
use eframe::{
egui::{self, DragValue},
epi,
};
use eframe::egui::{self, DragValue, TextStyle};
use egui_node_graph::*;
// ========= First, define your user data types =============
@ -352,14 +349,10 @@ impl Default for NodeGraphExample {
}
}
impl epi::App for NodeGraphExample {
fn name(&self) -> &str {
"Egui node graph example"
}
impl eframe::App for NodeGraphExample {
/// 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`.
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);
for node_response in graph_response.node_responses {
// Here, we ignore all other graph events. But you may find
@ -384,7 +377,7 @@ impl epi::App for NodeGraphExample {
egui::pos2(10.0, 10.0),
egui::Align2::LEFT_TOP,
text,
egui::TextStyle::Button,
TextStyle::Button.resolve(&ctx.style()),
egui::Color32::WHITE,
);
}

View File

@ -5,7 +5,14 @@
// When compiling natively:
#[cfg(not(target_arch = "wasm32"))]
fn main() {
let app = egui_node_graph_example::NodeGraphExample::default();
let native_options = eframe::NativeOptions::default();
eframe::run_native(Box::new(app), native_options);
use eframe::egui::Visuals;
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())
}),
);
}