Update to egui version 0.33, also fix weird spacing between inputs

This commit is contained in:
elvis
2025-10-29 18:11:48 +01:00
parent 284f136409
commit cce3b5a7a0
6 changed files with 84 additions and 97 deletions

View File

@ -14,7 +14,7 @@ workspace = ".."
persistence = ["serde", "slotmap/serde", "smallvec/serde", "egui/persistence"] persistence = ["serde", "slotmap/serde", "smallvec/serde", "egui/persistence"]
[dependencies] [dependencies]
egui = "0.32" egui = "0.33"
slotmap = { version = "1.0" } slotmap = { version = "1.0" }
smallvec = { version = "1.10.0" } smallvec = { version = "1.10.0" }
serde = { version = "1.0", optional = true, features = ["derive"] } serde = { version = "1.0", optional = true, features = ["derive"] }

View File

@ -1,7 +1,7 @@
use std::collections::HashSet; use std::collections::HashSet;
use std::num::NonZeroU32; use std::num::NonZeroU32;
use egui::epaint::{CornerRadiusF32, CubicBezierShape, RectShape}; use egui::epaint::{CubicBezierShape, RectShape};
use egui::*; use egui::*;
use super::*; use super::*;
@ -538,7 +538,7 @@ where
2.0, 2.0,
bg_color, bg_color,
Stroke::new(3.0, stroke_color), Stroke::new(3.0, stroke_color),
StrokeKind::Middle, StrokeKind::Outside,
); );
self.selected_nodes = node_rects self.selected_nodes = node_rects
@ -583,7 +583,7 @@ where
} }
// Deselect and deactivate finder if the editor background is clicked, // 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) { if click_on_background || (mouse.any_click() && !cursor_in_editor) {
self.selected_nodes = Vec::new(); self.selected_nodes = Vec::new();
self.node_finder = None; self.node_finder = None;
@ -614,7 +614,7 @@ fn draw_connection(
dst_pos: Pos2, dst_pos: Pos2,
color: Color32, color: Color32,
) { ) {
let connection_stroke = egui::Stroke { let connection_stroke = Stroke {
width: 5.0 * pan_zoom.zoom, width: 5.0 * pan_zoom.zoom,
color, color,
}; };
@ -664,13 +664,13 @@ where
) -> Vec<NodeResponse<UserResponse, NodeData>> { ) -> Vec<NodeResponse<UserResponse, NodeData>> {
let mut child_ui = ui.new_child( let mut child_ui = ui.new_child(
UiBuilder::new() UiBuilder::new()
.id_salt(self.node_id) .layout(Layout::default())
.max_rect(Rect::from_min_size( .max_rect(Rect::from_min_size(
*self.position + self.pan, *self.position + self.pan,
Self::MAX_NODE_SIZE.into(), Self::MAX_NODE_SIZE.into(),
)) ))
.layout(Layout::default()) .id_salt(self.node_id)
.ui_stack_info(UiStackInfo::default()), // .ui_stack_info(UiStackInfo::default()),
); );
Self::show_graph_node(self, pan_zoom, &mut child_ui, user_state) Self::show_graph_node(self, pan_zoom, &mut child_ui, user_state)
@ -684,7 +684,7 @@ where
ui: &mut Ui, ui: &mut Ui,
user_state: &mut UserState, user_state: &mut UserState,
) -> Vec<NodeResponse<UserResponse, NodeData>> { ) -> 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 mut responses = Vec::<NodeResponse<UserResponse, NodeData>>::new();
let background_color; let background_color;
@ -720,7 +720,7 @@ where
UiBuilder::new() UiBuilder::new()
.max_rect(inner_rect) .max_rect(inner_rect)
.layout(*ui.layout()) .layout(*ui.layout())
.ui_stack_info(UiStackInfo::default()), // .ui_stack_info(UiStackInfo::default()),
); );
// Get interaction rect from memory, it may expand after the window // Get interaction rect from memory, it may expand after the window
@ -821,25 +821,24 @@ where
ui.label(param_name); ui.label(param_name);
} }
let height_intermediate = ui.min_rect().bottom(); // let height_intermediate = ui.min_rect().bottom();
let max_connections = self.graph[param_id] // let max_connections = self.graph[param_id]
.max_connections // .max_connections
.map(NonZeroU32::get) // .map(NonZeroU32::get)
.unwrap_or(u32::MAX) // .unwrap_or(u32::MAX) as usize;
as usize; // let port_height = port_height(
let port_height = port_height( // max_connections != 1,
max_connections != 1, // self.graph.connections(param_id).len(),
self.graph.connections(param_id).len(), // max_connections,
max_connections, // );
); // let margin = 5.0;
let margin = 5.0; // let missing_space = port_height
let missing_space = port_height // - (height_intermediate - height_before)
- (height_intermediate - height_before) // + margin;
+ margin; // if missing_space > 0.0 {
if missing_space > 0.0 { // ui.add_space(missing_space);
ui.add_space(missing_space); // }
}
self.graph[self.node_id].user_data.separator( self.graph[self.node_id].user_data.separator(
ui, ui,
@ -945,7 +944,7 @@ where
let port_rect = Rect::from_center_size( let port_rect = Rect::from_center_size(
port_pos, port_pos,
egui::vec2( vec2(
10.0, 10.0,
port_height(wide_port, connections, max_connections), port_height(wide_port, connections, max_connections),
) * pan_zoom.zoom, ) * pan_zoom.zoom,
@ -1135,8 +1134,7 @@ where
let max_connections = self.graph[*param] let max_connections = self.graph[*param]
.max_connections .max_connections
.map(NonZeroU32::get) .map(NonZeroU32::get)
.unwrap_or(u32::MAX) .unwrap_or(u32::MAX) as usize;
as usize;
draw_port( draw_port(
pan_zoom, pan_zoom,
ui, ui,
@ -1188,71 +1186,53 @@ where
let (shape, outline) = { let (shape, outline) = {
let rounding_radius = 4.0 * pan_zoom.zoom; let rounding_radius = 4.0 * pan_zoom.zoom;
let rounding = CornerRadiusF32::same(rounding_radius); let rounding = CornerRadius::from(rounding_radius);
let titlebar_height = title_height + margin.y; let titlebar_height = title_height + margin.y;
let titlebar_rect = Rect::from_min_size( let titlebar_rect = Rect::from_min_size(
outer_rect.min, outer_rect.min,
vec2(outer_rect.width(), titlebar_height), vec2(outer_rect.width(), titlebar_height),
); );
let titlebar = Shape::Rect(RectShape {
rect: titlebar_rect, let title_bar_color = self.graph[self.node_id]
corner_radius: rounding.into(),
fill: self.graph[self.node_id]
.user_data .user_data
.titlebar_color(ui, self.node_id, self.graph, user_state) .titlebar_color(ui, self.node_id, self.graph, user_state)
.unwrap_or_else(|| background_color.lighten(0.8)), .unwrap_or_else(|| background_color.lighten(0.8));
stroke: Stroke::NONE,
blur_width: 0.0, let titlebar = Shape::Rect(
stroke_kind: StrokeKind::Middle, RectShape::filled(titlebar_rect, rounding, title_bar_color)
brush: None, .with_texture(Default::default(), Rect::ZERO),
round_to_pixels: None, );
});
let body_rect = Rect::from_min_size( let body_rect = Rect::from_min_size(
outer_rect.min + vec2(0.0, titlebar_height - rounding_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(
rect: body_rect, RectShape::filled(body_rect, CornerRadius::ZERO, background_color)
corner_radius: CornerRadius::ZERO, .with_texture(Default::default(), Rect::ZERO),
fill: background_color, );
stroke: Stroke::NONE,
blur_width: 0.0,
stroke_kind: StrokeKind::Middle,
brush: None,
round_to_pixels: None,
});
let bottom_body_rect = Rect::from_min_size( let bottom_body_rect = Rect::from_min_size(
body_rect.min body_rect.min
+ vec2(0.0, body_rect.height() - titlebar_height * 0.5), + vec2(0.0, body_rect.height() - titlebar_height * 0.5),
vec2(outer_rect.width(), titlebar_height), vec2(outer_rect.width(), titlebar_height),
); );
let bottom_body = Shape::Rect(RectShape { let bottom_body = Shape::Rect(
rect: bottom_body_rect, RectShape::filled(bottom_body_rect, rounding, background_color)
corner_radius: rounding.into(), .with_texture(Default::default(), Rect::ZERO),
fill: background_color, );
stroke: Stroke::NONE,
blur_width: 0.0,
stroke_kind: StrokeKind::Middle,
brush: None,
round_to_pixels: None,
});
let node_rect = let node_rect =
titlebar_rect.union(body_rect).union(bottom_body_rect); titlebar_rect.union(body_rect).union(bottom_body_rect);
let outline = if self.selected { let outline = if self.selected {
Shape::Rect(RectShape { Shape::Rect(
rect: node_rect.expand(1.0 * pan_zoom.zoom), RectShape::filled(
corner_radius: rounding.into(), node_rect.expand(1.0 * pan_zoom.zoom),
fill: Color32::WHITE.lighten(0.8), rounding,
stroke: Stroke::NONE, Color32::WHITE.lighten(0.8))
blur_width: 0.0, .with_texture(Default::default(), Rect::ZERO)
stroke_kind: StrokeKind::Middle, )
brush: None,
round_to_pixels: None,
})
} else { } else {
Shape::Noop Shape::Noop
}; };

View File

@ -80,7 +80,7 @@ where
&& ui.input(|i| i.key_pressed(Key::Enter)); && ui.input(|i| i.key_pressed(Key::Enter));
let max_height = let max_height =
ui.input(|i| f32::max(i.screen_rect.height() * 0.5, 200.)); ui.input(|i| f32::max(i.content_rect().height() * 0.5, 200.));
let scroll_area_width = resp.rect.width(); let scroll_area_width = resp.rect.width();
let all_kinds = all_kinds.all_kinds(); let all_kinds = all_kinds.all_kinds();

View File

@ -26,10 +26,18 @@ impl Scale for Vec2 {
impl Scale for Margin { impl Scale for Margin {
fn scale(&mut self, amount: f32) { fn scale(&mut self, amount: f32) {
self.left = (self.leftf() * amount).round() as _; self.left = (self.left as f32 * amount)
self.right = (self.rightf() * amount).round() as _; .round()
self.top = (self.topf() * amount).round() as _; .clamp(i8::MIN as f32, i8::MAX as f32) as i8;
self.bottom = (self.bottomf() * amount).round() as _; 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;
} }
} }
@ -44,10 +52,18 @@ impl Scale for CornerRadiusF32 {
impl Scale for CornerRadius { impl Scale for CornerRadius {
fn scale(&mut self, amount: f32) { fn scale(&mut self, amount: f32) {
self.nw = (self.nw as f32 * amount) as u8; self.ne = (self.ne as f32 * amount)
self.ne = (self.ne as f32 * amount) as u8; .round()
self.sw = (self.sw as f32 * amount) as u8; .clamp(0f32, u8::MAX as f32) as u8;
self.se = (self.se as f32 * amount) 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;
} }
} }
@ -59,8 +75,7 @@ impl Scale for Stroke {
impl Scale for Shadow { impl Scale for Shadow {
fn scale(&mut self, amount: f32) { fn scale(&mut self, amount: f32) {
self.spread = self.spread = (self.spread as f32 * amount.clamp(0.4, 1.)) as u8;
((self.spread as f32) * amount.clamp(0.4, 1.)).round() as _;
} }
} }
@ -86,22 +101,15 @@ impl Scale for Style {
self.spacing.item_spacing.scale(amount); self.spacing.item_spacing.scale(amount);
self.spacing.window_margin.scale(amount); self.spacing.window_margin.scale(amount);
self.spacing.button_padding.scale(amount); self.spacing.button_padding.scale(amount);
self.spacing.menu_margin *= amount;
self.spacing.indent *= amount; self.spacing.indent *= amount;
self.spacing.interact_size.scale(amount); self.spacing.interact_size.scale(amount);
self.spacing.slider_width *= amount; self.spacing.slider_width *= amount;
self.spacing.slider_rail_height *= amount;
self.spacing.combo_width *= amount;
self.spacing.text_edit_width *= amount; self.spacing.text_edit_width *= amount;
self.spacing.icon_width *= amount; self.spacing.icon_width *= amount;
self.spacing.icon_width_inner *= amount; self.spacing.icon_width_inner *= amount;
self.spacing.icon_spacing *= amount; self.spacing.icon_spacing *= amount;
self.spacing.default_area_size *= amount;
self.spacing.tooltip_width *= amount; self.spacing.tooltip_width *= amount;
self.spacing.menu_width *= amount;
self.spacing.menu_spacing *= amount;
self.spacing.combo_height *= amount; self.spacing.combo_height *= amount;
self.spacing.scroll.bar_width *= amount; self.spacing.scroll.bar_width *= amount;
self.spacing.scroll.floating_allocated_width *= amount; self.spacing.scroll.floating_allocated_width *= amount;
self.spacing.scroll.floating_width *= amount; self.spacing.scroll.floating_width *= amount;
@ -117,7 +125,6 @@ impl Scale for Style {
self.visuals.selection.stroke.scale(amount); self.visuals.selection.stroke.scale(amount);
self.visuals.menu_corner_radius *= amount;
self.visuals.resize_corner_size *= amount; self.visuals.resize_corner_size *= amount;
self.visuals.text_cursor.stroke.width *= amount; self.visuals.text_cursor.stroke.width *= amount;
self.visuals.clip_rect_margin *= amount; self.visuals.clip_rect_margin *= amount;

View File

@ -8,8 +8,8 @@ use serde::{Deserialize, Serialize};
use super::*; use super::*;
use crate::scale::Scale; use crate::scale::Scale;
const MIN_ZOOM: f32 = 0.2; const MIN_ZOOM: f32 = 0.1;
const MAX_ZOOM: f32 = 2.0; const MAX_ZOOM: f32 = 2.5;
#[derive(Clone)] #[derive(Clone)]
#[cfg_attr(feature = "persistence", derive(Serialize, Deserialize))] #[cfg_attr(feature = "persistence", derive(Serialize, Deserialize))]

View File

@ -8,7 +8,7 @@ crate-type = ["cdylib", "rlib"]
[dependencies] [dependencies]
log = "*" log = "*"
eframe = "0.32" eframe = "0.33"
anyhow = "1" anyhow = "1"
serde = { version = "1", optional = true } serde = { version = "1", optional = true }
colored = "*" colored = "*"