mirror of https://codeberg.org/topola/topola.git
feat(egui): move View menu code to actions
This commit is contained in:
parent
ebeaaf04c9
commit
babe531f73
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
pub struct Action {
|
||||
name: String,
|
||||
shortcut: egui::KeyboardShortcut,
|
||||
shortcut: Option<egui::KeyboardShortcut>,
|
||||
}
|
||||
|
||||
pub struct Trigger {
|
||||
|
|
@ -20,16 +20,27 @@ impl Action {
|
|||
pub fn new(name: String, modifiers: egui::Modifiers, key: egui::Key) -> Self {
|
||||
Self {
|
||||
name,
|
||||
shortcut: egui::KeyboardShortcut::new(modifiers, key),
|
||||
shortcut: Some(egui::KeyboardShortcut::new(modifiers, key)),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn new_keyless(name: String) -> Self {
|
||||
Self {
|
||||
name,
|
||||
shortcut: None,
|
||||
}
|
||||
}
|
||||
|
||||
fn widget_text(&self) -> String {
|
||||
if let Some(shortcut) = self.shortcut {
|
||||
format!(
|
||||
"{} ({})",
|
||||
self.name,
|
||||
self.shortcut.format(&egui::ModifierNames::NAMES, false)
|
||||
shortcut.format(&egui::ModifierNames::NAMES, false)
|
||||
)
|
||||
} else {
|
||||
format!("{}", self.name)
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
|
|
@ -61,10 +72,12 @@ impl Trigger {
|
|||
}
|
||||
|
||||
fn consume_key(&mut self, ctx: &egui::Context, _ui: &mut egui::Ui) {
|
||||
if ctx.input_mut(|i| i.consume_shortcut(&self.action.shortcut)) {
|
||||
if let Some(shortcut) = self.action.shortcut {
|
||||
if ctx.input_mut(|i| i.consume_shortcut(&shortcut)) {
|
||||
self.triggered = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn triggered(&self) -> bool {
|
||||
self.triggered
|
||||
|
|
@ -82,9 +95,11 @@ impl Switch {
|
|||
_ui: &mut egui::Ui,
|
||||
selected: &mut bool,
|
||||
) -> bool {
|
||||
if ctx.input_mut(|i| i.consume_shortcut(&self.action.shortcut)) {
|
||||
if let Some(shortcut) = self.action.shortcut {
|
||||
if ctx.input_mut(|i| i.consume_shortcut(&shortcut)) {
|
||||
*selected = !*selected;
|
||||
}
|
||||
}
|
||||
|
||||
*selected
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,7 +4,9 @@
|
|||
|
||||
use crate::{
|
||||
action::{Action, Switch, Trigger},
|
||||
menu_bar::MenuBar,
|
||||
translator::Translator,
|
||||
viewport::Viewport,
|
||||
};
|
||||
|
||||
use egui::{Context, Ui};
|
||||
|
|
@ -154,6 +156,73 @@ impl EditActions {
|
|||
}
|
||||
}
|
||||
|
||||
pub struct ViewActions {
|
||||
pub zoom_to_fit: Switch,
|
||||
pub show_ratsnest: Switch,
|
||||
pub show_navmesh: Switch,
|
||||
pub show_bboxes: Switch,
|
||||
pub show_origin_destination: Switch,
|
||||
pub show_appearance_panel: Switch,
|
||||
}
|
||||
|
||||
impl ViewActions {
|
||||
pub fn new(tr: &Translator) -> Self {
|
||||
Self {
|
||||
zoom_to_fit: Action::new_keyless(tr.text("tr-menu-view-zoom-to-fit")).into_switch(),
|
||||
show_ratsnest: Action::new_keyless(tr.text("tr-menu-view-show-ratsnest")).into_switch(),
|
||||
show_navmesh: Action::new_keyless(tr.text("tr-menu-view-show-navmesh")).into_switch(),
|
||||
show_bboxes: Action::new_keyless(tr.text("tr-menu-view-show-bboxes")).into_switch(),
|
||||
show_origin_destination: Action::new_keyless(
|
||||
tr.text("tr-menu-view-show-origin-destination"),
|
||||
)
|
||||
.into_switch(),
|
||||
show_appearance_panel: Action::new_keyless(tr.text("tr-menu-view-show-layer-manager"))
|
||||
.into_switch(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn render_menu(
|
||||
&mut self,
|
||||
ctx: &Context,
|
||||
ui: &mut Ui,
|
||||
tr: &Translator,
|
||||
menu_bar: &mut MenuBar,
|
||||
viewport: &mut Viewport,
|
||||
) {
|
||||
ui.toggle_value(
|
||||
&mut viewport.scheduled_zoom_to_fit,
|
||||
tr.text("tr-menu-view-zoom-to-fit"),
|
||||
);
|
||||
|
||||
ui.separator();
|
||||
|
||||
//ui.add_enabled_ui(maybe_workspace.is_some(), |ui| {
|
||||
ui.checkbox(
|
||||
&mut menu_bar.show_ratsnest,
|
||||
tr.text("tr-menu-view-show-ratsnest"),
|
||||
);
|
||||
ui.checkbox(
|
||||
&mut menu_bar.show_navmesh,
|
||||
tr.text("tr-menu-view-show-navmesh"),
|
||||
);
|
||||
ui.checkbox(
|
||||
&mut menu_bar.show_bboxes,
|
||||
tr.text("tr-menu-view-show-bboxes"),
|
||||
);
|
||||
ui.checkbox(
|
||||
&mut menu_bar.show_origin_destination,
|
||||
tr.text("tr-menu-view-show-origin-destination"),
|
||||
);
|
||||
|
||||
ui.separator();
|
||||
|
||||
ui.checkbox(
|
||||
&mut menu_bar.show_appearance_panel,
|
||||
tr.text("tr-menu-view-show-layer-manager"),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
pub struct PlaceActions {
|
||||
pub place_via: Switch,
|
||||
}
|
||||
|
|
@ -302,6 +371,7 @@ impl HelpActions {
|
|||
pub struct Actions {
|
||||
pub file: FileActions,
|
||||
pub edit: EditActions,
|
||||
pub view: ViewActions,
|
||||
pub place: PlaceActions,
|
||||
pub route: RouteActions,
|
||||
pub inspect: InspectActions,
|
||||
|
|
@ -313,6 +383,7 @@ impl Actions {
|
|||
Self {
|
||||
file: FileActions::new(tr),
|
||||
edit: EditActions::new(tr),
|
||||
view: ViewActions::new(tr),
|
||||
place: PlaceActions::new(tr),
|
||||
route: RouteActions::new(tr),
|
||||
inspect: InspectActions::new(tr),
|
||||
|
|
|
|||
|
|
@ -2,20 +2,17 @@
|
|||
//
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
use std::{borrow::Cow, ops::ControlFlow, path::Path, sync::mpsc::Sender};
|
||||
use std::{ops::ControlFlow, path::Path, sync::mpsc::Sender};
|
||||
|
||||
use topola::{
|
||||
autorouter::{
|
||||
execution::Command, invoker::InvokerError, selection::Selection, AutorouterOptions,
|
||||
},
|
||||
interactor::activity::{ActivityContext, ActivityStepperWithStatus, InteractiveInput},
|
||||
router::RouterOptions,
|
||||
specctra::{design::SpecctraDesign, ParseError, ParseErrorContext as SpecctraLoadingError},
|
||||
stepper::Abort,
|
||||
};
|
||||
|
||||
use crate::{
|
||||
action::{Action, Switch, Trigger},
|
||||
actions::Actions,
|
||||
app::{execute, handle_file},
|
||||
translator::Translator,
|
||||
|
|
@ -96,7 +93,17 @@ impl MenuBar {
|
|||
)
|
||||
});
|
||||
|
||||
self.update_view_menu(ctx, ui, tr, viewport);
|
||||
ui.menu_button(tr.text("tr-menu-view"), |ui| {
|
||||
actions.view.render_menu(ctx, ui, tr, self, viewport);
|
||||
|
||||
ui.separator();
|
||||
|
||||
ui.label(tr.text("tr-menu-view-frame-timestep"));
|
||||
ui.add(
|
||||
egui::widgets::Slider::new(&mut self.frame_timestep, 0.0..=3.0)
|
||||
.suffix(" s"),
|
||||
);
|
||||
});
|
||||
|
||||
// NOTE: we could disable the entire range of menus below
|
||||
// when no workspace is loaded, but that would disrupt "hover-scrolling"
|
||||
|
|
@ -283,48 +290,6 @@ impl MenuBar {
|
|||
.inner
|
||||
}
|
||||
|
||||
pub fn update_view_menu(
|
||||
&mut self,
|
||||
_ctx: &egui::Context,
|
||||
ui: &mut egui::Ui,
|
||||
tr: &Translator,
|
||||
viewport: &mut Viewport,
|
||||
) {
|
||||
ui.menu_button(tr.text("tr-menu-view"), |ui| {
|
||||
ui.toggle_value(
|
||||
&mut viewport.scheduled_zoom_to_fit,
|
||||
tr.text("tr-menu-view-zoom-to-fit"),
|
||||
);
|
||||
|
||||
ui.separator();
|
||||
|
||||
//ui.add_enabled_ui(maybe_workspace.is_some(), |ui| {
|
||||
ui.checkbox(
|
||||
&mut self.show_ratsnest,
|
||||
tr.text("tr-menu-view-show-ratsnest"),
|
||||
);
|
||||
ui.checkbox(&mut self.show_navmesh, tr.text("tr-menu-view-show-navmesh"));
|
||||
ui.checkbox(&mut self.show_bboxes, tr.text("tr-menu-view-show-bboxes"));
|
||||
ui.checkbox(
|
||||
&mut self.show_origin_destination,
|
||||
tr.text("tr-menu-view-show-origin-destination"),
|
||||
);
|
||||
|
||||
ui.separator();
|
||||
|
||||
ui.checkbox(
|
||||
&mut self.show_appearance_panel,
|
||||
tr.text("tr-menu-view-show-layer-manager"),
|
||||
);
|
||||
|
||||
ui.separator();
|
||||
//});
|
||||
|
||||
ui.label(tr.text("tr-menu-view-frame-timestep"));
|
||||
ui.add(egui::widgets::Slider::new(&mut self.frame_timestep, 0.0..=3.0).suffix(" s"));
|
||||
});
|
||||
}
|
||||
|
||||
pub fn update_preferences_menu(ctx: &egui::Context, ui: &mut egui::Ui, tr: &mut Translator) {
|
||||
ui.menu_button(tr.text("tr-menu-preferences"), |ui| {
|
||||
ui.menu_button(tr.text("tr-menu-preferences-set-language"), |ui| {
|
||||
|
|
|
|||
Loading…
Reference in New Issue