Commit 56404439 authored by Bilal Elmoussaoui's avatar Bilal Elmoussaoui
Browse files

prepare for next gtk-rs release

parent 7f5767bd
Pipeline #333027 passed with stage
in 16 minutes and 22 seconds
This diff is collapsed.
......@@ -5,12 +5,12 @@ authors = ["Bilal Elmoussaoui <bil.elmoussaoui@gmail.com>"]
edition = "2018"
[dependencies]
gtk = { package = "gtk4", version = "0.3" }
gtk = { package = "gtk4", git = "https://github.com/gtk-rs/gtk4-rs.git" }
log = "0.4"
gettext-rs= { version = "0.7", features = ["gettext-system"] }
pretty_env_logger = "0.4"
anyhow = "1.0"
gtk-macros = "0.3"
adw = {package = "libadwaita", version = "0.1.0-alpha-6"}
adw = {package = "libadwaita", git = "https://gitlab.gnome.org/world/rust/libadwaita-rs"}
once_cell = "1.8"
gdk-pixbuf = { version = "0.14", features = ["v2_36"]}
gdk-pixbuf = {git = "https://github.com/gtk-rs/gtk-rs-core", features = ["v2_36"]}
......@@ -3,7 +3,7 @@
export MESON_BUILD_ROOT="$1"
export MESON_SOURCE_ROOT="$2"
export CARGO_TARGET_DIR="$MESON_BUILD_ROOT"/target
export CARGO_HOME="$CARGO_TARGET_DIR"/cargo-home
export CARGO_HOME="$MESON_BUILD_ROOT"/cargo-home
if [[ $4 = "development" ]]; then
echo "DEBUG MODE"
......
......@@ -3,9 +3,8 @@ use crate::widgets::{View, Window};
use adw::{prelude::*, subclass::prelude::*};
use gettextrs::gettext;
use gtk::{
gdk, gio,
gio,
glib::{self, clone},
prelude::*,
subclass::prelude::*,
};
use gtk_macros::action;
......@@ -14,17 +13,11 @@ use log::info;
mod imp {
use super::*;
#[derive(Debug)]
#[derive(Default, Debug)]
pub struct Application {
pub windows: gtk::WindowGroup,
}
impl Default for Application {
fn default() -> Self {
Self { windows: gtk::WindowGroup::new() }
}
}
#[glib::object_subclass]
impl ObjectSubclass for Application {
const NAME: &'static str = "Application";
......
......@@ -17,11 +17,7 @@ pub enum Filter {
mod imp {
use super::*;
use glib::{
object::{Interface, InterfaceRef},
subclass::Signal,
ParamFlags, ParamSpec,
};
use glib::{subclass::Signal, ParamFlags, ParamSpec};
use once_cell::sync::Lazy;
use std::cell::{Cell, RefCell};
......@@ -110,7 +106,7 @@ mod imp {
let vadj = obj.vadjustment().unwrap();
let new_scroll = (hadj.value(), vadj.value());
obj.set_property("zoom", &(self_.zoom.get() * change)).unwrap();
obj.set_property("zoom", &(self_.zoom.get() * change));
self_.queued_scroll.replace(Some(new_scroll));
self_.scale_factor.set(obj.scale_factor());
......@@ -201,7 +197,7 @@ mod imp {
drop.read_value_async(
String::static_type(),
glib::PRIORITY_DEFAULT,
gio::NONE_CANCELLABLE,
gio::Cancellable::NONE,
clone!(@weak drop, @weak this => move |val| {
if let Ok(uri) = val.map(|v| v.get::<String>().unwrap()) {
let file = gio::File::for_uri(&uri);
......@@ -221,17 +217,16 @@ mod imp {
fn properties() -> &'static [ParamSpec] {
static PROPERTIES: Lazy<Vec<ParamSpec>> = Lazy::new(|| {
let interface: InterfaceRef<gtk::Scrollable> = Interface::from_type(gtk::Scrollable::static_type()).unwrap();
vec![
ParamSpec::new_boolean("can-undo", "Can undo", "whether you can undo", false, ParamFlags::READWRITE),
ParamSpec::new_boolean("can-redo", "Can redo", "whether you can redo", false, ParamFlags::READWRITE),
ParamSpec::new_double("zoom", "Zoom", "Current zoom level", 0.0, f64::INFINITY, 1.0, ParamFlags::READWRITE),
ParamSpec::new_enum("filter", "Filter", "The applied filter", Filter::static_type(), Filter::Blur as i32, ParamFlags::READWRITE),
// Scrollable properties
ParamSpec::new_override("hscroll-policy", &interface.find_property("hscroll-policy").unwrap()),
ParamSpec::new_override("vscroll-policy", &interface.find_property("vscroll-policy").unwrap()),
ParamSpec::new_override("hadjustment", &interface.find_property("hadjustment").unwrap()),
ParamSpec::new_override("vadjustment", &interface.find_property("vadjustment").unwrap()),
ParamSpec::new_override_interface::<gtk::Scrollable>("hscroll-policy"),
ParamSpec::new_override_interface::<gtk::Scrollable>("vscroll-policy"),
ParamSpec::new_override_interface::<gtk::Scrollable>("hadjustment"),
ParamSpec::new_override_interface::<gtk::Scrollable>("vadjustment"),
]
});
PROPERTIES.as_ref()
......@@ -334,7 +329,7 @@ mod imp {
snapshot.append_border(
&gsk::RoundedRect::from_rect(selection_rect, 0.0),
&[1.0, 1.0, 1.0, 1.0],
&[gdk::RGBA::black(), gdk::RGBA::black(), gdk::RGBA::black(), gdk::RGBA::black()],
&[gdk::RGBA::BLACK, gdk::RGBA::BLACK, gdk::RGBA::BLACK, gdk::RGBA::BLACK],
);
}
}
......@@ -369,7 +364,7 @@ impl DrawingArea {
}
pub fn zoom(&self) -> f64 {
self.property("zoom").unwrap().get().unwrap()
self.property("zoom")
}
fn effective_zoom(&self) -> f64 {
......@@ -432,8 +427,8 @@ impl DrawingArea {
self_.start_position.replace(None);
self_.current_position.replace(None);
self_.initial_zoom_center.replace(None);
self.set_property("can-undo", &false).unwrap();
self.set_property("can-redo", &false).unwrap();
self.set_property("can-undo", &false);
self.set_property("can-redo", &false);
self.set_zoom(1.0);
self_.queued_scroll.replace(Some((0.0, 0.0)));
self.queue_allocate();
......@@ -449,7 +444,7 @@ impl DrawingArea {
let self_ = imp::DrawingArea::from_instance(self);
let zoom = self_.zoom.get();
self.set_property("zoom", &new_zoom.clamp((0.1f64).min(zoom), (8.0f64).max(zoom))).unwrap();
self.set_property("zoom", &new_zoom.clamp((0.1f64).min(zoom), (8.0f64).max(zoom)));
let hadj = self.hadjustment().unwrap();
let vadj = self.vadjustment().unwrap();
......@@ -481,18 +476,18 @@ impl DrawingArea {
}
pub fn set_filter(&self, filter: Filter) {
self.set_property("filter", &filter).unwrap();
self.set_property("filter", &filter);
}
fn filter(&self) -> Filter {
self.property("filter").unwrap().get().unwrap()
self.property("filter")
}
pub fn save_to(&self, dest: &gio::File) -> anyhow::Result<()> {
if let Some(ref texture) = self.texture() {
let pixbuf = gdk::pixbuf_get_from_texture(texture).unwrap();
let stream = dest.append_to(gio::FileCreateFlags::NONE, gio::NONE_CANCELLABLE)?;
pixbuf.save_to_streamv(&stream, "png", &[], gio::NONE_CANCELLABLE)?;
let stream = dest.append_to(gio::FileCreateFlags::NONE, gio::Cancellable::NONE)?;
pixbuf.save_to_streamv(&stream, "png", &[], gio::Cancellable::NONE)?;
}
Ok(())
}
......@@ -501,10 +496,10 @@ impl DrawingArea {
let display = gdk::Display::default().unwrap();
let clipboard = display.clipboard();
clipboard.read_texture_async(
gio::NONE_CANCELLABLE,
gio::Cancellable::NONE,
clone!(@weak self as this => move |r| if let Ok(Some(texture)) = r {
this.load_texture(texture);
this.emit_by_name("loaded", &[]).unwrap();
this.emit_by_name("loaded", &[]);
}),
);
}
......@@ -521,12 +516,12 @@ impl DrawingArea {
pub fn undo(&self) {
let self_ = imp::DrawingArea::from_instance(self);
if let Some(texture) = self_.history.borrow_mut().pop() {
self.set_property("can-redo", &true).unwrap();
self.set_property("can-redo", &true);
self_.future.borrow_mut().push(texture);
} else {
self.set_property("can-redo", &false).unwrap();
self.set_property("can-redo", &false);
}
self.set_property("can-undo", &(self_.history.borrow().len() > 1)).unwrap();
self.set_property("can-undo", &(self_.history.borrow().len() > 1));
self.queue_allocate();
self.queue_draw();
}
......@@ -535,11 +530,11 @@ impl DrawingArea {
let self_ = imp::DrawingArea::from_instance(self);
if let Some(texture) = self_.future.borrow_mut().pop() {
self_.history.borrow_mut().push(texture);
self.set_property("can-undo", &true).unwrap();
self.set_property("can-undo", &true);
} else {
self.set_property("can-undo", &true).unwrap();
self.set_property("can-undo", &true);
}
self.set_property("can-redo", &(self_.future.borrow().len() != 0)).unwrap();
self.set_property("can-redo", &(self_.future.borrow().len() != 0));
self.queue_draw();
}
......@@ -576,16 +571,16 @@ impl DrawingArea {
}
Filter::Filled => {
snapshot.append_texture(&texture, &texture_bounds);
snapshot.append_color(&gdk::RGBA::black(), &filter_bounds);
snapshot.append_color(&gdk::RGBA::BLACK, &filter_bounds);
}
};
let node = snapshot.free_to_node().unwrap();
let node = snapshot.to_node().unwrap();
let texture = renderer.render_texture(&node, None::<&graphene::Rect>).unwrap();
self_.history.borrow_mut().push(texture);
self_.current_position.replace(None);
self.set_property("can-undo", &true).unwrap();
self.set_property("can-undo", &true);
self.queue_draw();
}
......
......@@ -181,7 +181,7 @@ impl Window {
pub fn set_open_file(&self, file: &gio::File) -> Result<()> {
let self_ = imp::Window::from_instance(self);
let info = file.query_info("standard::display-name", gio::FileQueryInfoFlags::NONE, gio::NONE_CANCELLABLE)?;
let info = file.query_info("standard::display-name", gio::FileQueryInfoFlags::NONE, gio::Cancellable::NONE)?;
let display_name = info.attribute_as_string("standard::display-name");
self_.window_title.set_subtitle(&display_name.unwrap());
......@@ -190,7 +190,7 @@ impl Window {
}
fn application(&self) -> Application {
self.property("application").unwrap().get::<gtk::Application>().unwrap().downcast().unwrap()
self.property::<gtk::Application>("application").downcast().unwrap()
}
fn setup_actions(&self) {
......@@ -211,17 +211,15 @@ impl Window {
}),
);
drawing_area
.connect_local(
"loaded",
false,
clone!(@weak self as this => @default-panic, move |_| {
this.set_view(View::Image);
None
}),
)
.unwrap();
drawing_area.connect_local(
"loaded",
false,
clone!(@weak self as this => @default-panic, move |_| {
this.set_view(View::Image);
None
}),
);
// Undo
action!(
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment