1 /* 2 * This file is part of d-handy. 3 * 4 * d-handy is free software; you can redistribute it and/or modify 5 * it under the terms of the GNU Lesser General Public License 6 * as published by the Free Software Foundation; either version 3 7 * of the License, or (at your option) any later version, with 8 * some exceptions, please read the COPYING file. 9 * 10 * d-handy is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU Lesser General Public License for more details. 14 * 15 * You should have received a copy of the GNU Lesser General Public License 16 * along with d-handy; if not, write to the Free Software 17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA 18 */ 19 module handy.Leaflet; 20 21 private import glib.ConstructionException; 22 private import glib.Str; 23 private import gobject.ObjectG; 24 private import gtk.BuildableIF; 25 private import gtk.BuildableT; 26 private import gtk.Container; 27 private import gtk.OrientableIF; 28 private import gtk.OrientableT; 29 private import gtk.Widget; 30 private import handy.SwipeableIF; 31 private import handy.SwipeableT; 32 private import handy.c.functions; 33 public import handy.c.types; 34 35 36 /** */ 37 public class Leaflet : Container, OrientableIF, SwipeableIF 38 { 39 /** the main Gtk struct */ 40 protected HdyLeaflet* hdyLeaflet; 41 42 /** Get the main Gtk struct */ 43 public HdyLeaflet* getLeafletStruct(bool transferOwnership = false) 44 { 45 if (transferOwnership) 46 ownedRef = false; 47 return hdyLeaflet; 48 } 49 50 /** the main Gtk struct as a void* */ 51 protected override void* getStruct() 52 { 53 return cast(void*)hdyLeaflet; 54 } 55 56 /** 57 * Sets our main struct and passes it to the parent class. 58 */ 59 public this (HdyLeaflet* hdyLeaflet, bool ownedRef = false) 60 { 61 this.hdyLeaflet = hdyLeaflet; 62 super(cast(GtkContainer*)hdyLeaflet, ownedRef); 63 } 64 65 // add the Orientable capabilities 66 mixin OrientableT!(HdyLeaflet); 67 68 // add the Swipeable capabilities 69 mixin SwipeableT!(HdyLeaflet); 70 71 72 /** */ 73 public static GType getType() 74 { 75 return hdy_leaflet_get_type(); 76 } 77 78 /** */ 79 public this() 80 { 81 auto __p = hdy_leaflet_new(); 82 83 if(__p is null) 84 { 85 throw new ConstructionException("null returned by new"); 86 } 87 88 this(cast(HdyLeaflet*) __p); 89 } 90 91 /** 92 * Gets the previous or next child that doesn't have 'navigatable' child 93 * property set to %FALSE, or %NULL if it doesn't exist. This will be the same 94 * widget hdy_leaflet_navigate() will navigate to. 95 * 96 * Params: 97 * direction = the direction 98 * 99 * Returns: the previous or next child, or 100 * %NULL if it doesn't exist. 101 * 102 * Since: 1.0 103 */ 104 public Widget getAdjacentChild(HdyNavigationDirection direction) 105 { 106 auto __p = hdy_leaflet_get_adjacent_child(hdyLeaflet, direction); 107 108 if(__p is null) 109 { 110 return null; 111 } 112 113 return ObjectG.getDObject!(Widget)(cast(GtkWidget*) __p); 114 } 115 116 /** 117 * Returns whether the #HdyLeaflet allows swiping to the previous child. 118 * 119 * Returns: %TRUE if back swipe is enabled. 120 * 121 * Since: 0.0.12 122 */ 123 public bool getCanSwipeBack() 124 { 125 return hdy_leaflet_get_can_swipe_back(hdyLeaflet) != 0; 126 } 127 128 /** 129 * Returns whether the #HdyLeaflet allows swiping to the next child. 130 * 131 * Returns: %TRUE if forward swipe is enabled. 132 * 133 * Since: 0.0.12 134 */ 135 public bool getCanSwipeForward() 136 { 137 return hdy_leaflet_get_can_swipe_forward(hdyLeaflet) != 0; 138 } 139 140 /** 141 * Finds the child of @self with the name given as the argument. Returns %NULL 142 * if there is no child with this name. 143 * 144 * Params: 145 * name = the name of the child to find 146 * 147 * Returns: the requested child of @self 148 * 149 * Since: 1.0 150 */ 151 public Widget getChildByName(string name) 152 { 153 auto __p = hdy_leaflet_get_child_by_name(hdyLeaflet, Str.toStringz(name)); 154 155 if(__p is null) 156 { 157 return null; 158 } 159 160 return ObjectG.getDObject!(Widget)(cast(GtkWidget*) __p); 161 } 162 163 /** 164 * Returns the amount of time (in milliseconds) that 165 * transitions between children in @self will take. 166 * 167 * Returns: the child transition duration 168 */ 169 public uint getChildTransitionDuration() 170 { 171 return hdy_leaflet_get_child_transition_duration(hdyLeaflet); 172 } 173 174 /** 175 * Returns whether @self is currently in a transition from one page to 176 * another. 177 * 178 * Returns: %TRUE if the transition is currently running, %FALSE otherwise. 179 */ 180 public bool getChildTransitionRunning() 181 { 182 return hdy_leaflet_get_child_transition_running(hdyLeaflet) != 0; 183 } 184 185 /** 186 * Gets whether @self is folded. 187 * 188 * Returns: whether @self is folded. 189 */ 190 public bool getFolded() 191 { 192 return hdy_leaflet_get_folded(hdyLeaflet) != 0; 193 } 194 195 /** 196 * Gets whether @self is homogeneous for the given fold and orientation. 197 * See hdy_leaflet_set_homogeneous(). 198 * 199 * Params: 200 * folded = the fold 201 * orientation = the orientation 202 * 203 * Returns: whether @self is homogeneous for the given fold and orientation. 204 */ 205 public bool getHomogeneous(bool folded, GtkOrientation orientation) 206 { 207 return hdy_leaflet_get_homogeneous(hdyLeaflet, folded, orientation) != 0; 208 } 209 210 /** 211 * Returns whether the #HdyLeaflet is set up to interpolate between 212 * the sizes of children on page switch. 213 * 214 * Returns: %TRUE if child sizes are interpolated 215 */ 216 public bool getInterpolateSize() 217 { 218 return hdy_leaflet_get_interpolate_size(hdyLeaflet) != 0; 219 } 220 221 /** 222 * Returns the amount of time (in milliseconds) that 223 * transitions between modes in @self will take. 224 * 225 * Returns: the mode transition duration 226 */ 227 public uint getModeTransitionDuration() 228 { 229 return hdy_leaflet_get_mode_transition_duration(hdyLeaflet); 230 } 231 232 /** 233 * Gets the type of animation that will be used 234 * for transitions between modes and children in @self. 235 * 236 * Returns: the current transition type of @self 237 * 238 * Since: 0.0.12 239 */ 240 public HdyLeafletTransitionType getTransitionType() 241 { 242 return hdy_leaflet_get_transition_type(hdyLeaflet); 243 } 244 245 /** 246 * Gets the visible child widget. 247 * 248 * Returns: the visible child widget 249 */ 250 public Widget getVisibleChild() 251 { 252 auto __p = hdy_leaflet_get_visible_child(hdyLeaflet); 253 254 if(__p is null) 255 { 256 return null; 257 } 258 259 return ObjectG.getDObject!(Widget)(cast(GtkWidget*) __p); 260 } 261 262 /** 263 * Gets the name of the currently visible child widget. 264 * 265 * Returns: the name of the visible child 266 */ 267 public string getVisibleChildName() 268 { 269 return Str.toString(hdy_leaflet_get_visible_child_name(hdyLeaflet)); 270 } 271 272 /** 273 * Switches to the previous or next child that doesn't have 'navigatable' child 274 * property set to %FALSE, similar to performing a swipe gesture to go in 275 * @direction. 276 * 277 * Params: 278 * direction = the direction 279 * 280 * Returns: %TRUE if visible child was changed, %FALSE otherwise. 281 * 282 * Since: 1.0 283 */ 284 public bool navigate(HdyNavigationDirection direction) 285 { 286 return hdy_leaflet_navigate(hdyLeaflet, direction) != 0; 287 } 288 289 /** 290 * Sets whether or not @self allows switching to the previous child that has 291 * 'navigatable' child property set to %TRUE via a swipe gesture 292 * 293 * Params: 294 * canSwipeBack = the new value 295 * 296 * Since: 0.0.12 297 */ 298 public void setCanSwipeBack(bool canSwipeBack) 299 { 300 hdy_leaflet_set_can_swipe_back(hdyLeaflet, canSwipeBack); 301 } 302 303 /** 304 * Sets whether or not @self allows switching to the next child that has 305 * 'navigatable' child property set to %TRUE via a swipe gesture. 306 * 307 * Params: 308 * canSwipeForward = the new value 309 * 310 * Since: 0.0.12 311 */ 312 public void setCanSwipeForward(bool canSwipeForward) 313 { 314 hdy_leaflet_set_can_swipe_forward(hdyLeaflet, canSwipeForward); 315 } 316 317 /** 318 * Sets the duration that transitions between children in @self 319 * will take. 320 * 321 * Params: 322 * duration = the new duration, in milliseconds 323 */ 324 public void setChildTransitionDuration(uint duration) 325 { 326 hdy_leaflet_set_child_transition_duration(hdyLeaflet, duration); 327 } 328 329 /** 330 * Sets the #HdyLeaflet to be homogeneous or not for the given fold and orientation. 331 * If it is homogeneous, the #HdyLeaflet will request the same 332 * width or height for all its children depending on the orientation. 333 * If it isn't and it is folded, the leaflet may change width or height 334 * when a different child becomes visible. 335 * 336 * Params: 337 * folded = the fold 338 * orientation = the orientation 339 * homogeneous = %TRUE to make @self homogeneous 340 */ 341 public void setHomogeneous(bool folded, GtkOrientation orientation, bool homogeneous) 342 { 343 hdy_leaflet_set_homogeneous(hdyLeaflet, folded, orientation, homogeneous); 344 } 345 346 /** 347 * Sets whether or not @self will interpolate its size when 348 * changing the visible child. If the #HdyLeaflet:interpolate-size 349 * property is set to %TRUE, @self will interpolate its size between 350 * the current one and the one it'll take after changing the 351 * visible child, according to the set transition duration. 352 * 353 * Params: 354 * interpolateSize = the new value 355 */ 356 public void setInterpolateSize(bool interpolateSize) 357 { 358 hdy_leaflet_set_interpolate_size(hdyLeaflet, interpolateSize); 359 } 360 361 /** 362 * Sets the duration that transitions between modes in @self 363 * will take. 364 * 365 * Params: 366 * duration = the new duration, in milliseconds 367 */ 368 public void setModeTransitionDuration(uint duration) 369 { 370 hdy_leaflet_set_mode_transition_duration(hdyLeaflet, duration); 371 } 372 373 /** 374 * Sets the type of animation that will be used for transitions between modes 375 * and children in @self. 376 * 377 * The transition type can be changed without problems at runtime, so it is 378 * possible to change the animation based on the mode or child that is about to 379 * become current. 380 * 381 * Params: 382 * transition = the new transition type 383 * 384 * Since: 0.0.12 385 */ 386 public void setTransitionType(HdyLeafletTransitionType transition) 387 { 388 hdy_leaflet_set_transition_type(hdyLeaflet, transition); 389 } 390 391 /** 392 * Makes @visible_child visible using a transition determined by 393 * HdyLeaflet:transition-type and HdyLeaflet:child-transition-duration. The 394 * transition can be cancelled by the user, in which case visible child will 395 * change back to the previously visible child. 396 * 397 * Params: 398 * visibleChild = the new child 399 */ 400 public void setVisibleChild(Widget visibleChild) 401 { 402 hdy_leaflet_set_visible_child(hdyLeaflet, (visibleChild is null) ? null : visibleChild.getWidgetStruct()); 403 } 404 405 /** 406 * Makes the child with the name @name visible. 407 * 408 * See hdy_leaflet_set_visible_child() for more details. 409 * 410 * Params: 411 * name = the name of a child 412 */ 413 public void setVisibleChildName(string name) 414 { 415 hdy_leaflet_set_visible_child_name(hdyLeaflet, Str.toStringz(name)); 416 } 417 }