-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This allows the user to change the text size via keyboard, scrolling, zoom gesture and from the primary menu.
- Loading branch information
Showing
8 changed files
with
290 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
mod zoom_level_selector; | ||
|
||
pub use self::zoom_level_selector::ZoomLevelSelector; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
/* zoom_level_selector.rs | ||
* | ||
* Copyright 2025 Julian Sparber <[email protected]> | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
* | ||
* SPDX-License-Identifier: GPL-3.0-or-later | ||
*/ | ||
use std::cell::Cell; | ||
|
||
use adw::subclass::prelude::*; | ||
use gtk::prelude::*; | ||
use gtk::glib; | ||
use sourceview::*; | ||
|
||
mod imp { | ||
use super::*; | ||
|
||
#[derive(Debug, Default, glib::Properties, gtk::CompositeTemplate)] | ||
#[properties(wrapper_type = super::ZoomLevelSelector)] | ||
#[template(resource = "/org/p2panda/aardvark/components/zoom_level_selector.ui")] | ||
pub struct ZoomLevelSelector { | ||
#[template_child] | ||
pub button: TemplateChild<gtk::Button>, | ||
#[property(get, set)] | ||
zoom_level: Cell<f64>, | ||
} | ||
|
||
#[glib::object_subclass] | ||
impl ObjectSubclass for ZoomLevelSelector { | ||
const NAME: &'static str = "ZoomLevelSelector"; | ||
type Type = super::ZoomLevelSelector; | ||
type ParentType = gtk::Box; | ||
|
||
fn class_init(klass: &mut Self::Class) { | ||
klass.bind_template(); | ||
} | ||
|
||
fn instance_init(obj: &glib::subclass::InitializingObject<Self>) { | ||
obj.init_template(); | ||
} | ||
} | ||
|
||
#[glib::derived_properties] | ||
impl ObjectImpl for ZoomLevelSelector { | ||
fn constructed(&self) { | ||
self.parent_constructed(); | ||
self.obj() | ||
.bind_property("zoom_level", &*self.button, "label") | ||
.sync_create() | ||
.transform_to(|_, zoom_level: f64| Some(format!("{:.0}%", zoom_level * 100.0))) | ||
.build(); | ||
} | ||
} | ||
|
||
impl WidgetImpl for ZoomLevelSelector {} | ||
impl BoxImpl for ZoomLevelSelector {} | ||
} | ||
|
||
glib::wrapper! { | ||
pub struct ZoomLevelSelector(ObjectSubclass<imp::ZoomLevelSelector>) | ||
@extends gtk::Widget, gtk::Box; | ||
} | ||
|
||
impl ZoomLevelSelector { | ||
pub fn new() -> Self { | ||
glib::Object::builder() | ||
.build() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<interface> | ||
<requires lib="gtk" version="4.0"/> | ||
<template class="ZoomLevelSelector" parent="GtkBox"> | ||
<property name="hexpand">True</property> | ||
<child> | ||
<object class="GtkBox"> | ||
<property name="spacing">12</property> | ||
<property name="margin-start">18</property> | ||
<property name="margin-end">18</property> | ||
<child> | ||
<object class="GtkButton"> | ||
<property name="icon-name">zoom-out-symbolic</property> | ||
<!-- Translators: Button tooltip--> | ||
<property name="tooltip-text" translatable="yes">Zoom Out</property> | ||
<property name="action-name">window.zoom-out</property> | ||
<accessibility> | ||
<!-- Translators: Button --> | ||
<property name="label" translatable="yes">Zoom Out</property> | ||
</accessibility> | ||
<style> | ||
<class name="circular"/> | ||
<class name="flat"/> | ||
</style> | ||
</object> | ||
</child> | ||
<child> | ||
<object class="GtkButton" id="button"> | ||
<property name="hexpand">True</property> | ||
<property name="action-name">window.zoom-one</property> | ||
<style> | ||
<class name="circular"/> | ||
<class name="flat"/> | ||
</style> | ||
</object> | ||
</child> | ||
<child> | ||
<object class="GtkButton"> | ||
<property name="icon-name">zoom-in-symbolic</property> | ||
<!-- Translators: Button tooltip--> | ||
<property name="tooltip-text" translatable="yes">Zoom In</property> | ||
<property name="action-name">window.zoom-in</property> | ||
<accessibility> | ||
<!-- Translators: Button --> | ||
<property name="label" translatable="yes">Zoom In</property> | ||
</accessibility> | ||
<style> | ||
<class name="circular"/> | ||
<class name="flat"/> | ||
</style> | ||
</object> | ||
</child> | ||
</object> | ||
</child> | ||
</template> | ||
</interface> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,6 +20,7 @@ | |
|
||
mod application; | ||
mod config; | ||
mod components; | ||
mod document; | ||
mod textbuffer; | ||
mod window; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,7 +13,3 @@ | |
.user-counter { | ||
font-weight: bold; | ||
} | ||
|
||
.editor { | ||
font-size: 24px; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.