diff options
| author | Rubén Beltrán del Río <jj@r.bdr.sh> | 2026-03-26 23:18:11 +0100 |
|---|---|---|
| committer | Rubén Beltrán del Río <jj@r.bdr.sh> | 2026-03-26 23:26:01 +0100 |
| commit | 1f28cbdf1dbe26e4c7da27323a0202a3276cb3a7 (patch) | |
| tree | f5a707ed5671d0345b21c935f5a46099b12b8f19 /src/components | |
| parent | 9a472115e594e28f4e3bd95b10800bf2b690febf (diff) | |
Move footer to its own component
Diffstat (limited to 'src/components')
| -rw-r--r-- | src/components/footer.rs | 97 | ||||
| -rw-r--r-- | src/components/mod.rs | 1 |
2 files changed, 98 insertions, 0 deletions
diff --git a/src/components/footer.rs b/src/components/footer.rs new file mode 100644 index 0000000..2576163 --- /dev/null +++ b/src/components/footer.rs @@ -0,0 +1,97 @@ +use gtk::prelude::*; +use relm4::prelude::*; +use relm4::actions::ActionablePlus; + +use crate::tr; +use crate::constants; + +use crate::{ + ZoomInAction, ZoomOutAction, actions::Action +}; +use crate::icon_names::shipped::{ ZOOM_IN_REGULAR, ZOOM_OUT_REGULAR }; + +// Model and Input Messages + +pub struct Footer { + zoom: f64, +} + +pub struct FooterInit { + pub zoom: f64, +} + +#[derive(Debug, Clone)] +pub enum FooterAction { + SetZoom(f64) +} + +#[relm4::component(pub)] +impl SimpleComponent for Footer { + type Init = FooterInit; + type Input = FooterAction; + type Output = Action; + + view! { + >k::ActionBar { + pack_end = >k::Box { + set_orientation: gtk::Orientation::Horizontal, + + gtk::Label { + #[watch] + set_label: &format!("{:.1}x", model.zoom), + set_margin_end: 5 + }, + + gtk::Button::with_label(&tr!("command.view.zoom_out")) { + set_icon_name: ZOOM_OUT_REGULAR, + set_margin_end: 5, + add_css_class: "flat", + add_css_class: "zoom", + add_css_class: "zoom-out", + ActionablePlus::set_stateless_action::<ZoomOutAction>: &(), + }, + + gtk::Scale { + set_orientation: gtk::Orientation::Horizontal, + set_range: (constants::MIN_ZOOM, constants::MAX_ZOOM), + #[watch] + set_value: model.zoom, + set_draw_value: false, + set_increments: (constants::ZOOM_STEP, constants::ZOOM_STEP), + set_value_pos: gtk::PositionType::Left, + set_width_request: 100, + connect_value_changed[sender] => move |scale| { + let _ = sender.output(Action::Zoom(scale.value())); + } + }, + + gtk::Button::with_label(&tr!("command.view.zoom_in")) { + set_icon_name: ZOOM_IN_REGULAR, + add_css_class: "flat", + add_css_class: "zoom", + add_css_class: "zoom-in", + ActionablePlus::set_stateless_action::<ZoomInAction>: &(), + }, + } + } + } + + fn init( + init: Self::Init, + root: Self::Root, + sender: ComponentSender<Self>, + ) -> ComponentParts<Self> { + let model = Footer { + zoom: init.zoom + }; + let widgets = view_output!(); + + ComponentParts { model, widgets } + } + + fn update(&mut self, message: Self::Input, _sender: ComponentSender<Self>) { + match message { + FooterAction::SetZoom(zoom) => self.zoom = zoom + } + } +} diff --git a/src/components/mod.rs b/src/components/mod.rs index d32bbea..1194b9f 100644 --- a/src/components/mod.rs +++ b/src/components/mod.rs @@ -13,4 +13,5 @@ // You should have received a copy of the GNU Affero General Public License // along with this program. If not, see <http://www.gnu.org/licenses/>. +pub mod footer; pub mod header; |