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
// This file is auto-generated by rute_gen. DO NOT EDIT.
use std::cell::Cell;
use std::rc::Rc;
#[allow(unused_imports)]
use std::marker::PhantomData;
#[allow(unused_imports)]
use std::os::raw::c_void;
#[allow(unused_imports)]
use std::mem::transmute;
#[allow(unused_imports)]
use std::ffi::{CStr, CString};
use rute_ffi_base::*;
#[allow(unused_imports)]
use auto::*;
/// **Notice these docs are heavy WIP and not very relevent yet**
///
/// This is used by custom layouts.
///
/// Pure virtual functions are provided to return information about
/// the layout, including, sizeHint(), minimumSize(), maximumSize()
/// and expanding().
///
/// The layout's geometry can be set and retrieved with setGeometry()
/// and geometry(), and its alignment with setAlignment() and
/// alignment().
///
/// isEmpty() returns whether the layout item is empty. If the
/// concrete item is a QWidget, it can be retrieved using widget().
/// Similarly for layout() and spacerItem().
///
/// Some layouts have width and height interdependencies. These can
/// be expressed using hasHeightForWidth(), heightForWidth(), and
/// minimumHeightForWidth(). For more explanation see the *Qt
/// Quarterly* article
/// [Trading
/// Height for Width](http://doc.qt.io/archives/qq/qq04-height-for-width.html)
///
///
/// **See also:** [`Layout`]
/// # Licence
///
/// The documentation is an adoption of the original [Qt Documentation](http://doc.qt.io/) and provided herein is licensed under the terms of the [GNU Free Documentation License version 1.3](http://www.gnu.org/licenses/fdl.html) as published by the Free Software Foundation.
#[derive(Clone)]
pub struct LayoutItem<'a> {
#[doc(hidden)]
pub data: Rc<Cell<Option<*const RUBase>>>,
#[doc(hidden)]
pub all_funcs: *const RULayoutItemAllFuncs,
#[doc(hidden)]
pub owned: bool,
#[doc(hidden)]
pub _marker: PhantomData<::std::cell::Cell<&'a ()>>,
}
impl<'a> LayoutItem<'a> {
#[allow(dead_code)]
pub(crate) fn new_from_rc(ffi_data: RULayoutItem) -> LayoutItem<'a> {
LayoutItem {
data: unsafe { Rc::from_raw(ffi_data.host_data as *const Cell<Option<*const RUBase>>) },
all_funcs: ffi_data.all_funcs,
owned: false,
_marker: PhantomData,
}
}
#[allow(dead_code)]
pub(crate) fn new_from_owned(ffi_data: RULayoutItem) -> LayoutItem<'a> {
LayoutItem {
data: Rc::new(Cell::new(Some(ffi_data.qt_data as *const RUBase))),
all_funcs: ffi_data.all_funcs,
owned: true,
_marker: PhantomData,
}
}
#[allow(dead_code)]
pub(crate) fn new_from_temporary(ffi_data: RULayoutItem) -> LayoutItem<'a> {
LayoutItem {
data: Rc::new(Cell::new(Some(ffi_data.qt_data as *const RUBase))),
all_funcs: ffi_data.all_funcs,
owned: false,
_marker: PhantomData,
}
}
///
/// Implemented in subclasses to return the preferred size of this item.
pub fn size_hint(&self) -> Size {
let (obj_data, funcs) = self.get_layout_item_obj_funcs();
unsafe {
let ret_val = ((*funcs).size_hint)(obj_data);
let t = ret_val;
let ret_val;
if t.host_data != ::std::ptr::null() {
ret_val = Size::new_from_rc(t);
} else {
ret_val = Size::new_from_owned(t);
}
ret_val
}
}
///
/// Implemented in subclasses to return the minimum size of this item.
pub fn minimum_size(&self) -> Size {
let (obj_data, funcs) = self.get_layout_item_obj_funcs();
unsafe {
let ret_val = ((*funcs).minimum_size)(obj_data);
let t = ret_val;
let ret_val;
if t.host_data != ::std::ptr::null() {
ret_val = Size::new_from_rc(t);
} else {
ret_val = Size::new_from_owned(t);
}
ret_val
}
}
///
/// Implemented in subclasses to return the maximum size of this item.
pub fn maximum_size(&self) -> Size {
let (obj_data, funcs) = self.get_layout_item_obj_funcs();
unsafe {
let ret_val = ((*funcs).maximum_size)(obj_data);
let t = ret_val;
let ret_val;
if t.host_data != ::std::ptr::null() {
ret_val = Size::new_from_rc(t);
} else {
ret_val = Size::new_from_owned(t);
}
ret_val
}
}
///
/// Returns whether this layout item can make use of more space than
/// sizeHint(). A value of Qt::Vertical or Qt::Horizontal means that
/// it wants to grow in only one dimension, whereas Qt::Vertical |
/// Qt::Horizontal means that it wants to grow in both dimensions.
pub fn expanding_directions(&self) -> Orientations {
let (obj_data, funcs) = self.get_layout_item_obj_funcs();
unsafe {
let ret_val = ((*funcs).expanding_directions)(obj_data);
let ret_val = Orientations::from_bits_truncate(ret_val);
ret_val
}
}
///
/// Implemented in subclasses to return whether this item is empty,
/// i.e. whether it contains any widgets.
pub fn is_empty(&self) -> bool {
let (obj_data, funcs) = self.get_layout_item_obj_funcs();
unsafe {
let ret_val = ((*funcs).is_empty)(obj_data);
ret_val
}
}
///
/// Returns `true` if this layout's preferred height depends on its
/// width; otherwise returns `false.` The default implementation returns
/// false.
///
/// Reimplement this function in layout managers that support height
/// for width.
///
/// **See also:** [`height_for_width()`]
/// [`Widget::height_for_width`]
pub fn has_height_for_width(&self) -> bool {
let (obj_data, funcs) = self.get_layout_item_obj_funcs();
unsafe {
let ret_val = ((*funcs).has_height_for_width)(obj_data);
ret_val
}
}
///
/// Returns the preferred height for this layout item, given the
/// width, which is not used in this default implementation.
///
/// The default implementation returns -1, indicating that the
/// preferred height is independent of the width of the item. Using
/// the function hasHeightForWidth() will typically be much faster
/// than calling this function and testing for -1.
///
/// Reimplement this function in layout managers that support height
/// for width. A typical implementation will look like this:
///
/// Caching is strongly recommended; without it layout will take
/// exponential time.
///
/// **See also:** [`has_height_for_width()`]
pub fn height_for_width(&self, arg0: i32) -> i32 {
let (obj_data, funcs) = self.get_layout_item_obj_funcs();
unsafe {
let ret_val = ((*funcs).height_for_width)(obj_data, arg0);
ret_val
}
}
///
/// Returns the minimum height this widget needs for the given width,
/// *w.* The default implementation simply returns heightForWidth( *w).*
pub fn minimum_height_for_width(&self, arg0: i32) -> i32 {
let (obj_data, funcs) = self.get_layout_item_obj_funcs();
unsafe {
let ret_val = ((*funcs).minimum_height_for_width)(obj_data, arg0);
ret_val
}
}
///
/// Invalidates any cached information in this layout item.
pub fn invalidate(&self) -> &Self {
let (obj_data, funcs) = self.get_layout_item_obj_funcs();
unsafe {
((*funcs).invalidate)(obj_data);
}
self
}
///
/// If this item manages a QWidget, returns that widget. Otherwise,
/// `nullptr` is returned.
///
/// **Note**: While the functions layout() and spacerItem() perform casts, this
/// function returns another object: QLayout and QSpacerItem inherit QLayoutItem,
/// while QWidget does not.
///
/// **See also:** [`layout()`]
/// [`spacer_item()`]
pub fn widget(&self) -> Option<Widget> {
let (obj_data, funcs) = self.get_layout_item_obj_funcs();
unsafe {
let ret_val = ((*funcs).widget)(obj_data);
if ret_val.qt_data == ::std::ptr::null() {
return None;
}
let t = ret_val;
let ret_val;
if t.host_data != ::std::ptr::null() {
ret_val = Widget::new_from_rc(t);
} else {
ret_val = Widget::new_from_owned(t);
}
Some(ret_val)
}
}
///
/// If this item is a QLayout, it is returned as a QLayout; otherwise
/// 0 is returned. This function provides type-safe casting.
///
/// **See also:** [`spacer_item()`]
/// [`widget()`]
pub fn layout(&self) -> Option<Layout> {
let (obj_data, funcs) = self.get_layout_item_obj_funcs();
unsafe {
let ret_val = ((*funcs).layout)(obj_data);
if ret_val.qt_data == ::std::ptr::null() {
return None;
}
let t = ret_val;
let ret_val;
if t.host_data != ::std::ptr::null() {
ret_val = Layout::new_from_rc(t);
} else {
ret_val = Layout::new_from_owned(t);
}
Some(ret_val)
}
}
///
/// If this item is a QSpacerItem, it is returned as a QSpacerItem;
/// otherwise 0 is returned. This function provides type-safe casting.
///
/// **See also:** [`layout()`]
/// [`widget()`]
pub fn spacer_item(&self) -> Option<SpacerItem> {
let (obj_data, funcs) = self.get_layout_item_obj_funcs();
unsafe {
let ret_val = ((*funcs).spacer_item)(obj_data);
if ret_val.qt_data == ::std::ptr::null() {
return None;
}
let t = ret_val;
let ret_val;
if t.host_data != ::std::ptr::null() {
ret_val = SpacerItem::new_from_rc(t);
} else {
ret_val = SpacerItem::new_from_owned(t);
}
Some(ret_val)
}
}
///
/// Returns the alignment of this item.
pub fn alignment(&self) -> Alignment {
let (obj_data, funcs) = self.get_layout_item_obj_funcs();
unsafe {
let ret_val = ((*funcs).alignment)(obj_data);
let ret_val = Alignment::from_bits_truncate(ret_val);
ret_val
}
}
///
/// Sets the alignment of this item to *alignment.*
///
/// **Note:** Item alignment is only supported by QLayoutItem subclasses
/// where it would have a visual effect. Except for QSpacerItem, which provides
/// blank space for layouts, all public Qt classes that inherit QLayoutItem
/// support item alignment.
pub fn set_alignment(&self, a: Alignment) -> &Self {
let enum_a_1 = a.bits();
let (obj_data, funcs) = self.get_layout_item_obj_funcs();
unsafe {
((*funcs).set_alignment)(obj_data, enum_a_1);
}
self
}
pub fn build(&self) -> Self {
self.clone()
}
}
pub trait LayoutItemTrait<'a> {
#[inline]
#[doc(hidden)]
fn get_layout_item_obj_funcs(&self) -> (*const RUBase, *const RULayoutItemFuncs);
}
impl<'a> LayoutItemTrait<'a> for LayoutItem<'a> {
#[doc(hidden)]
fn get_layout_item_obj_funcs(&self) -> (*const RUBase, *const RULayoutItemFuncs) {
let obj = self.data.get().unwrap();
unsafe { (obj, (*self.all_funcs).layout_item_funcs) }
}
}