mirror of https://codeberg.org/topola/topola.git
refactor(egui/actions): put menu rendering into `actions` module
This commit is contained in:
parent
b47459b3d7
commit
f454e248d7
|
|
@ -51,7 +51,7 @@ impl Trigger {
|
|||
self.triggered = ui.button(self.action.widget_text()).clicked();
|
||||
}
|
||||
|
||||
pub fn hyperlink(&mut self, _ctx: &egui::Context, ui: &mut egui::Ui, url: &str) {
|
||||
pub fn hyperlink(&self, _ctx: &egui::Context, ui: &mut egui::Ui, url: &str) {
|
||||
ui.hyperlink_to(self.action.widget_text(), url);
|
||||
}
|
||||
|
||||
|
|
@ -72,7 +72,7 @@ impl Trigger {
|
|||
}
|
||||
|
||||
impl Switch {
|
||||
pub fn toggle_widget(&mut self, _ctx: &egui::Context, ui: &mut egui::Ui, selected: &mut bool) {
|
||||
pub fn toggle_widget(&self, _ctx: &egui::Context, ui: &mut egui::Ui, selected: &mut bool) {
|
||||
ui.toggle_value(selected, self.action.widget_text());
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -7,6 +7,9 @@ use crate::{
|
|||
translator::Translator,
|
||||
};
|
||||
|
||||
use egui::{Context, Ui};
|
||||
use topola::autorouter::AutorouterOptions;
|
||||
|
||||
pub struct FileActions {
|
||||
pub open_design: Trigger,
|
||||
pub export_session: Trigger,
|
||||
|
|
@ -50,6 +53,25 @@ impl FileActions {
|
|||
.into_trigger(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn render_menu(&mut self, ctx: &Context, ui: &mut Ui, _have_workspace: bool) {
|
||||
self.open_design.button(ctx, ui);
|
||||
//ui.add_enabled_ui(have_workspace, |ui| {
|
||||
self.export_session.button(ctx, ui);
|
||||
|
||||
ui.separator();
|
||||
|
||||
self.import_history.button(ctx, ui);
|
||||
self.export_history.button(ctx, ui);
|
||||
//});
|
||||
|
||||
ui.separator();
|
||||
|
||||
// "Quit" button wouldn't work on a Web page.
|
||||
if !cfg!(target_arch = "wasm32") {
|
||||
self.quit.button(ctx, ui);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub struct EditActions {
|
||||
|
|
@ -88,6 +110,29 @@ impl EditActions {
|
|||
.into_trigger(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn render_menu(
|
||||
&mut self,
|
||||
ctx: &Context,
|
||||
ui: &mut Ui,
|
||||
have_workspace: bool,
|
||||
_workspace_activities_enabled: bool,
|
||||
) -> egui::InnerResponse<()> {
|
||||
ui.add_enabled_ui(have_workspace, |ui| {
|
||||
self.undo.button(ctx, ui);
|
||||
self.redo.button(ctx, ui);
|
||||
|
||||
ui.separator();
|
||||
|
||||
self.abort.button(ctx, ui);
|
||||
|
||||
ui.separator();
|
||||
|
||||
//ui.add_enabled_ui(workspace_activities_enabled, |ui| {
|
||||
self.remove_bands.button(ctx, ui);
|
||||
//});
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
pub struct PlaceActions {
|
||||
|
|
@ -105,6 +150,18 @@ impl PlaceActions {
|
|||
.into_switch(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn render_menu(
|
||||
&mut self,
|
||||
ctx: &Context,
|
||||
ui: &mut Ui,
|
||||
have_workspace: bool,
|
||||
is_placing_via: &mut bool,
|
||||
) -> egui::InnerResponse<()> {
|
||||
ui.add_enabled_ui(have_workspace, |ui| {
|
||||
self.place_via.toggle_widget(ctx, ui, is_placing_via);
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
pub struct RouteActions {
|
||||
|
|
@ -122,6 +179,52 @@ impl RouteActions {
|
|||
.into_trigger(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn render_menu(
|
||||
&mut self,
|
||||
ctx: &Context,
|
||||
ui: &mut Ui,
|
||||
tr: &Translator,
|
||||
have_workspace: bool,
|
||||
_workspace_activities_enabled: bool,
|
||||
autorouter_options: &mut AutorouterOptions,
|
||||
) -> egui::InnerResponse<()> {
|
||||
ui.add_enabled_ui(have_workspace, |ui| {
|
||||
//ui.add_enabled_ui(workspace_activities_enabled, |ui| {
|
||||
self.autoroute.button(ctx, ui);
|
||||
//});
|
||||
ui.separator();
|
||||
|
||||
ui.label(tr.text("tr-menu-route-routed-band-width"));
|
||||
|
||||
ui.add(
|
||||
egui::widgets::Slider::new(
|
||||
&mut autorouter_options.router_options.routed_band_width,
|
||||
1.0..=1000.0,
|
||||
)
|
||||
.suffix(""),
|
||||
);
|
||||
|
||||
ui.separator();
|
||||
|
||||
ui.menu_button(tr.text("tr-menu-options"), |ui| {
|
||||
ui.checkbox(
|
||||
&mut autorouter_options.presort_by_pairwise_detours,
|
||||
tr.text("tr-menu-route-options-presort-by-pairwise-detours"),
|
||||
);
|
||||
ui.checkbox(
|
||||
&mut autorouter_options
|
||||
.router_options
|
||||
.squeeze_through_under_bends,
|
||||
tr.text("tr-menu-route-options-squeeze-through-under-bends"),
|
||||
);
|
||||
ui.checkbox(
|
||||
&mut autorouter_options.router_options.wrap_around_bands,
|
||||
tr.text("tr-menu-route-options-wrap-around-bands"),
|
||||
);
|
||||
});
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
pub struct InspectActions {
|
||||
|
|
@ -146,6 +249,13 @@ impl InspectActions {
|
|||
.into_trigger(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn render_menu(&mut self, ctx: &Context, ui: &mut Ui, workspace_activities_enabled: bool) {
|
||||
ui.add_enabled_ui(workspace_activities_enabled, |ui| {
|
||||
self.compare_detours.button(ctx, ui);
|
||||
self.measure_length.button(ctx, ui);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
pub struct HelpActions {
|
||||
|
|
@ -163,6 +273,11 @@ impl HelpActions {
|
|||
.into_trigger(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn render_menu(&mut self, ctx: &Context, ui: &mut Ui, online_documentation_url: &str) {
|
||||
self.online_documentation
|
||||
.hyperlink(ctx, ui, online_documentation_url);
|
||||
}
|
||||
}
|
||||
|
||||
pub struct Actions {
|
||||
|
|
|
|||
|
|
@ -84,39 +84,16 @@ impl MenuBar {
|
|||
ui.separator();
|
||||
|
||||
ui.menu_button(tr.text("tr-menu-file"), |ui| {
|
||||
actions.file.open_design.button(ctx, ui);
|
||||
//ui.add_enabled_ui(maybe_workspace.is_some(), |ui| {
|
||||
actions.file.export_session.button(ctx, ui);
|
||||
|
||||
ui.separator();
|
||||
|
||||
actions.file.import_history.button(ctx, ui);
|
||||
actions.file.export_history.button(ctx, ui);
|
||||
//});
|
||||
|
||||
ui.separator();
|
||||
|
||||
// "Quit" button wouldn't work on a Web page.
|
||||
if !cfg!(target_arch = "wasm32") {
|
||||
actions.file.quit.button(ctx, ui);
|
||||
}
|
||||
actions.file.render_menu(ctx, ui, maybe_workspace.is_some())
|
||||
});
|
||||
|
||||
ui.menu_button(tr.text("tr-menu-edit"), |ui| {
|
||||
ui.add_enabled_ui(maybe_workspace.is_some(), |ui| {
|
||||
actions.edit.undo.button(ctx, ui);
|
||||
actions.edit.redo.button(ctx, ui);
|
||||
|
||||
ui.separator();
|
||||
|
||||
actions.edit.abort.button(ctx, ui);
|
||||
|
||||
ui.separator();
|
||||
|
||||
//ui.add_enabled_ui(workspace_activities_enabled, |ui| {
|
||||
actions.edit.remove_bands.button(ctx, ui);
|
||||
//});
|
||||
});
|
||||
actions.edit.render_menu(
|
||||
ctx,
|
||||
ui,
|
||||
maybe_workspace.is_some(),
|
||||
workspace_activities_enabled,
|
||||
)
|
||||
});
|
||||
|
||||
self.update_view_menu(ctx, ui, tr, viewport);
|
||||
|
|
@ -127,69 +104,35 @@ impl MenuBar {
|
|||
// those outside...
|
||||
|
||||
ui.menu_button(tr.text("tr-menu-place"), |ui| {
|
||||
ui.add_enabled_ui(maybe_workspace.is_some(), |ui| {
|
||||
actions.place.place_via.toggle_widget(
|
||||
ctx,
|
||||
ui,
|
||||
&mut self.is_placing_via,
|
||||
);
|
||||
});
|
||||
actions.place.render_menu(
|
||||
ctx,
|
||||
ui,
|
||||
maybe_workspace.is_some(),
|
||||
&mut self.is_placing_via,
|
||||
)
|
||||
});
|
||||
|
||||
ui.menu_button(tr.text("tr-menu-route"), |ui| {
|
||||
ui.add_enabled_ui(maybe_workspace.is_some(), |ui| {
|
||||
//ui.add_enabled_ui(workspace_activities_enabled, |ui| {
|
||||
actions.route.autoroute.button(ctx, ui);
|
||||
//});
|
||||
ui.separator();
|
||||
|
||||
ui.label(tr.text("tr-menu-route-routed-band-width"));
|
||||
|
||||
ui.add(
|
||||
egui::widgets::Slider::new(
|
||||
&mut self.autorouter_options.router_options.routed_band_width,
|
||||
1.0..=1000.0,
|
||||
)
|
||||
.suffix(""),
|
||||
);
|
||||
|
||||
ui.separator();
|
||||
|
||||
ui.menu_button(tr.text("tr-menu-options"), |ui| {
|
||||
ui.checkbox(
|
||||
&mut self.autorouter_options.presort_by_pairwise_detours,
|
||||
tr.text("tr-menu-route-options-presort-by-pairwise-detours"),
|
||||
);
|
||||
ui.checkbox(
|
||||
&mut self
|
||||
.autorouter_options
|
||||
.router_options
|
||||
.squeeze_through_under_bends,
|
||||
tr.text("tr-menu-route-options-squeeze-through-under-bends"),
|
||||
);
|
||||
ui.checkbox(
|
||||
&mut self.autorouter_options.router_options.wrap_around_bands,
|
||||
tr.text("tr-menu-route-options-wrap-around-bands"),
|
||||
);
|
||||
});
|
||||
});
|
||||
actions.route.render_menu(
|
||||
ctx,
|
||||
ui,
|
||||
tr,
|
||||
maybe_workspace.is_some(),
|
||||
workspace_activities_enabled,
|
||||
&mut self.autorouter_options,
|
||||
)
|
||||
});
|
||||
|
||||
ui.menu_button(tr.text("tr-menu-inspect"), |ui| {
|
||||
ui.add_enabled_ui(workspace_activities_enabled, |ui| {
|
||||
actions.inspect.compare_detours.button(ctx, ui);
|
||||
actions.inspect.measure_length.button(ctx, ui);
|
||||
});
|
||||
actions
|
||||
.inspect
|
||||
.render_menu(ctx, ui, workspace_activities_enabled);
|
||||
});
|
||||
|
||||
self.update_preferences_menu(ctx, ui, tr);
|
||||
|
||||
ui.menu_button(tr.text("tr-menu-help"), |ui| {
|
||||
actions.help.online_documentation.hyperlink(
|
||||
ctx,
|
||||
ui,
|
||||
online_documentation_url,
|
||||
);
|
||||
actions.help.render_menu(ctx, ui, online_documentation_url)
|
||||
});
|
||||
|
||||
ui.separator();
|
||||
|
|
|
|||
Loading…
Reference in New Issue