Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make use of impl T wherever possible #839

Merged
merged 2 commits into from
Jan 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 10 additions & 22 deletions gdk4/src/clipboard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,11 @@ use std::ptr;

impl Clipboard {
#[doc(alias = "gdk_clipboard_read_async")]
pub fn read_async<
P: IsA<gio::Cancellable>,
Q: FnOnce(Result<(gio::InputStream, GString), glib::Error>) + 'static,
>(
pub fn read_async<Q: FnOnce(Result<(gio::InputStream, GString), glib::Error>) + 'static>(
&self,
mime_types: &[&str],
io_priority: glib::Priority,
cancellable: Option<&P>,
cancellable: Option<&impl IsA<gio::Cancellable>>,
callback: Q,
) {
let user_data: Box<Q> = Box::new(callback);
Expand Down Expand Up @@ -89,10 +86,10 @@ impl Clipboard {
}

#[doc(alias = "gdk_clipboard_store_async")]
pub fn store_async<P: IsA<gio::Cancellable>, Q: FnOnce(Result<(), glib::Error>) + 'static>(
pub fn store_async<Q: FnOnce(Result<(), glib::Error>) + 'static>(
&self,
io_priority: glib::Priority,
cancellable: Option<&P>,
cancellable: Option<&impl IsA<gio::Cancellable>>,
callback: Q,
) {
let user_data: Box<Q> = Box::new(callback);
Expand Down Expand Up @@ -137,14 +134,11 @@ impl Clipboard {
}

#[doc(alias = "gdk_clipboard_read_value_async")]
pub fn read_value_async<
P: IsA<gio::Cancellable>,
Q: FnOnce(Result<glib::Value, glib::Error>) + 'static,
>(
pub fn read_value_async<Q: FnOnce(Result<glib::Value, glib::Error>) + 'static>(
&self,
type_: glib::types::Type,
io_priority: glib::Priority,
cancellable: Option<&P>,
cancellable: Option<&impl IsA<gio::Cancellable>>,
callback: Q,
) {
let user_data: Box<Q> = Box::new(callback);
Expand Down Expand Up @@ -193,12 +187,9 @@ impl Clipboard {
}

#[doc(alias = "gdk_clipboard_read_text_async")]
pub fn read_text_async<
P: IsA<gio::Cancellable>,
Q: FnOnce(Result<Option<glib::GString>, glib::Error>) + 'static,
>(
pub fn read_text_async<Q: FnOnce(Result<Option<glib::GString>, glib::Error>) + 'static>(
&self,
cancellable: Option<&P>,
cancellable: Option<&impl IsA<gio::Cancellable>>,
callback: Q,
) {
let user_data: Box<Q> = Box::new(callback);
Expand Down Expand Up @@ -244,12 +235,9 @@ impl Clipboard {
}

#[doc(alias = "gdk_clipboard_read_texture_async")]
pub fn read_texture_async<
P: IsA<gio::Cancellable>,
Q: FnOnce(Result<Option<Texture>, glib::Error>) + 'static,
>(
pub fn read_texture_async<Q: FnOnce(Result<Option<Texture>, glib::Error>) + 'static>(
&self,
cancellable: Option<&P>,
cancellable: Option<&impl IsA<gio::Cancellable>>,
callback: Q,
) {
let user_data: Box<Q> = Box::new(callback);
Expand Down
14 changes: 4 additions & 10 deletions gdk4/src/drop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,11 @@ use std::ptr;

impl Drop {
#[doc(alias = "gdk_drop_read_async")]
pub fn read_async<
P: IsA<gio::Cancellable>,
Q: FnOnce(Result<(gio::InputStream, GString), glib::Error>) + 'static,
>(
pub fn read_async<Q: FnOnce(Result<(gio::InputStream, GString), glib::Error>) + 'static>(
&self,
mime_types: &[&str],
io_priority: glib::Priority,
cancellable: Option<&P>,
cancellable: Option<&impl IsA<gio::Cancellable>>,
callback: Q,
) {
let user_data: Box<Q> = Box::new(callback);
Expand Down Expand Up @@ -81,14 +78,11 @@ impl Drop {
}

#[doc(alias = "gdk_drop_read_value_async")]
pub fn read_value_async<
P: IsA<gio::Cancellable>,
Q: FnOnce(Result<glib::Value, glib::Error>) + 'static,
>(
pub fn read_value_async<Q: FnOnce(Result<glib::Value, glib::Error>) + 'static>(
&self,
type_: glib::types::Type,
io_priority: glib::Priority,
cancellable: Option<&P>,
cancellable: Option<&impl IsA<gio::Cancellable>>,
callback: Q,
) {
let user_data: Box<Q> = Box::new(callback);
Expand Down
6 changes: 3 additions & 3 deletions gdk4/src/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ impl Event {

#[doc(alias = "gdk_events_get_angle")]
#[doc(alias = "get_angle")]
pub fn angle<P: AsRef<Event>>(&self, event: P) -> Option<f64> {
pub fn angle(&self, event: impl AsRef<Event>) -> Option<f64> {
skip_assert_initialized!();
unsafe {
let mut angle = mem::MaybeUninit::uninit();
Expand All @@ -49,7 +49,7 @@ impl Event {

#[doc(alias = "gdk_events_get_center")]
#[doc(alias = "get_center")]
pub fn center<P: AsRef<Event>>(&self, event: P) -> Option<(f64, f64)> {
pub fn center(&self, event: impl AsRef<Event>) -> Option<(f64, f64)> {
skip_assert_initialized!();
unsafe {
let mut x = mem::MaybeUninit::uninit();
Expand All @@ -72,7 +72,7 @@ impl Event {

#[doc(alias = "gdk_events_get_distance")]
#[doc(alias = "get_distance")]
pub fn distance<P: AsRef<Event>>(&self, event: P) -> Option<f64> {
pub fn distance(&self, event: impl AsRef<Event>) -> Option<f64> {
skip_assert_initialized!();
unsafe {
let mut distance = mem::MaybeUninit::uninit();
Expand Down
28 changes: 10 additions & 18 deletions gdk4/src/functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,12 @@ pub fn pango_layout_get_clip_region(
}

#[doc(alias = "gdk_content_deserialize_async")]
pub fn content_deserialize_async<
P: IsA<gio::InputStream>,
Q: IsA<gio::Cancellable>,
R: FnOnce(Result<glib::Value, glib::Error>) + Send + 'static,
>(
stream: &P,
pub fn content_deserialize_async<R: FnOnce(Result<glib::Value, glib::Error>) + Send + 'static>(
stream: &impl IsA<gio::InputStream>,
mime_type: &str,
type_: glib::types::Type,
io_priority: glib::Priority,
cancellable: Option<&Q>,
cancellable: Option<&impl IsA<gio::Cancellable>>,
callback: R,
) {
assert_initialized_main_thread!();
Expand Down Expand Up @@ -78,8 +74,8 @@ pub fn content_deserialize_async<
}
}

pub fn content_deserialize_future<P: IsA<gio::InputStream> + Clone + 'static>(
stream: &P,
pub fn content_deserialize_future(
stream: &(impl IsA<gio::InputStream> + Clone + 'static),
mime_type: &str,
type_: glib::types::Type,
io_priority: glib::Priority,
Expand Down Expand Up @@ -222,16 +218,12 @@ pub fn content_register_serializer<
}

#[doc(alias = "gdk_content_serialize_async")]
pub fn content_serialize_async<
P: IsA<gio::OutputStream>,
Q: IsA<gio::Cancellable>,
R: FnOnce(Result<(), glib::Error>) + Send + 'static,
>(
stream: &P,
pub fn content_serialize_async<R: FnOnce(Result<(), glib::Error>) + Send + 'static>(
stream: &impl IsA<gio::OutputStream>,
mime_type: &str,
value: &glib::Value,
io_priority: glib::Priority,
cancellable: Option<&Q>,
cancellable: Option<&impl IsA<gio::Cancellable>>,
callback: R,
) {
assert_initialized_main_thread!();
Expand Down Expand Up @@ -267,8 +259,8 @@ pub fn content_serialize_async<
}
}

pub fn content_serialize_future<P: IsA<gio::OutputStream> + Clone + 'static>(
stream: &P,
pub fn content_serialize_future(
stream: &(impl IsA<gio::OutputStream> + Clone + 'static),
mime_type: &str,
value: &glib::Value,
io_priority: glib::Priority,
Expand Down
44 changes: 2 additions & 42 deletions gtk4/Gir.toml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ generate = [
"Gtk.BuilderScope",
"Gtk.ButtonsType",
"Gtk.CellAreaBox",
"Gtk.CellEditable",
"Gtk.CellRendererAccelMode",
"Gtk.CellRendererMode",
"Gtk.CellRendererPixbuf",
Expand Down Expand Up @@ -130,6 +131,7 @@ generate = [
"Gtk.IconThemeError",
"Gtk.IconViewDropPosition",
"Gtk.ImageType",
"Gtk.IMContext",
"Gtk.IMMulticontext",
"Gtk.InputHints",
"Gtk.InputPurpose",
Expand Down Expand Up @@ -671,14 +673,6 @@ manual_traits = ["CellAreaExtManual"]
pattern = "cell_[gs]et_property"
manual = true
[[object.function]]
name = "activate_cell"
manual = true # to handlndle gdk::Event
doc_trait_name = "CellAreaExtManual"
[[object.function]]
name = "event"
manual = true # to handlndle gdk::Event
doc_trait_name = "CellAreaExtManual"
[[object.function]]
name = "apply_attributes"
[[object.function.parameter]]
name = "iter"
Expand All @@ -705,15 +699,6 @@ name = "Gtk.CellAreaContext"
status = "generate"
generate_builder = false

[[object]]
name = "Gtk.CellEditable"
status = "generate"
manual_traits = ["CellEditableExtManual"]
[[object.function]]
name = "start_editing"
manual = true # to handle gdk::Event
doc_trait_name = "CellEditableExtManual"

[[object]]
name = "Gtk.CellLayout"
status = "generate"
Expand All @@ -734,20 +719,12 @@ manual_traits = ["CellRendererExtManual"]
[[object.property]]
pattern = "*-set" # those properties are read only
generate = ["get", "notify"]
[[object.function]]
name = "activate"
manual = true # to handle gdk::Event
doc_trait_name = "CellRendererExtManual"
[[object.signal]]
name = "editing-started"
[[object.signal.parameter]]
name = "path"
transformation = "treepath"
[[object.function]]
name = "start_editing"
manual = true # to handle gdk::Event
doc_trait_name = "CellRendererExtManual"
[[object.function]]
name = "render"
ignore = true # docs only

Expand Down Expand Up @@ -1278,14 +1255,6 @@ status = "generate"
name = "pixbuf"
nullable = false

[[object]]
name = "Gtk.IMContext"
status = "generate"
manual_traits = ["IMContextExtManual"]
[[object.function]]
name = "filter_keypress"
manual = true # to handle gdk::Event
doc_trait_name = "IMContextExtManual"

[[object]]
name = "Gtk.IMContextSimple"
Expand Down Expand Up @@ -1816,10 +1785,6 @@ manual_traits = ["ShortcutTriggerExtManual"]
name = "compare"
manual = true # complains about the trait IsA<T> being so generic
doc_trait_name = "ShortcutTriggerExtManual"
[[object.function]]
name = "trigger"
manual = true # to handle gdk::Event
doc_trait_name = "ShortcutTriggerExtManual"

[[object]]
name = "Gtk.SignalAction"
Expand Down Expand Up @@ -1961,11 +1926,6 @@ status = "generate"
[[object]]
name = "Gtk.TextView"
status = "generate"
manual_traits = ["TextViewExtManual"]
[[object.function]]
name = "im_context_filter_keypress"
manual = true # to handle gdk::Event
doc_trait_name = "TextViewExtManual"
[[object.signal]]
name = "extend-selection"
inhibit = true
Expand Down
60 changes: 60 additions & 0 deletions gtk4/src/auto/cell_area.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,16 @@ pub trait CellAreaExt: 'static {
edit_only: bool,
) -> bool;

#[doc(alias = "gtk_cell_area_activate_cell")]
fn activate_cell(
&self,
widget: &impl IsA<Widget>,
renderer: &impl IsA<CellRenderer>,
event: impl AsRef<gdk::Event>,
cell_area: &gdk::Rectangle,
flags: CellRendererState,
) -> bool;

#[doc(alias = "gtk_cell_area_add")]
fn add(&self, renderer: &impl IsA<CellRenderer>);

Expand Down Expand Up @@ -84,6 +94,16 @@ pub trait CellAreaExt: 'static {
#[doc(alias = "gtk_cell_area_create_context")]
fn create_context(&self) -> CellAreaContext;

#[doc(alias = "gtk_cell_area_event")]
fn event(
&self,
context: &impl IsA<CellAreaContext>,
widget: &impl IsA<Widget>,
event: impl AsRef<gdk::Event>,
cell_area: &gdk::Rectangle,
flags: CellRendererState,
) -> i32;

#[doc(alias = "gtk_cell_area_focus")]
fn focus(&self, direction: DirectionType) -> bool;

Expand Down Expand Up @@ -297,6 +317,26 @@ impl<O: IsA<CellArea>> CellAreaExt for O {
}
}

fn activate_cell(
&self,
widget: &impl IsA<Widget>,
renderer: &impl IsA<CellRenderer>,
event: impl AsRef<gdk::Event>,
cell_area: &gdk::Rectangle,
flags: CellRendererState,
) -> bool {
unsafe {
from_glib(ffi::gtk_cell_area_activate_cell(
self.as_ref().to_glib_none().0,
widget.as_ref().to_glib_none().0,
renderer.as_ref().to_glib_none().0,
event.as_ref().to_glib_none().0,
cell_area.to_glib_none().0,
flags.into_glib(),
))
}
}

fn add(&self, renderer: &impl IsA<CellRenderer>) {
unsafe {
ffi::gtk_cell_area_add(
Expand Down Expand Up @@ -386,6 +426,26 @@ impl<O: IsA<CellArea>> CellAreaExt for O {
}
}

fn event(
&self,
context: &impl IsA<CellAreaContext>,
widget: &impl IsA<Widget>,
event: impl AsRef<gdk::Event>,
cell_area: &gdk::Rectangle,
flags: CellRendererState,
) -> i32 {
unsafe {
ffi::gtk_cell_area_event(
self.as_ref().to_glib_none().0,
context.as_ref().to_glib_none().0,
widget.as_ref().to_glib_none().0,
event.as_ref().to_glib_none().0,
cell_area.to_glib_none().0,
flags.into_glib(),
)
}
}

fn focus(&self, direction: DirectionType) -> bool {
unsafe {
from_glib(ffi::gtk_cell_area_focus(
Expand Down
Loading