diff options
| author | Rubén Beltrán del Río <jj@r.bdr.sh> | 2025-12-27 15:24:27 +0100 |
|---|---|---|
| committer | Rubén Beltrán del Río <jj@r.bdr.sh> | 2025-12-28 15:14:20 +0100 |
| commit | fa29265150bbbcf0b45616884d995e27cfa15763 (patch) | |
| tree | 2f0c23df910bda4ba07b8b430a6da86a260cf842 /src/main.rs | |
| parent | 9129c8bc3376cc6014dd97113ceb9ff189d5e411 (diff) | |
Add keyboard shortcuts
Diffstat (limited to 'src/main.rs')
| -rw-r--r-- | src/main.rs | 56 |
1 files changed, 43 insertions, 13 deletions
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 => { + } } } } |