1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
use crate::{Actor, ActorBox, AllocationFlags, Container, LayoutMeta};
use glib::{
object as gobject,
object::{Cast, IsA},
signal::{connect_raw, SignalHandlerId},
translate::*,
};
use std::boxed::Box as Box_;
use std::{fmt, mem, mem::transmute};
glib_wrapper! {
pub struct LayoutManager(Object<ffi::ClutterLayoutManager, ffi::ClutterLayoutManagerClass, LayoutManagerClass>) @extends gobject::InitiallyUnowned;
match fn {
get_type => || ffi::clutter_layout_manager_get_type(),
}
}
pub const NONE_LAYOUT_MANAGER: Option<&LayoutManager> = None;
/// Trait containing all `LayoutManager` methods.
///
/// # Implementors
///
/// [`BinLayout`](struct.BinLayout.html), [`BoxLayout`](struct.BoxLayout.html), [`FixedLayout`](struct.FixedLayout.html), [`FlowLayout`](struct.FlowLayout.html), [`GridLayout`](struct.GridLayout.html), [`LayoutManager`](struct.LayoutManager.html)
pub trait LayoutManagerExt: 'static {
/// Allocates the children of `container` given an area
///
/// See also `ActorExt::allocate`
/// ## `container`
/// the `Container` using `self`
/// ## `allocation`
/// the `ActorBox` containing the allocated area
/// of `container`
/// ## `flags`
/// the allocation flags
fn allocate<P: IsA<Container>>(
&self,
container: &P,
allocation: &ActorBox,
flags: AllocationFlags,
);
//fn child_get<P: IsA<Container>, Q: IsA<Actor>>(&self, container: &P, actor: &Q, first_property: &str, : /*Unknown conversion*//*Unimplemented*/Fundamental: VarArgs);
/// Gets a property on the `LayoutMeta` created by `self` and
/// attached to a child of `container`
///
/// The `gobject::Value` must already be initialized to the type of the property
/// and has to be unset with `gobject::Value::unset` after extracting the real
/// value out of it
/// ## `container`
/// a `Container` using `self`
/// ## `actor`
/// a `Actor` child of `container`
/// ## `property_name`
/// the name of the property to get
/// ## `value`
/// a `gobject::Value` with the value of the property to get
fn child_get_property<P: IsA<Container>, Q: IsA<Actor>>(
&self,
container: &P,
actor: &Q,
property_name: &str,
value: &mut glib::Value,
);
//fn child_set<P: IsA<Container>, Q: IsA<Actor>>(&self, container: &P, actor: &Q, first_property: &str, : /*Unknown conversion*//*Unimplemented*/Fundamental: VarArgs);
/// Sets a property on the `LayoutMeta` created by `self` and
/// attached to a child of `container`
/// ## `container`
/// a `Container` using `self`
/// ## `actor`
/// a `Actor` child of `container`
/// ## `property_name`
/// the name of the property to set
/// ## `value`
/// a `gobject::Value` with the value of the property to set
fn child_set_property<P: IsA<Container>, Q: IsA<Actor>>(
&self,
container: &P,
actor: &Q,
property_name: &str,
value: &glib::Value,
);
/// Retrieves the `gobject::ParamSpec` for the layout property `name` inside
/// the `LayoutMeta` sub-class used by `self`
/// ## `name`
/// the name of the property
///
/// # Returns
///
/// a `gobject::ParamSpec` describing the property,
/// or `None` if no property with that name exists. The returned
/// `gobject::ParamSpec` is owned by the layout manager and should not be
/// modified or freed
fn find_child_property(&self, name: &str) -> Option<glib::ParamSpec>;
/// Retrieves the `LayoutMeta` that the layout `self` associated
/// to the `actor` child of `container`, eventually by creating one if the
/// `LayoutManager` supports layout properties
/// ## `container`
/// a `Container` using `self`
/// ## `actor`
/// a `Actor` child of `container`
///
/// # Returns
///
/// a `LayoutMeta`, or `None` if the
/// `LayoutManager` does not have layout properties. The returned
/// layout meta instance is owned by the `LayoutManager` and it
/// should not be unreferenced
fn get_child_meta<P: IsA<Container>, Q: IsA<Actor>>(
&self,
container: &P,
actor: &Q,
) -> Option<LayoutMeta>;
/// Computes the minimum and natural heights of the `container` according
/// to `self`.
///
/// See also `ActorExt::get_preferred_height`
/// ## `container`
/// the `Container` using `self`
/// ## `for_width`
/// the width for which the height should be computed, or -1
/// ## `min_height_p`
/// return location for the minimum height
/// of the layout, or `None`
/// ## `nat_height_p`
/// return location for the natural height
/// of the layout, or `None`
fn get_preferred_height<P: IsA<Container>>(&self, container: &P, for_width: f32) -> (f32, f32);
/// Computes the minimum and natural widths of the `container` according
/// to `self`.
///
/// See also `ActorExt::get_preferred_width`
/// ## `container`
/// the `Container` using `self`
/// ## `for_height`
/// the height for which the width should be computed, or -1
/// ## `min_width_p`
/// return location for the minimum width
/// of the layout, or `None`
/// ## `nat_width_p`
/// return location for the natural width
/// of the layout, or `None`
fn get_preferred_width<P: IsA<Container>>(&self, container: &P, for_height: f32) -> (f32, f32);
/// Emits the `LayoutManager::layout-changed` signal on `self`
///
/// This function should only be called by implementations of the
/// `LayoutManager` class
fn layout_changed(&self);
/// Retrieves all the `gobject::ParamSpec`<!-- -->s for the layout properties
/// stored inside the `LayoutMeta` sub-class used by `self`
/// ## `n_pspecs`
/// return location for the number of returned
/// `gobject::ParamSpec`<!-- -->s
///
/// # Returns
///
/// the newly-allocated,
/// `None`-terminated array of `gobject::ParamSpec`<!-- -->s. Use `g_free` to free the
/// resources allocated for the array
fn list_child_properties(&self) -> Vec<glib::ParamSpec>;
/// If the `LayoutManager` sub-class allows it, allow
/// adding a weak reference of the `container` using `self`
/// from within the layout manager
///
/// The layout manager should not increase the reference
/// count of the `container`
/// ## `container`
/// a `Container` using `self`
fn set_container<P: IsA<Container>>(&self, container: Option<&P>);
/// The ::layout-changed signal is emitted each time a layout manager
/// has been changed. Every `Actor` using the `manager` instance
/// as a layout manager should connect a handler to the ::layout-changed
/// signal and queue a relayout on themselves:
///
///
/// ```text
/// static void layout_changed (ClutterLayoutManager *manager,
/// ClutterActor *self)
/// {
/// clutter_actor_queue_relayout (self);
/// }
/// ...
/// self->manager = g_object_ref_sink (manager);
/// g_signal_connect (self->manager, "layout-changed",
/// G_CALLBACK (layout_changed),
/// self);
/// ```
///
/// Sub-classes of `LayoutManager` that implement a layout that
/// can be controlled or changed using parameters should emit the
/// ::layout-changed signal whenever one of the parameters changes,
/// by using `LayoutManagerExt::layout_changed`.
fn connect_layout_changed<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;
}
impl<O: IsA<LayoutManager>> LayoutManagerExt for O {
fn allocate<P: IsA<Container>>(
&self,
container: &P,
allocation: &ActorBox,
flags: AllocationFlags,
) {
unsafe {
ffi::clutter_layout_manager_allocate(
self.as_ref().to_glib_none().0,
container.as_ref().to_glib_none().0,
allocation.to_glib_none().0,
flags.to_glib(),
);
}
}
//fn child_get<P: IsA<Container>, Q: IsA<Actor>>(&self, container: &P, actor: &Q, first_property: &str, : /*Unknown conversion*//*Unimplemented*/Fundamental: VarArgs) {
// unsafe { TODO: call clutter_sys:clutter_layout_manager_child_get() }
//}
fn child_get_property<P: IsA<Container>, Q: IsA<Actor>>(
&self,
container: &P,
actor: &Q,
property_name: &str,
value: &mut glib::Value,
) {
unsafe {
ffi::clutter_layout_manager_child_get_property(
self.as_ref().to_glib_none().0,
container.as_ref().to_glib_none().0,
actor.as_ref().to_glib_none().0,
property_name.to_glib_none().0,
value.to_glib_none_mut().0,
);
}
}
//fn child_set<P: IsA<Container>, Q: IsA<Actor>>(&self, container: &P, actor: &Q, first_property: &str, : /*Unknown conversion*//*Unimplemented*/Fundamental: VarArgs) {
// unsafe { TODO: call clutter_sys:clutter_layout_manager_child_set() }
//}
fn child_set_property<P: IsA<Container>, Q: IsA<Actor>>(
&self,
container: &P,
actor: &Q,
property_name: &str,
value: &glib::Value,
) {
unsafe {
ffi::clutter_layout_manager_child_set_property(
self.as_ref().to_glib_none().0,
container.as_ref().to_glib_none().0,
actor.as_ref().to_glib_none().0,
property_name.to_glib_none().0,
value.to_glib_none().0,
);
}
}
fn find_child_property(&self, name: &str) -> Option<glib::ParamSpec> {
unsafe {
from_glib_none(ffi::clutter_layout_manager_find_child_property(
self.as_ref().to_glib_none().0,
name.to_glib_none().0,
))
}
}
fn get_child_meta<P: IsA<Container>, Q: IsA<Actor>>(
&self,
container: &P,
actor: &Q,
) -> Option<LayoutMeta> {
unsafe {
from_glib_none(ffi::clutter_layout_manager_get_child_meta(
self.as_ref().to_glib_none().0,
container.as_ref().to_glib_none().0,
actor.as_ref().to_glib_none().0,
))
}
}
fn get_preferred_height<P: IsA<Container>>(&self, container: &P, for_width: f32) -> (f32, f32) {
unsafe {
let mut min_height_p = mem::MaybeUninit::uninit();
let mut nat_height_p = mem::MaybeUninit::uninit();
ffi::clutter_layout_manager_get_preferred_height(
self.as_ref().to_glib_none().0,
container.as_ref().to_glib_none().0,
for_width,
min_height_p.as_mut_ptr(),
nat_height_p.as_mut_ptr(),
);
let min_height_p = min_height_p.assume_init();
let nat_height_p = nat_height_p.assume_init();
(min_height_p, nat_height_p)
}
}
fn get_preferred_width<P: IsA<Container>>(&self, container: &P, for_height: f32) -> (f32, f32) {
unsafe {
let mut min_width_p = mem::MaybeUninit::uninit();
let mut nat_width_p = mem::MaybeUninit::uninit();
ffi::clutter_layout_manager_get_preferred_width(
self.as_ref().to_glib_none().0,
container.as_ref().to_glib_none().0,
for_height,
min_width_p.as_mut_ptr(),
nat_width_p.as_mut_ptr(),
);
let min_width_p = min_width_p.assume_init();
let nat_width_p = nat_width_p.assume_init();
(min_width_p, nat_width_p)
}
}
fn layout_changed(&self) {
unsafe {
ffi::clutter_layout_manager_layout_changed(self.as_ref().to_glib_none().0);
}
}
fn list_child_properties(&self) -> Vec<glib::ParamSpec> {
unsafe {
let mut n_pspecs = mem::MaybeUninit::uninit();
let ret = FromGlibContainer::from_glib_full_num(
ffi::clutter_layout_manager_list_child_properties(
self.as_ref().to_glib_none().0,
n_pspecs.as_mut_ptr(),
),
n_pspecs.assume_init() as usize,
);
ret
}
}
fn set_container<P: IsA<Container>>(&self, container: Option<&P>) {
unsafe {
ffi::clutter_layout_manager_set_container(
self.as_ref().to_glib_none().0,
container.map(|p| p.as_ref()).to_glib_none().0,
);
}
}
fn connect_layout_changed<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
unsafe extern "C" fn layout_changed_trampoline<P, F: Fn(&P) + 'static>(
this: *mut ffi::ClutterLayoutManager,
f: glib_sys::gpointer,
) where
P: IsA<LayoutManager>,
{
let f: &F = &*(f as *const F);
f(&LayoutManager::from_glib_borrow(this).unsafe_cast_ref())
}
unsafe {
let f: Box_<F> = Box_::new(f);
connect_raw(
self.as_ptr() as *mut _,
b"layout-changed\0".as_ptr() as *const _,
Some(transmute::<_, unsafe extern "C" fn()>(
layout_changed_trampoline::<Self, F> as *const (),
)),
Box_::into_raw(f),
)
}
}
}
impl fmt::Display for LayoutManager {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "LayoutManager")
}
}