From fa29265150bbbcf0b45616884d995e27cfa15763 Mon Sep 17 00:00:00 2001 From: Rubén Beltrán del Río Date: Sat, 27 Dec 2025 15:24:27 +0100 Subject: Add keyboard shortcuts --- src/main.rs | 56 +++++++++++++++++++++++++++++++++++++++++++------------- src/stages.rs | 34 ---------------------------------- 2 files changed, 43 insertions(+), 47 deletions(-) (limited to 'src') diff --git a/src/main.rs b/src/main.rs index 562530d..1bf0e71 100644 --- a/src/main.rs +++ b/src/main.rs @@ -11,6 +11,7 @@ use crate::icon_names::shipped::{ }; use cairo::ImageSurface; use gtk::prelude::*; +use gtk::{gdk, glib}; use relm4::{ComponentParts, ComponentSender, RelmApp, RelmWidgetExt, SimpleComponent, gtk}; use sourceview5::LanguageManager; use sourceview5::prelude::{BufferExt, TextBufferExt, TextViewExt}; @@ -40,6 +41,7 @@ enum AppAction { Zoom(f64), ZoomOut, ZoomIn, + ExportImage } impl AppModel { @@ -83,6 +85,30 @@ impl SimpleComponent for AppModel { set_default_width: 300, set_default_height: 100, + add_controller = gtk::EventControllerKey::new() { + connect_key_pressed[sender] => move |_, key, _, modifier| { + match (key, modifier) { + (gdk::Key::plus | gdk::Key::equal, gdk::ModifierType::CONTROL_MASK) => { + sender.input(AppAction::ZoomIn); + glib::Propagation::Stop + }, + (gdk::Key::minus, gdk::ModifierType::CONTROL_MASK) => { + sender.input(AppAction::ZoomOut); + glib::Propagation::Stop + }, + (gdk::Key::l, gdk::ModifierType::CONTROL_MASK) => { + sender.input(AppAction::ChangeOrientation); + glib::Propagation::Stop + }, + (gdk::Key::e, gdk::ModifierType::CONTROL_MASK) => { + sender.input(AppAction::ExportImage); + glib::Propagation::Stop + }, + _ => glib::Propagation::Proceed + } + } + }, + gtk::Box { set_orientation: gtk::Orientation::Vertical, set_spacing: 0, @@ -100,14 +126,15 @@ impl SimpleComponent for AppModel { gtk::Orientation::Horizontal => SPLIT_VERTICAL_REGULAR, _ => SPLIT_HORIZONTAL_REGULAR }, - connect_clicked => AppAction::ChangeOrientation + connect_clicked => AppAction::ChangeOrientation, } }, pack_end = >k::Box { set_orientation: gtk::Orientation::Horizontal, - gtk::Button::with_label("Print") { - set_icon_name: IMAGE_REGULAR + gtk::Button::with_label("Export as Image") { + set_icon_name: IMAGE_REGULAR, + connect_clicked => AppAction::ExportImage }, gtk::DropDown { @@ -147,11 +174,6 @@ impl SimpleComponent for AppModel { set_content_height: model.surface_height } } - - // #[wrap(Some)] - // set_end_child = >k::DrawingArea { - // set_expand: true - // } }, gtk::ActionBar { @@ -228,20 +250,26 @@ impl SimpleComponent for AppModel { } let drawing_area = gtk::DrawingArea::new(); + let map = parse(""); + let mut render_configuration = Configuration::default(); + let stage_type = StageType::Activities; + render_configuration.options.smart_label_positioning = true; + let surface = render_to_surface(&map, stage_type, &render_configuration).unwrap(); - let model = AppModel { + let mut model = AppModel { orientation: gtk::Orientation::Horizontal, stage_type_list, - stage_type: StageType::Practice, + stage_type, source, - map: parse(""), + map, zoom, - render_configuration: Configuration::default(), - surface: ImageSurface::create(cairo::Format::ARgb32, 0, 0).unwrap(), + render_configuration, + surface, surface_width: 0, surface_height: 0, drawing_area: drawing_area.clone(), }; + model.update_image(); let widgets = view_output!(); @@ -286,6 +314,8 @@ impl SimpleComponent for AppModel { self.update_image(); } } + AppAction::ExportImage => { + } } } } diff --git a/src/stages.rs b/src/stages.rs index 9584c68..0ff0adf 100644 --- a/src/stages.rs +++ b/src/stages.rs @@ -24,37 +24,3 @@ pub fn all_stages() -> &'static [StageType] { StageType::Behavior, ] } - -pub fn types() -> &'static [StageType] { - &[ - StageType::Activities, - StageType::Practice, - StageType::Data, - StageType::Knowledge, - ] -} - -pub fn characteristics() -> &'static [StageType] { - &[ - StageType::Ubiquity, - StageType::Certainty, - StageType::PublicationTypes, - ] -} - -pub fn properties() -> &'static [StageType] { - &[ - StageType::Market, - StageType::KnowledgeManagement, - StageType::MarketPerception, - StageType::UserPerception, - StageType::PerceptionInIndustry, - StageType::FocusOfValue, - StageType::Understanding, - StageType::Comparison, - StageType::Failure, - StageType::MarketAction, - StageType::Efficiency, - StageType::DecisionDrivers, - ] -} -- cgit