libadwaita/auto/
sidebar_section.rs1use crate::{ffi, Sidebar, SidebarItem};
7use glib::{
8 prelude::*,
9 signal::{connect_raw, SignalHandlerId},
10 translate::*,
11};
12use std::boxed::Box as Box_;
13
14glib::wrapper! {
15 #[doc(alias = "AdwSidebarSection")]
16 pub struct SidebarSection(Object<ffi::AdwSidebarSection, ffi::AdwSidebarSectionClass>) @implements gtk::Buildable;
17
18 match fn {
19 type_ => || ffi::adw_sidebar_section_get_type(),
20 }
21}
22
23impl SidebarSection {
24 #[doc(alias = "adw_sidebar_section_new")]
25 pub fn new() -> SidebarSection {
26 assert_initialized_main_thread!();
27 unsafe { from_glib_full(ffi::adw_sidebar_section_new()) }
28 }
29
30 #[doc(alias = "adw_sidebar_section_append")]
31 pub fn append(&self, item: impl IsA<SidebarItem>) {
32 unsafe {
33 ffi::adw_sidebar_section_append(self.to_glib_none().0, item.upcast().into_glib_ptr());
34 }
35 }
36
37 #[doc(alias = "adw_sidebar_section_bind_model")]
38 pub fn bind_model<P: Fn(&glib::Object) -> SidebarItem + 'static>(
39 &self,
40 model: Option<&impl IsA<gio::ListModel>>,
41 create_item_func: P,
42 ) {
43 let create_item_func_data: Box_<P> = Box_::new(create_item_func);
44 unsafe extern "C" fn create_item_func_func<
45 P: Fn(&glib::Object) -> SidebarItem + 'static,
46 >(
47 item: *mut glib::gobject_ffi::GObject,
48 user_data: glib::ffi::gpointer,
49 ) -> *mut ffi::AdwSidebarItem {
50 let item = from_glib_borrow(item);
51 let callback = &*(user_data as *mut P);
52 (*callback)(&item).to_glib_full()
53 }
54 let create_item_func = Some(create_item_func_func::<P> as _);
55 unsafe extern "C" fn user_data_free_func_func<
56 P: Fn(&glib::Object) -> SidebarItem + 'static,
57 >(
58 data: glib::ffi::gpointer,
59 ) {
60 let _callback = Box_::from_raw(data as *mut P);
61 }
62 let destroy_call4 = Some(user_data_free_func_func::<P> as _);
63 let super_callback0: Box_<P> = create_item_func_data;
64 unsafe {
65 ffi::adw_sidebar_section_bind_model(
66 self.to_glib_none().0,
67 model.map(|p| p.as_ref()).to_glib_none().0,
68 create_item_func,
69 Box_::into_raw(super_callback0) as *mut _,
70 destroy_call4,
71 );
72 }
73 }
74
75 #[doc(alias = "adw_sidebar_section_get_item")]
76 #[doc(alias = "get_item")]
77 pub fn item(&self, index: u32) -> Option<SidebarItem> {
78 unsafe {
79 from_glib_none(ffi::adw_sidebar_section_get_item(
80 self.to_glib_none().0,
81 index,
82 ))
83 }
84 }
85
86 #[doc(alias = "adw_sidebar_section_get_items")]
87 #[doc(alias = "get_items")]
88 pub fn items(&self) -> gio::ListModel {
89 unsafe { from_glib_full(ffi::adw_sidebar_section_get_items(self.to_glib_none().0)) }
90 }
91
92 #[doc(alias = "adw_sidebar_section_get_sidebar")]
93 #[doc(alias = "get_sidebar")]
94 pub fn sidebar(&self) -> Option<Sidebar> {
95 unsafe { from_glib_none(ffi::adw_sidebar_section_get_sidebar(self.to_glib_none().0)) }
96 }
97
98 #[doc(alias = "adw_sidebar_section_get_title")]
99 #[doc(alias = "get_title")]
100 pub fn title(&self) -> Option<glib::GString> {
101 unsafe { from_glib_none(ffi::adw_sidebar_section_get_title(self.to_glib_none().0)) }
102 }
103
104 #[doc(alias = "adw_sidebar_section_insert")]
105 pub fn insert(&self, item: impl IsA<SidebarItem>, position: i32) {
106 unsafe {
107 ffi::adw_sidebar_section_insert(
108 self.to_glib_none().0,
109 item.upcast().into_glib_ptr(),
110 position,
111 );
112 }
113 }
114
115 #[doc(alias = "adw_sidebar_section_prepend")]
116 pub fn prepend(&self, item: impl IsA<SidebarItem>) {
117 unsafe {
118 ffi::adw_sidebar_section_prepend(self.to_glib_none().0, item.upcast().into_glib_ptr());
119 }
120 }
121
122 #[doc(alias = "adw_sidebar_section_remove")]
123 pub fn remove(&self, item: &impl IsA<SidebarItem>) {
124 unsafe {
125 ffi::adw_sidebar_section_remove(self.to_glib_none().0, item.as_ref().to_glib_none().0);
126 }
127 }
128
129 #[doc(alias = "adw_sidebar_section_remove_all")]
130 pub fn remove_all(&self) {
131 unsafe {
132 ffi::adw_sidebar_section_remove_all(self.to_glib_none().0);
133 }
134 }
135
136 #[doc(alias = "adw_sidebar_section_set_title")]
137 #[doc(alias = "title")]
138 pub fn set_title(&self, title: Option<&str>) {
139 unsafe {
140 ffi::adw_sidebar_section_set_title(self.to_glib_none().0, title.to_glib_none().0);
141 }
142 }
143
144 #[cfg(feature = "v1_9")]
145 #[cfg_attr(docsrs, doc(cfg(feature = "v1_9")))]
146 #[doc(alias = "items")]
147 pub fn connect_items_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
148 unsafe extern "C" fn notify_items_trampoline<F: Fn(&SidebarSection) + 'static>(
149 this: *mut ffi::AdwSidebarSection,
150 _param_spec: glib::ffi::gpointer,
151 f: glib::ffi::gpointer,
152 ) {
153 let f: &F = &*(f as *const F);
154 f(&from_glib_borrow(this))
155 }
156 unsafe {
157 let f: Box_<F> = Box_::new(f);
158 connect_raw(
159 self.as_ptr() as *mut _,
160 c"notify::items".as_ptr() as *const _,
161 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
162 notify_items_trampoline::<F> as *const (),
163 )),
164 Box_::into_raw(f),
165 )
166 }
167 }
168
169 #[cfg(feature = "v1_9")]
170 #[cfg_attr(docsrs, doc(cfg(feature = "v1_9")))]
171 #[doc(alias = "sidebar")]
172 pub fn connect_sidebar_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
173 unsafe extern "C" fn notify_sidebar_trampoline<F: Fn(&SidebarSection) + 'static>(
174 this: *mut ffi::AdwSidebarSection,
175 _param_spec: glib::ffi::gpointer,
176 f: glib::ffi::gpointer,
177 ) {
178 let f: &F = &*(f as *const F);
179 f(&from_glib_borrow(this))
180 }
181 unsafe {
182 let f: Box_<F> = Box_::new(f);
183 connect_raw(
184 self.as_ptr() as *mut _,
185 c"notify::sidebar".as_ptr() as *const _,
186 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
187 notify_sidebar_trampoline::<F> as *const (),
188 )),
189 Box_::into_raw(f),
190 )
191 }
192 }
193
194 #[cfg(feature = "v1_9")]
195 #[cfg_attr(docsrs, doc(cfg(feature = "v1_9")))]
196 #[doc(alias = "title")]
197 pub fn connect_title_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
198 unsafe extern "C" fn notify_title_trampoline<F: Fn(&SidebarSection) + 'static>(
199 this: *mut ffi::AdwSidebarSection,
200 _param_spec: glib::ffi::gpointer,
201 f: glib::ffi::gpointer,
202 ) {
203 let f: &F = &*(f as *const F);
204 f(&from_glib_borrow(this))
205 }
206 unsafe {
207 let f: Box_<F> = Box_::new(f);
208 connect_raw(
209 self.as_ptr() as *mut _,
210 c"notify::title".as_ptr() as *const _,
211 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
212 notify_title_trampoline::<F> as *const (),
213 )),
214 Box_::into_raw(f),
215 )
216 }
217 }
218}
219
220#[cfg(feature = "v1_9")]
221#[cfg_attr(docsrs, doc(cfg(feature = "v1_9")))]
222impl Default for SidebarSection {
223 fn default() -> Self {
224 Self::new()
225 }
226}