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.Carousel; 20 21 private import glib.ConstructionException; 22 private import gobject.ObjectG; 23 private import gobject.Signals; 24 private import gtk.BuildableIF; 25 private import gtk.BuildableT; 26 private import gtk.EventBox; 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 private import std.algorithm; 35 36 37 /** */ 38 public class Carousel : EventBox, OrientableIF, SwipeableIF 39 { 40 /** the main Gtk struct */ 41 protected HdyCarousel* hdyCarousel; 42 43 /** Get the main Gtk struct */ 44 public HdyCarousel* getCarouselStruct(bool transferOwnership = false) 45 { 46 if (transferOwnership) 47 ownedRef = false; 48 return hdyCarousel; 49 } 50 51 /** the main Gtk struct as a void* */ 52 protected override void* getStruct() 53 { 54 return cast(void*)hdyCarousel; 55 } 56 57 /** 58 * Sets our main struct and passes it to the parent class. 59 */ 60 public this (HdyCarousel* hdyCarousel, bool ownedRef = false) 61 { 62 this.hdyCarousel = hdyCarousel; 63 super(cast(GtkEventBox*)hdyCarousel, ownedRef); 64 } 65 66 // add the Orientable capabilities 67 mixin OrientableT!(HdyCarousel); 68 69 // add the Swipeable capabilities 70 mixin SwipeableT!(HdyCarousel); 71 72 73 /** */ 74 public static GType getType() 75 { 76 return hdy_carousel_get_type(); 77 } 78 79 /** 80 * Create a new #HdyCarousel widget. 81 * 82 * Returns: The newly created #HdyCarousel widget 83 * 84 * Since: 1.0 85 * 86 * Throws: ConstructionException GTK+ fails to create the object. 87 */ 88 public this() 89 { 90 auto __p = hdy_carousel_new(); 91 92 if(__p is null) 93 { 94 throw new ConstructionException("null returned by new"); 95 } 96 97 this(cast(HdyCarousel*) __p); 98 } 99 100 /** 101 * Sets whether @self can be dragged with mouse pointer 102 * 103 * Returns: %TRUE if @self can be dragged with mouse 104 * 105 * Since: 1.0 106 */ 107 public bool getAllowMouseDrag() 108 { 109 return hdy_carousel_get_allow_mouse_drag(hdyCarousel) != 0; 110 } 111 112 /** 113 * Gets animation duration used by hdy_carousel_scroll_to(). 114 * 115 * Returns: Animation duration in milliseconds 116 * 117 * Since: 1.0 118 */ 119 public uint getAnimationDuration() 120 { 121 return hdy_carousel_get_animation_duration(hdyCarousel); 122 } 123 124 /** 125 * Gets whether @self can be navigated. 126 * 127 * Returns: %TRUE if @self can be swiped 128 * 129 * Since: 1.0 130 */ 131 public bool getInteractive() 132 { 133 return hdy_carousel_get_interactive(hdyCarousel) != 0; 134 } 135 136 /** 137 * Gets the number of pages in @self. 138 * 139 * Returns: The number of pages in @self 140 * 141 * Since: 1.0 142 */ 143 public uint getNPages() 144 { 145 return hdy_carousel_get_n_pages(hdyCarousel); 146 } 147 148 /** 149 * Gets current scroll position in @self. It's unitless, 1 matches 1 page. 150 * 151 * Returns: The scroll position 152 * 153 * Since: 1.0 154 */ 155 public double getPosition() 156 { 157 return hdy_carousel_get_position(hdyCarousel); 158 } 159 160 /** 161 * Gets duration of the animation used when adding or removing pages in 162 * milliseconds. 163 * 164 * Returns: Page reveal duration 165 * 166 * Since: 1.0 167 */ 168 public uint getRevealDuration() 169 { 170 return hdy_carousel_get_reveal_duration(hdyCarousel); 171 } 172 173 /** 174 * Gets spacing between pages in pixels. 175 * 176 * Returns: Spacing between pages 177 * 178 * Since: 1.0 179 */ 180 public uint getSpacing() 181 { 182 return hdy_carousel_get_spacing(hdyCarousel); 183 } 184 185 /** 186 * Inserts @child into @self at position @position. 187 * 188 * If position is -1, or larger than the number of pages, 189 * @child will be appended to the end. 190 * 191 * Params: 192 * child = a widget to add 193 * position = the position to insert @child in. 194 * 195 * Since: 1.0 196 */ 197 public void insert(Widget child, int position) 198 { 199 hdy_carousel_insert(hdyCarousel, (child is null) ? null : child.getWidgetStruct(), position); 200 } 201 202 /** 203 * Prepends @child to @self 204 * 205 * Params: 206 * child = a widget to add 207 * 208 * Since: 1.0 209 */ 210 public void prepend(Widget child) 211 { 212 hdy_carousel_prepend(hdyCarousel, (child is null) ? null : child.getWidgetStruct()); 213 } 214 215 /** 216 * Moves @child into position @position. 217 * 218 * If position is -1, or larger than the number of pages, @child will be moved 219 * to the end. 220 * 221 * Params: 222 * child = a widget to add 223 * position = the position to move @child to. 224 * 225 * Since: 1.0 226 */ 227 public void reorder(Widget child, int position) 228 { 229 hdy_carousel_reorder(hdyCarousel, (child is null) ? null : child.getWidgetStruct(), position); 230 } 231 232 /** 233 * Scrolls to @widget position with an animation. 234 * #HdyCarousel:animation-duration property can be used for controlling the 235 * duration. 236 * 237 * Params: 238 * widget = a child of @self 239 * 240 * Since: 1.0 241 */ 242 public void scrollTo(Widget widget) 243 { 244 hdy_carousel_scroll_to(hdyCarousel, (widget is null) ? null : widget.getWidgetStruct()); 245 } 246 247 /** 248 * Scrolls to @widget position with an animation. 249 * 250 * Params: 251 * widget = a child of @self 252 * duration = animation duration in milliseconds 253 * 254 * Since: 1.0 255 */ 256 public void scrollToFull(Widget widget, long duration) 257 { 258 hdy_carousel_scroll_to_full(hdyCarousel, (widget is null) ? null : widget.getWidgetStruct(), duration); 259 } 260 261 /** 262 * Sets whether @self can be dragged with mouse pointer. If @allow_mouse_drag 263 * is %FALSE, dragging is only available on touch. 264 * 265 * Params: 266 * allowMouseDrag = whether @self can be dragged with mouse pointer 267 * 268 * Since: 1.0 269 */ 270 public void setAllowMouseDrag(bool allowMouseDrag) 271 { 272 hdy_carousel_set_allow_mouse_drag(hdyCarousel, allowMouseDrag); 273 } 274 275 /** 276 * Sets animation duration used by hdy_carousel_scroll_to(). 277 * 278 * Params: 279 * duration = animation duration in milliseconds 280 * 281 * Since: 1.0 282 */ 283 public void setAnimationDuration(uint duration) 284 { 285 hdy_carousel_set_animation_duration(hdyCarousel, duration); 286 } 287 288 /** 289 * Sets whether @self can be navigated. This can be used to temporarily disable 290 * a #HdyCarousel to only allow swiping in a certain state. 291 * 292 * Params: 293 * interactive = whether @self can be swiped. 294 * 295 * Since: 1.0 296 */ 297 public void setInteractive(bool interactive) 298 { 299 hdy_carousel_set_interactive(hdyCarousel, interactive); 300 } 301 302 /** 303 * Sets duration of the animation used when adding or removing pages in 304 * milliseconds. 305 * 306 * Params: 307 * revealDuration = the new reveal duration value 308 * 309 * Since: 1.0 310 */ 311 public void setRevealDuration(uint revealDuration) 312 { 313 hdy_carousel_set_reveal_duration(hdyCarousel, revealDuration); 314 } 315 316 /** 317 * Sets spacing between pages in pixels. 318 * 319 * Params: 320 * spacing = the new spacing value 321 * 322 * Since: 1.0 323 */ 324 public void setSpacing(uint spacing) 325 { 326 hdy_carousel_set_spacing(hdyCarousel, spacing); 327 } 328 329 /** 330 * This signal is emitted after a page has been changed. This can be used to 331 * implement "infinite scrolling" by connecting to this signal and amending 332 * the pages. 333 * 334 * Params: 335 * index = Current page 336 * 337 * Since: 1.0 338 */ 339 gulong addOnPageChanged(void delegate(uint, Carousel) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 340 { 341 return Signals.connect(this, "page-changed", dlg, connectFlags ^ ConnectFlags.SWAPPED); 342 } 343 }