Skip to content

Commit 5a291d5

Browse files
committed
Update to newest egui-multiwin and make it compile. Some menus are probably broken.
1 parent ae6a468 commit 5a291d5

13 files changed

+1335
-810
lines changed

Cargo.lock

+1,126-672
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ publish = false
1010
[dependencies]
1111
bincode = "1.3.3"
1212
directories = "5.0.1"
13-
egui-multiwin = "0.1.7"
13+
egui-multiwin = "0.5.2"
1414
futures = "0.3.28"
1515
interprocess = "1.2.1"
1616
lazy_static = "1.4.0"

src/ipc.rs

+8
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,11 @@ pub enum IpcMessage {
99
/// Create a new schematic window
1010
NewSchematic,
1111
}
12+
13+
use egui_multiwin::winit::window::WindowId;
14+
15+
impl IpcMessage {
16+
pub fn window_id(&self) -> Option<WindowId> {
17+
None
18+
}
19+
}

src/main.rs

+24-15
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,21 @@ mod symbol;
2222

2323
use std::collections::HashMap;
2424

25-
use egui_multiwin::{
26-
multi_window::{MultiWindow, NewWindowRequest},
27-
winit::event_loop::EventLoopBuilder,
28-
};
25+
/// Macro generated code
26+
pub mod egui_multiwin_dynamic {
27+
egui_multiwin::tracked_window!(
28+
crate::MyApp,
29+
crate::ipc::IpcMessage,
30+
crate::window::Windows
31+
);
32+
egui_multiwin::multi_window!(
33+
crate::MyApp,
34+
crate::ipc::IpcMessage,
35+
crate::window::Windows
36+
);
37+
}
38+
39+
use egui_multiwin_dynamic::multi_window::{MultiWindow, NewWindowRequest};
2940

3041
use crate::schematic::SchematicHolder;
3142

@@ -68,11 +79,10 @@ fn main() {
6879
return;
6980
}
7081

71-
let mut event_loop: EventLoopBuilder<ipc::IpcMessage> =
72-
egui_multiwin::winit::event_loop::EventLoopBuilder::with_user_event();
82+
let mut event_loop = egui_multiwin::winit::event_loop::EventLoopBuilder::with_user_event();
7383
#[cfg(target_os = "linux")]
7484
egui_multiwin::winit::platform::x11::EventLoopBuilderExtX11::with_x11(&mut event_loop);
75-
let event_loop = event_loop.build();
85+
let event_loop = event_loop.build().unwrap();
7686
let proxy = event_loop.create_proxy();
7787

7888
std::thread::spawn(move || {
@@ -104,8 +114,7 @@ fn main() {
104114
}
105115
});
106116

107-
let mut multi_window: MultiWindow<MyApp, ipc::IpcMessage> =
108-
egui_multiwin::multi_window::MultiWindow::new();
117+
let mut multi_window = MultiWindow::new();
109118
let mut fd = egui_multiwin::egui::FontData::from_static(COMPUTER_MODERN_FONT);
110119
fd.tweak.y_offset_factor = 1.0 / 3.0;
111120
multi_window.add_font("computermodern".to_string(), fd);
@@ -120,17 +129,17 @@ fn main() {
120129
match ac.args[1].as_str() {
121130
"schematic" => {
122131
let _e =
123-
multi_window.add(window::schematic::SchematicWindow::request(), &event_loop);
132+
multi_window.add(window::schematic::SchematicWindow::request(), &mut ac, &event_loop);
124133
}
125134
"library" => {
126-
let _e = multi_window.add(window::library::Library::request(), &event_loop);
135+
let _e = multi_window.add(window::library::Library::request(), &mut ac, &event_loop);
127136
}
128137
_ => {
129-
let _e = multi_window.add(window::library::Library::request(), &event_loop);
138+
let _e = multi_window.add(window::library::Library::request(), &mut ac, &event_loop);
130139
}
131140
}
132141
} else {
133-
let _e = multi_window.add(window::schematic::SchematicWindow::request(), &event_loop);
142+
let _e = multi_window.add(window::schematic::SchematicWindow::request(), &mut ac, &event_loop);
134143
}
135144
multi_window.run(event_loop, ac);
136145
}
@@ -151,8 +160,8 @@ pub struct MyApp {
151160
units: general::DisplayMode,
152161
}
153162

