Skip to content
This repository was archived by the owner on Mar 4, 2024. It is now read-only.

Commit 433d40f

Browse files
authored
Merge pull request #701 from sdroege/wrapper-api-changes
Update for glib wrapper API changes
2 parents a624e44 + 5422ba3 commit 433d40f

File tree

8 files changed

+119
-88
lines changed

8 files changed

+119
-88
lines changed

gdk/src/event.rs

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,7 @@ impl Event {
416416
impl fmt::Debug for Event {
417417
fn fmt(&self, fmt: &mut fmt::Formatter) -> Result<(), fmt::Error> {
418418
fmt.debug_struct("Event")
419-
.field("inner", &self.0)
419+
.field("inner", &self.inner)
420420
.field("type", &self.event_type())
421421
.finish()
422422
}
@@ -435,7 +435,8 @@ macro_rules! event_wrapper {
435435

436436
#[inline]
437437
fn to_glib_none(&'a self) -> Stash<'a, *const ::ffi::$ffi_name, Self> {
438-
let ptr = ToGlibPtr::<*const ::ffi::GdkEvent>::to_glib_none(&self.0).0;
438+
let ptr =
439+
<$crate::Event as ToGlibPtr<*const ::ffi::GdkEvent>>::to_glib_none(&*self).0;
439440
Stash(ptr as *const ::ffi::$ffi_name, self)
440441
}
441442
}
@@ -445,15 +446,21 @@ macro_rules! event_wrapper {
445446

446447
#[inline]
447448
fn to_glib_none_mut(&'a mut self) -> StashMut<'a, *mut ::ffi::$ffi_name, Self> {
448-
let ptr = ToGlibPtrMut::<*mut ::ffi::GdkEvent>::to_glib_none_mut(&mut self.0).0;
449+
let ptr = <$crate::Event as ToGlibPtrMut<*mut ::ffi::GdkEvent>>::to_glib_none_mut(
450+
&mut *self,
451+
)
452+
.0;
449453
StashMut(ptr as *mut ::ffi::$ffi_name, self)
450454
}
451455
}
452456

453457
impl FromGlibPtrNone<*mut ::ffi::$ffi_name> for $name {
454458
#[inline]
455459
unsafe fn from_glib_none(ptr: *mut ::ffi::$ffi_name) -> Self {
456-
$name(from_glib_none(ptr as *mut ::ffi::GdkEvent))
460+
<$name as crate::event::FromEvent>::from(from_glib_none(
461+
ptr as *mut ::ffi::GdkEvent,
462+
))
463+
.unwrap()
457464
}
458465
}
459466

@@ -475,7 +482,10 @@ macro_rules! event_wrapper {
475482
impl FromGlibPtrFull<*mut ::ffi::$ffi_name> for $name {
476483
#[inline]
477484
unsafe fn from_glib_full(ptr: *mut ::ffi::$ffi_name) -> Self {
478-
$name(from_glib_full(ptr as *mut ::ffi::GdkEvent))
485+
<$name as crate::event::FromEvent>::from(from_glib_full(
486+
ptr as *mut ::ffi::GdkEvent,
487+
))
488+
.unwrap()
479489
}
480490
}
481491

gdk/src/geometry.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,37 +11,37 @@ glib::wrapper! {
1111

1212
impl Geometry {
1313
pub fn min_width(&self) -> i32 {
14-
self.0.min_width
14+
self.inner.min_width
1515
}
1616
pub fn min_height(&self) -> i32 {
17-
self.0.min_height
17+
self.inner.min_height
1818
}
1919
pub fn max_width(&self) -> i32 {
20-
self.0.max_width
20+
self.inner.max_width
2121
}
2222
pub fn max_height(&self) -> i32 {
23-
self.0.max_height
23+
self.inner.max_height
2424
}
2525
pub fn base_width(&self) -> i32 {
26-
self.0.base_width
26+
self.inner.base_width
2727
}
2828
pub fn base_height(&self) -> i32 {
29-
self.0.base_height
29+
self.inner.base_height
3030
}
3131
pub fn width_inc(&self) -> i32 {
32-
self.0.width_inc
32+
self.inner.width_inc
3333
}
3434
pub fn height_inc(&self) -> i32 {
35-
self.0.height_inc
35+
self.inner.height_inc
3636
}
3737
pub fn min_aspect(&self) -> f64 {
38-
self.0.min_aspect
38+
self.inner.min_aspect
3939
}
4040
pub fn max_aspect(&self) -> f64 {
41-
self.0.max_aspect
41+
self.inner.max_aspect
4242
}
4343
pub fn win_gravity(&self) -> Gravity {
44-
unsafe { from_glib(self.0.win_gravity) }
44+
unsafe { from_glib(self.inner.win_gravity) }
4545
}
4646
}
4747

gdk/src/keymap_key.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@ glib::wrapper! {
99

1010
impl KeymapKey {
1111
pub fn keycode(&self) -> u32 {
12-
self.0.keycode
12+
self.inner.keycode
1313
}
1414
pub fn group(&self) -> i32 {
15-
self.0.group
15+
self.inner.group
1616
}
1717
pub fn level(&self) -> i32 {
18-
self.0.level
18+
self.inner.level
1919
}
2020
}
2121

gdk/src/rectangle.rs

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,43 +2,46 @@
22

33
use crate::Rectangle;
44
use cairo::RectangleInt;
5+
use glib::translate::*;
56
use std::convert::{AsRef, From};
67
use std::fmt;
78

89
impl Rectangle {
910
pub fn new(x: i32, y: i32, width: i32, height: i32) -> Rectangle {
1011
skip_assert_initialized!();
11-
Rectangle(ffi::GdkRectangle {
12-
x,
13-
y,
14-
width,
15-
height,
16-
})
12+
unsafe {
13+
Rectangle::unsafe_from(ffi::GdkRectangle {
14+
x,
15+
y,
16+
width,
17+
height,
18+
})
19+
}
1720
}
1821

1922
pub fn x(&self) -> i32 {
20-
self.0.x
23+
self.inner.x
2124
}
2225

2326
pub fn y(&self) -> i32 {
24-
self.0.y
27+
self.inner.y
2528
}
2629

2730
pub fn width(&self) -> i32 {
28-
self.0.width
31+
self.inner.width
2932
}
3033

3134
pub fn height(&self) -> i32 {
32-
self.0.height
35+
self.inner.height
3336
}
3437

3538
#[cfg(not(any(feature = "v3_20", feature = "dox")))]
3639
#[doc(alias = "gdk_rectangle_equal")]
3740
fn equal(&self, rect2: &Rectangle) -> bool {
38-
self.0.x == rect2.0.x
39-
&& self.0.y == rect2.0.y
40-
&& self.0.width == rect2.0.width
41-
&& self.0.height == rect2.0.height
41+
self.inner.x == rect2.inner.x
42+
&& self.inner.y == rect2.inner.y
43+
&& self.inner.width == rect2.inner.width
44+
&& self.inner.height == rect2.inner.height
4245
}
4346
}
4447

gdk/src/rgba.rs

Lines changed: 65 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -10,44 +10,46 @@ use std::str::FromStr;
1010
impl RGBA {
1111
pub fn new(red: f64, green: f64, blue: f64, alpha: f64) -> RGBA {
1212
skip_assert_initialized!();
13-
RGBA(ffi::GdkRGBA {
14-
red,
15-
green,
16-
blue,
17-
alpha,
18-
})
13+
unsafe {
14+
RGBA::unsafe_from(ffi::GdkRGBA {
15+
red,
16+
green,
17+
blue,
18+
alpha,
19+
})
20+
}
1921
}
2022

2123
pub fn red(&self) -> f64 {
22-
self.0.red
24+
self.inner.red
2325
}
2426

2527
pub fn set_red(&mut self, red: f64) {
26-
self.0.red = red;
28+
self.inner.red = red;
2729
}
2830

2931
pub fn green(&self) -> f64 {
30-
self.0.green
32+
self.inner.green
3133
}
3234

3335
pub fn set_green(&mut self, green: f64) {
34-
self.0.green = green;
36+
self.inner.green = green;
3537
}
3638

3739
pub fn blue(&self) -> f64 {
38-
self.0.blue
40+
self.inner.blue
3941
}
4042

4143
pub fn set_blue(&mut self, blue: f64) {
42-
self.0.blue = blue;
44+
self.inner.blue = blue;
4345
}
4446

4547
pub fn alpha(&self) -> f64 {
46-
self.0.alpha
48+
self.inner.alpha
4749
}
4850

4951
pub fn set_alpha(&mut self, alpha: f64) {
50-
self.0.alpha = alpha;
52+
self.inner.alpha = alpha;
5153
}
5254

5355
#[doc(alias = "gdk_rgba_parse")]
@@ -63,40 +65,55 @@ impl RGBA {
6365
}
6466
}
6567

66-
pub const BLACK: RGBA = RGBA(ffi::GdkRGBA {
67-
red: 0f64,
68-
green: 0f64,
69-
blue: 0f64,
70-
alpha: 1f64,
71-
});
72-
73-
pub const BLUE: RGBA = RGBA(ffi::GdkRGBA {
74-
red: 0f64,
75-
green: 0f64,
76-
blue: 1f64,
77-
alpha: 1f64,
78-
});
79-
80-
pub const GREEN: RGBA = RGBA(ffi::GdkRGBA {
81-
red: 0f64,
82-
green: 1f64,
83-
blue: 0f64,
84-
alpha: 1f64,
85-
});
86-
87-
pub const RED: RGBA = RGBA(ffi::GdkRGBA {
88-
red: 1f64,
89-
green: 0f64,
90-
blue: 0f64,
91-
alpha: 1f64,
92-
});
93-
94-
pub const WHITE: RGBA = RGBA(ffi::GdkRGBA {
95-
red: 1f64,
96-
green: 1f64,
97-
blue: 1f64,
98-
alpha: 1f64,
99-
});
68+
pub const BLACK: RGBA = RGBA {
69+
inner: ffi::GdkRGBA {
70+
red: 0f64,
71+
green: 0f64,
72+
blue: 0f64,
73+
alpha: 1f64,
74+
},
75+
phantom: std::marker::PhantomData,
76+
};
77+
78+
pub const BLUE: RGBA = RGBA {
79+
inner: ffi::GdkRGBA {
80+
red: 0f64,
81+
green: 0f64,
82+
blue: 1f64,
83+
alpha: 1f64,
84+
},
85+
phantom: std::marker::PhantomData,
86+
};
87+
88+
pub const GREEN: RGBA = RGBA {
89+
inner: ffi::GdkRGBA {
90+
red: 0f64,
91+
green: 1f64,
92+
blue: 0f64,
93+
alpha: 1f64,
94+
},
95+
phantom: std::marker::PhantomData,
96+
};
97+
98+
pub const RED: RGBA = RGBA {
99+
inner: ffi::GdkRGBA {
100+
red: 1f64,
101+
green: 0f64,
102+
blue: 0f64,
103+
alpha: 1f64,
104+
},
105+
phantom: std::marker::PhantomData,
106+
};
107+
108+
pub const WHITE: RGBA = RGBA {
109+
inner: ffi::GdkRGBA {
110+
red: 1f64,
111+
green: 1f64,
112+
blue: 1f64,
113+
alpha: 1f64,
114+
},
115+
phantom: std::marker::PhantomData,
116+
};
100117
}
101118

102119
impl fmt::Debug for RGBA {

gdk/src/time_coord.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ glib::wrapper! {
77

88
impl TimeCoord {
99
pub fn time(&self) -> u32 {
10-
self.0.time
10+
self.inner.time
1111
}
1212

1313
pub fn axes(&self) -> &[f64; ffi::GDK_MAX_TIMECOORD_AXES as usize] {
14-
&self.0.axes
14+
&self.inner.axes
1515
}
1616
}

gtk/src/border.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,13 @@ impl ops::Deref for Border {
1919
type Target = ffi::GtkBorder;
2020

2121
fn deref(&self) -> &Self::Target {
22-
&self.0
22+
&self.inner
2323
}
2424
}
2525

2626
impl ops::DerefMut for Border {
2727
fn deref_mut(&mut self) -> &mut Self::Target {
28-
&mut self.0
28+
&mut self.inner
2929
}
3030
}
3131

gtk/src/page_range.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// Take a look at the license at the top of the repository in the LICENSE file.
22

3+
use glib::translate::*;
34
use std::fmt;
45

56
glib::wrapper! {
@@ -10,17 +11,17 @@ glib::wrapper! {
1011
impl PageRange {
1112
pub fn new(start: i32, end: i32) -> PageRange {
1213
skip_assert_initialized!();
13-
PageRange(ffi::GtkPageRange { start, end })
14+
unsafe { PageRange::unsafe_from(ffi::GtkPageRange { start, end }) }
1415
}
1516

1617
#[doc(alias = "get_start")]
1718
pub fn start(&self) -> i32 {
18-
self.0.start
19+
self.inner.start
1920
}
2021

2122
#[doc(alias = "get_end")]
2223
pub fn end(&self) -> i32 {
23-
self.0.end
24+
self.inner.end
2425
}
2526
}
2627

0 commit comments

Comments
 (0)