-
-
Notifications
You must be signed in to change notification settings - Fork 471
Expand file tree
/
Copy pathcanvasmenu.rs
More file actions
111 lines (95 loc) · 3.2 KB
/
Copy pathcanvasmenu.rs
File metadata and controls
111 lines (95 loc) · 3.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
// Imports
use crate::appwindow::RnAppWindow;
use gtk4::{
Button, CompositeTemplate, MenuButton, PopoverMenu, Widget, gio, glib, prelude::*,
subclass::prelude::*,
};
use rnote_engine::Camera;
mod imp {
use super::*;
#[derive(Default, Debug, CompositeTemplate)]
#[template(resource = "/com/github/flxzt/rnote/ui/canvasmenu.ui")]
pub(crate) struct RnCanvasMenu {
#[template_child]
pub(crate) menubutton: TemplateChild<MenuButton>,
#[template_child]
pub(crate) popovermenu: TemplateChild<PopoverMenu>,
#[template_child]
pub(crate) menu_model: TemplateChild<gio::MenuModel>,
#[template_child]
pub(crate) zoom_in_button: TemplateChild<Button>,
#[template_child]
pub(crate) zoom_out_button: TemplateChild<Button>,
#[template_child]
pub(crate) zoom_reset_button: TemplateChild<Button>,
#[template_child]
pub(crate) zoom_fit_width_button: TemplateChild<Button>,
#[template_child]
pub(crate) zoom_real_width_button: TemplateChild<Button>,
#[template_child]
pub(crate) fixedsize_quickactions_box: TemplateChild<gtk4::Box>,
}
#[glib::object_subclass]
impl ObjectSubclass for RnCanvasMenu {
const NAME: &'static str = "RnCanvasMenu";
type Type = super::RnCanvasMenu;
type ParentType = Widget;
fn class_init(klass: &mut Self::Class) {
klass.bind_template();
}
fn instance_init(obj: &glib::subclass::InitializingObject<Self>) {
obj.init_template();
}
}
impl ObjectImpl for RnCanvasMenu {
fn constructed(&self) {
self.parent_constructed();
self.menubutton
.get()
.set_popover(Some(&self.popovermenu.get()));
}
fn dispose(&self) {
self.dispose_template();
while let Some(child) = self.obj().first_child() {
child.unparent();
}
}
}
impl WidgetImpl for RnCanvasMenu {
fn size_allocate(&self, width: i32, height: i32, baseline: i32) {
self.parent_size_allocate(width, height, baseline);
self.popovermenu.get().present();
}
}
}
glib::wrapper! {
pub(crate) struct RnCanvasMenu(ObjectSubclass<imp::RnCanvasMenu>)
@extends Widget,
@implements gtk4::Accessible, gtk4::Buildable, gtk4::ConstraintTarget;
}
impl Default for RnCanvasMenu {
fn default() -> Self {
Self::new()
}
}
impl RnCanvasMenu {
pub(crate) fn new() -> Self {
glib::Object::new()
}
pub(crate) fn popovermenu(&self) -> PopoverMenu {
self.imp().popovermenu.get()
}
pub(crate) fn fixedsize_quickactions_box(&self) -> gtk4::Box {
self.imp().fixedsize_quickactions_box.get()
}
pub(crate) fn init(&self, _appwindow: &RnAppWindow) {
self.imp()
.zoom_reset_button
.set_label(format!("{:.0}%", (100.0 * Camera::ZOOM_DEFAULT).round()).as_str());
}
pub(crate) fn refresh_zoom_reset_label(&self, zoom: f64) {
self.imp()
.zoom_reset_button
.set_label(format!("{:.0}%", (100.0 * zoom).round()).as_str());
}
}