154-
impl egui_multiwin::multi_window::CommonEventHandler<MyApp, ipc::IpcMessage> for MyApp {
155-
fn process_event(&mut self, event: ipc::IpcMessage) -> Vec<NewWindowRequest<MyApp>> {
163+
impl MyApp {
164+
fn process_event(&mut self, event: ipc::IpcMessage) -> Vec<NewWindowRequest> {
156165
let mut windows_to_create = vec![];
157166
match event {
158167
ipc::IpcMessage::NewSchematic => {

src/schematic.rs

+9-3
Original file line numberDiff line numberDiff line change
@@ -748,7 +748,9 @@ impl<'a> egui::Widget for SchematicWidget<'a> {
748748
if ui.button("Properties").clicked() {
749749
ui.close_menu();
750750
}
751-
})
751+
});
752+
// TODO check this for correctness
753+
response
752754
}
753755
MouseMode::TextDrag => {
754756
if response.clicked() {
@@ -770,7 +772,9 @@ impl<'a> egui::Widget for SchematicWidget<'a> {
770772
if ui.button("Properties").clicked() {
771773
ui.close_menu();
772774
}
773-
})
775+
});
776+
// TODO check this for correctness
777+
response
774778
}
775779
};
776780
pr = pr.union(response);
@@ -877,6 +881,8 @@ impl<'a> egui::Widget for SchematicWidget<'a> {
877881
focusable: true,
878882
},
879883
);
880-
pr.union(response)
884+
//pr.union(response)
885+
//TODO fix this
886+
response
881887
}
882888
}

src/symbol.rs

