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.Paginator; 20 21 private import glib.ConstructionException; 22 private import gobject.ObjectG; 23 private import gtk.BuildableIF; 24 private import gtk.BuildableT; 25 private import gtk.EventBox; 26 private import gtk.OrientableIF; 27 private import gtk.OrientableT; 28 private import gtk.Widget; 29 private import handy.c.functions; 30 public import handy.c.types; 31 32 33 /** */ 34 public class Paginator : EventBox, OrientableIF 35 { 36 /** the main Gtk struct */ 37 protected HdyPaginator* hdyPaginator; 38 39 /** Get the main Gtk struct */ 40 public HdyPaginator* getPaginatorStruct(bool transferOwnership = false) 41 { 42 if (transferOwnership) 43 ownedRef = false; 44 return hdyPaginator; 45 } 46 47 /** the main Gtk struct as a void* */ 48 protected override void* getStruct() 49 { 50 return cast(void*)hdyPaginator; 51 } 52 53 /** 54 * Sets our main struct and passes it to the parent class. 55 */ 56 public this (HdyPaginator* hdyPaginator, bool ownedRef = false) 57 { 58 this.hdyPaginator = hdyPaginator; 59 super(cast(GtkEventBox*)hdyPaginator, ownedRef); 60 } 61 62 // add the Orientable capabilities 63 mixin OrientableT!(HdyPaginator); 64 65 66 /** */ 67 public static GType getType() 68 { 69 return hdy_paginator_get_type(); 70 } 71 72 /** 73 * Create a new #HdyPaginator widget. 74 * 75 * Returns: The newly created #HdyPaginator widget 76 * 77 * Since: 0.0.11 78 * 79 * Throws: ConstructionException GTK+ fails to create the object. 80 */ 81 public this() 82 { 83 auto p = hdy_paginator_new(); 84 85 if(p is null) 86 { 87 throw new ConstructionException("null returned by new"); 88 } 89 90 this(cast(HdyPaginator*) p); 91 } 92 93 /** 94 * Gets animation duration used by hdy_paginator_scroll_to(). 95 * 96 * Returns: Animation duration in milliseconds 97 * 98 * Since: 0.0.11 99 */ 100 public uint getAnimationDuration() 101 { 102 return hdy_paginator_get_animation_duration(hdyPaginator); 103 } 104 105 /** 106 * Sets whether @self is centering pages. 107 * 108 * Returns: %TRUE if @self is centering pages 109 * 110 * Since: 0.0.11 111 */ 112 public bool getCenterContent() 113 { 114 return hdy_paginator_get_center_content(hdyPaginator) != 0; 115 } 116 117 /** 118 * Gets spacing between content and page indicators. 119 * 120 * Returns: Spacing between content and indicators 121 * 122 * Since: 0.0.11 123 */ 124 public uint getIndicatorSpacing() 125 { 126 return hdy_paginator_get_indicator_spacing(hdyPaginator); 127 } 128 129 /** 130 * Gets the current page indicator style. 131 * 132 * Returns: the current indicator style 133 * 134 * Since: 0.0.11 135 */ 136 public HdyPaginatorIndicatorStyle getIndicatorStyle() 137 { 138 return hdy_paginator_get_indicator_style(hdyPaginator); 139 } 140 141 /** 142 * Gets whether @self can be navigated. 143 * 144 * Returns: %TRUE if @self can be swiped 145 * 146 * Since: 0.0.11 147 */ 148 public bool getInteractive() 149 { 150 return hdy_paginator_get_interactive(hdyPaginator) != 0; 151 } 152 153 /** 154 * Gets the number of pages in @self. 155 * 156 * Returns: The number of pages in @self 157 * 158 * Since: 0.0.11 159 */ 160 public uint getNPages() 161 { 162 return hdy_paginator_get_n_pages(hdyPaginator); 163 } 164 165 /** 166 * Gets current scroll position in @self. It's unitless, 1 matches 1 page. 167 * 168 * Returns: The scroll position 169 * 170 * Since: 0.0.11 171 */ 172 public double getPosition() 173 { 174 return hdy_paginator_get_position(hdyPaginator); 175 } 176 177 /** 178 * Gets spacing between pages in pixels. 179 * 180 * Returns: Spacing between pages 181 * 182 * Since: 0.0.11 183 */ 184 public uint getSpacing() 185 { 186 return hdy_paginator_get_spacing(hdyPaginator); 187 } 188 189 /** 190 * Inserts @child into @self at position @position. 191 * 192 * If position is -1, or larger than the number of pages, 193 * @child will be appended to the end. 194 * 195 * Params: 196 * child = a widget to add 197 * position = the position to insert @child in. 198 * 199 * Since: 0.0.11 200 */ 201 public void insert(Widget child, int position) 202 { 203 hdy_paginator_insert(hdyPaginator, (child is null) ? null : child.getWidgetStruct(), position); 204 } 205 206 /** 207 * Prepends @child to @self 208 * 209 * Params: 210 * child = a widget to add 211 * 212 * Since: 0.0.11 213 */ 214 public void prepend(Widget child) 215 { 216 hdy_paginator_prepend(hdyPaginator, (child is null) ? null : child.getWidgetStruct()); 217 } 218 219 /** 220 * Moves @child into position @position. 221 * 222 * If position is -1, or larger than the number of pages, @child will be moved 223 * to the end. 224 * 225 * Params: 226 * child = a widget to add 227 * position = the position to move @child to. 228 * 229 * Since: 0.0.11 230 */ 231 public void reorder(Widget child, int position) 232 { 233 hdy_paginator_reorder(hdyPaginator, (child is null) ? null : child.getWidgetStruct(), position); 234 } 235 236 /** 237 * Scrolls to @widget position with an animation. 238 * #HdyPaginator:animation-duration property can be used for controlling the 239 * duration. 240 * 241 * Params: 242 * widget = a child of @self 243 * 244 * Since: 0.0.11 245 */ 246 public void scrollTo(Widget widget) 247 { 248 hdy_paginator_scroll_to(hdyPaginator, (widget is null) ? null : widget.getWidgetStruct()); 249 } 250 251 /** 252 * Scrolls to @widget position with an animation. 253 * 254 * Params: 255 * widget = a child of @self 256 * duration = animation duration in milliseconds 257 * 258 * Since: 0.0.11 259 */ 260 public void scrollToFull(Widget widget, long duration) 261 { 262 hdy_paginator_scroll_to_full(hdyPaginator, (widget is null) ? null : widget.getWidgetStruct(), duration); 263 } 264 265 /** 266 * Sets animation duration used by hdy_paginator_scroll_to(). 267 * 268 * Params: 269 * duration = animation duration in milliseconds 270 * 271 * Since: 0.0.11 272 */ 273 public void setAnimationDuration(uint duration) 274 { 275 hdy_paginator_set_animation_duration(hdyPaginator, duration); 276 } 277 278 /** 279 * Sets whether @self is centering content. If #HdyPaginator:indicator-style is 280 * @HDY_PAGINATOR_INDICATOR_STYLE_NONE, centering does nothing, otherwise it 281 * adds whitespace to the left or above the pages to compensate for the 282 * indicators. 283 * 284 * Params: 285 * centerContent = whether @self should center contents 286 * 287 * Since: 0.0.11 288 */ 289 public void setCenterContent(bool centerContent) 290 { 291 hdy_paginator_set_center_content(hdyPaginator, centerContent); 292 } 293 294 /** 295 * Sets spacing between content and page indicators. Does nothing if 296 * #HdyPaginator:indicator-style is @HDY_PAGINATOR_INDICATOR_STYLE_NONE. 297 * 298 * Params: 299 * spacing = the new spacing value 300 * 301 * Since: 0.0.11 302 */ 303 public void setIndicatorSpacing(uint spacing) 304 { 305 hdy_paginator_set_indicator_spacing(hdyPaginator, spacing); 306 } 307 308 /** 309 * Sets style of page indicators. Depending on orientation, they are displayed 310 * below or besides the pages. If the pages are meant to be centered, 311 * #HdyPaginator:center-content can be used to compensate for that. 312 * 313 * Params: 314 * style = indicator style to use 315 * 316 * Since: 0.0.11 317 */ 318 public void setIndicatorStyle(HdyPaginatorIndicatorStyle style) 319 { 320 hdy_paginator_set_indicator_style(hdyPaginator, style); 321 } 322 323 /** 324 * Sets whether @self can be navigated. This can be used to temporarily disable 325 * a #HdyPaginator to only allow swiping in a certain state. 326 * 327 * Params: 328 * interactive = whether @self can be swiped. 329 * 330 * Since: 0.0.11 331 */ 332 public void setInteractive(bool interactive) 333 { 334 hdy_paginator_set_interactive(hdyPaginator, interactive); 335 } 336 337 /** 338 * Sets spacing between pages in pixels. 339 * 340 * Params: 341 * spacing = the new spacing value 342 * 343 * Since: 0.0.11 344 */ 345 public void setSpacing(uint spacing) 346 { 347 hdy_paginator_set_spacing(hdyPaginator, spacing); 348 } 349 }