+68-55
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,9 @@ impl<'a> egui::Widget for SymbolDefinitionWidget<'a> {
352352
if ui.button("Properties").clicked() {
353353
ui.close_menu();
354354
}
355-
})
355+
});
356+
//TODO check this for correctness
357+
response
356358
}
357359
MouseMode::TextDrag => {
358360
if response.dragged_by(egui::PointerButton::Primary) {
@@ -372,7 +374,9 @@ impl<'a> egui::Widget for SymbolDefinitionWidget<'a> {
372374
if ui.button("Properties").clicked() {
373375
ui.close_menu();
374376
}
375-
})
377+
});
378+
//TODO check this for correctness
379+
response
376380
}
377381
};
378382
pr = pr.union(response);
@@ -400,13 +404,19 @@ impl<'a> egui::Widget for SymbolDefinitionWidget<'a> {
400404
if ui.button("Properties").clicked() {
401405
ui.close_menu();
402406
}
403-
})
407+
});
408+
// TODO check this for correctness
409+
response
410+
}
411+
MouseMode::TextDrag => {
412+
response.context_menu(|ui| {
413+
if ui.button("Properties").clicked() {
414+
ui.close_menu();
415+
}
416+
});
417+
//TODO check this for correctness
418+
response
404419
}
405-
MouseMode::TextDrag => response.context_menu(|ui| {
406-
if ui.button("Properties").clicked() {
407-
ui.close_menu();
408-
}
409-
}),
410420
};
411421
pr = pr.union(response);
412422
}
@@ -419,60 +429,63 @@ impl<'a> egui::Widget for SymbolDefinitionWidget<'a> {
419429
ui.close_menu();
420430
}
421431
});
422-
423-
let pos = ui.input(|i| i.pointer.interact_pos());
424-
if let Some(pos) = pos {
425-
let pos2 = pos - zoom_origin.to_vec2();
426-
match self.mm {
427-
MouseMode::Selection => {}
428-
MouseMode::TextDrag => {}
429-
MouseMode::NewText => {
430-
if pr.clicked() {
431-
self.actions.push(LibraryAction::CreateText {
432-
libname: self.sym.libname.clone(),
433-
symname: self.sym.sym.name.clone(),
434-
text: TextOnPage {
435-
text: "New text".to_string(),
436-
location: crate::general::Coordinates::from_pos2(pos2, *self.zoom),
437-
color: crate::schematic::Colors::Standard,
438-
size: crate::general::Length::Inches(0.2),
439-
},
440-
});
441-
} else {
442-
pntr.text(
443-
pos,
444-
egui::Align2::LEFT_BOTTOM,
445-
"New text".to_string(),
446-
egui::FontId {
447-
size: crate::general::Length::Inches(0.2)
448-
.get_screen(*self.zoom, zoom_origin),
449-
family: egui::FontFamily::Monospace,
450-
},
451-
crate::schematic::Colors::Standard
452-
.get_color32(crate::general::ColorMode::ScreenModeDark),
453-
);
432+
if let Some(pr) = pr {
433+
let pos = ui.input(|i| i.pointer.interact_pos());
434+
if let Some(pos) = pos {
435+
let pos2 = pos - zoom_origin.to_vec2();
436+
match self.mm {
437+
MouseMode::Selection => {}
438+
MouseMode::TextDrag => {}
439+
MouseMode::NewText => {
440+
if pr.response.clicked() {
441+
self.actions.push(LibraryAction::CreateText {
442+
libname: self.sym.libname.clone(),
443+
symname: self.sym.sym.name.clone(),
444+
text: TextOnPage {
445+
text: "New text".to_string(),
446+
location: crate::general::Coordinates::from_pos2(pos2, *self.zoom),
447+
color: crate::schematic::Colors::Standard,
448+
size: crate::general::Length::Inches(0.2),
449+
},
450+
});
451+
} else {
452+
pntr.text(
453+
pos,
454+
egui::Align2::LEFT_BOTTOM,
455+
"New text".to_string(),
456+
egui::FontId {
457+
size: crate::general::Length::Inches(0.2)
458+
.get_screen(*self.zoom, zoom_origin),
459+
family: egui::FontFamily::Monospace,
460+
},
461+
crate::schematic::Colors::Standard
462+
.get_color32(crate::general::ColorMode::ScreenModeDark),
463+
);
464+
}
454465
}
455-
}
456-
MouseMode::NewPin => {
457-
let pin = crate::symbol::Pin {
458-
location: crate::general::Coordinates::from_pos2(pos2, *self.zoom),
459-
rotation: *self.pin_angle,
460-
};
461-
if pr.clicked() {
462-
self.actions.push(LibraryAction::CreatePin {
463-
libname: self.sym.libname.clone(),
464-
symname: self.sym.sym.name.clone(),
465-
pin: Some(pin),
466-
});
467-
} else {
468-
pin.draw(*self.zoom, zoom_origin, &pntr, pos, area);
466+
MouseMode::NewPin => {
467+
let pin = crate::symbol::Pin {
468+
location: crate::general::Coordinates::from_pos2(pos2, *self.zoom),
469+
rotation: *self.pin_angle,
470+
};
471+
if pr.response.clicked() {
472+
self.actions.push(LibraryAction::CreatePin {
473+
libname: self.sym.libname.clone(),
474+
symname: self.sym.sym.name.clone(),
475+
pin: Some(pin),
476+
});
477+
} else {
478+
pin.draw(*self.zoom, zoom_origin, &pntr, pos, area);
479+
}
469480
}
470481
}
471482
}
472483
}
473484

474485
let (_area, response) = ui.allocate_exact_size(size, sense);
475-
pr.union(response)
486+
//pr.union(response)
487+
//TODO fix this
488+
response
476489
}
477490
}
478491

src/window/component_name.rs

+12-10
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
//! This window asks the user for a name of the new library
22
33
use egui_multiwin::egui_glow::EguiGlow;
4-
use egui_multiwin::{
5-
egui,
4+
use egui_multiwin::egui;
5+
use crate::egui_multiwin_dynamic::{
66
multi_window::NewWindowRequest,
77
tracked_window::{RedrawResponse, TrackedWindow},
88
};
@@ -20,28 +20,29 @@ pub struct Name {
2020

2121
impl Name {
2222
/// Create a new window
23-
pub fn request(lib_name: String) -> NewWindowRequest<MyApp> {
24-
NewWindowRequest {
25-
window_state: Box::new(Self {
23+
pub fn request(lib_name: String) -> NewWindowRequest {
24+
NewWindowRequest::new(
25+
super::Windows::ComponentName(Self {
2626
lib_name,
2727
name: "".to_string(),
2828
}),
29-
builder: egui_multiwin::winit::window::WindowBuilder::new()
29+
egui_multiwin::winit::window::WindowBuilder::new()
3030
.with_resizable(true)
3131
.with_inner_size(egui_multiwin::winit::dpi::LogicalSize {
3232
width: 320.0,
3333
height: 240.0,
3434
})
3535
.with_title("New Library"),
36-
options: egui_multiwin::tracked_window::TrackedWindowOptions {
36+
egui_multiwin::tracked_window::TrackedWindowOptions {
3737
vsync: false,
3838
shader: None,
3939
},
40-
}
40+
egui_multiwin::multi_window::new_id(),
41+
)
4142
}
4243
}
4344

44-
impl TrackedWindow<MyApp> for Name {
45+
impl TrackedWindow for Name {
4546
fn is_root(&self) -> bool {
4647
false
4748
}
@@ -53,7 +54,8 @@ impl TrackedWindow<MyApp> for Name {
5354
c: &mut MyApp,
5455
egui: &mut EguiGlow,
5556
_window: &egui_multiwin::winit::window::Window,
56-
) -> RedrawResponse<MyApp> {
57+
_clipboard: &mut egui_multiwin::arboard::Clipboard,
58+
) -> RedrawResponse {
5759
let mut quit = false;
5860

5961
let windows_to_create = vec![];

0 commit comments

Comments
 (0)