1 /** 2 Tabs control. 3 4 Copyright: 5 Copyright (c) 2007-2018 Juan Linietsky, Ariel Manzur. 6 Copyright (c) 2014-2018 Godot Engine contributors (cf. AUTHORS.md) 7 Copyright (c) 2017-2018 Godot-D contributors 8 9 License: $(LINK2 https://opensource.org/licenses/MIT, MIT License) 10 11 12 */ 13 module godot.tabs; 14 import std.meta : AliasSeq, staticIndexOf; 15 import std.traits : Unqual; 16 import godot.d.traits; 17 import godot.core; 18 import godot.c; 19 import godot.d.bind; 20 import godot.d.reference; 21 import godot.globalenums; 22 import godot.object; 23 import godot.classdb; 24 import godot.control; 25 import godot.canvasitem; 26 import godot.node; 27 import godot.inputevent; 28 import godot.texture; 29 /** 30 Tabs control. 31 32 Simple tabs control, similar to $(D TabContainer) but is only in charge of drawing tabs, not interacting with children. 33 */ 34 @GodotBaseClass struct Tabs 35 { 36 package(godot) enum string _GODOT_internal_name = "Tabs"; 37 public: 38 @nogc nothrow: 39 union { /** */ godot_object _godot_object; /** */ Control _GODOT_base; } 40 alias _GODOT_base this; 41 alias BaseClasses = AliasSeq!(typeof(_GODOT_base), typeof(_GODOT_base).BaseClasses); 42 package(godot) __gshared bool _classBindingInitialized = false; 43 package(godot) static struct GDNativeClassBinding 44 { 45 __gshared: 46 @GodotName("_gui_input") GodotMethod!(void, InputEvent) _guiInput; 47 @GodotName("_on_mouse_exited") GodotMethod!(void) _onMouseExited; 48 @GodotName("_update_hover") GodotMethod!(void) _updateHover; 49 @GodotName("add_tab") GodotMethod!(void, String, Texture) addTab; 50 @GodotName("ensure_tab_visible") GodotMethod!(void, long) ensureTabVisible; 51 @GodotName("get_current_tab") GodotMethod!(long) getCurrentTab; 52 @GodotName("get_drag_to_rearrange_enabled") GodotMethod!(bool) getDragToRearrangeEnabled; 53 @GodotName("get_offset_buttons_visible") GodotMethod!(bool) getOffsetButtonsVisible; 54 @GodotName("get_previous_tab") GodotMethod!(long) getPreviousTab; 55 @GodotName("get_scrolling_enabled") GodotMethod!(bool) getScrollingEnabled; 56 @GodotName("get_select_with_rmb") GodotMethod!(bool) getSelectWithRmb; 57 @GodotName("get_tab_align") GodotMethod!(Tabs.TabAlign) getTabAlign; 58 @GodotName("get_tab_close_display_policy") GodotMethod!(Tabs.CloseButtonDisplayPolicy) getTabCloseDisplayPolicy; 59 @GodotName("get_tab_count") GodotMethod!(long) getTabCount; 60 @GodotName("get_tab_disabled") GodotMethod!(bool, long) getTabDisabled; 61 @GodotName("get_tab_icon") GodotMethod!(Texture, long) getTabIcon; 62 @GodotName("get_tab_offset") GodotMethod!(long) getTabOffset; 63 @GodotName("get_tab_rect") GodotMethod!(Rect2, long) getTabRect; 64 @GodotName("get_tab_title") GodotMethod!(String, long) getTabTitle; 65 @GodotName("get_tabs_rearrange_group") GodotMethod!(long) getTabsRearrangeGroup; 66 @GodotName("move_tab") GodotMethod!(void, long, long) moveTab; 67 @GodotName("remove_tab") GodotMethod!(void, long) removeTab; 68 @GodotName("set_current_tab") GodotMethod!(void, long) setCurrentTab; 69 @GodotName("set_drag_to_rearrange_enabled") GodotMethod!(void, bool) setDragToRearrangeEnabled; 70 @GodotName("set_scrolling_enabled") GodotMethod!(void, bool) setScrollingEnabled; 71 @GodotName("set_select_with_rmb") GodotMethod!(void, bool) setSelectWithRmb; 72 @GodotName("set_tab_align") GodotMethod!(void, long) setTabAlign; 73 @GodotName("set_tab_close_display_policy") GodotMethod!(void, long) setTabCloseDisplayPolicy; 74 @GodotName("set_tab_disabled") GodotMethod!(void, long, bool) setTabDisabled; 75 @GodotName("set_tab_icon") GodotMethod!(void, long, Texture) setTabIcon; 76 @GodotName("set_tab_title") GodotMethod!(void, long, String) setTabTitle; 77 @GodotName("set_tabs_rearrange_group") GodotMethod!(void, long) setTabsRearrangeGroup; 78 } 79 /// 80 pragma(inline, true) bool opEquals(in Tabs other) const 81 { return _godot_object.ptr is other._godot_object.ptr; } 82 /// 83 pragma(inline, true) typeof(null) opAssign(typeof(null) n) 84 { _godot_object.ptr = n; return null; } 85 /// 86 pragma(inline, true) bool opEquals(typeof(null) n) const 87 { return _godot_object.ptr is n; } 88 /// 89 size_t toHash() const @trusted { return cast(size_t)_godot_object.ptr; } 90 mixin baseCasts; 91 /// Construct a new instance of Tabs. 92 /// Note: use `memnew!Tabs` instead. 93 static Tabs _new() 94 { 95 static godot_class_constructor constructor; 96 if(constructor is null) constructor = _godot_api.godot_get_class_constructor("Tabs"); 97 if(constructor is null) return typeof(this).init; 98 return cast(Tabs)(constructor()); 99 } 100 @disable new(size_t s); 101 /// 102 enum CloseButtonDisplayPolicy : int 103 { 104 /** 105 Never show the close buttons. 106 */ 107 closeButtonShowNever = 0, 108 /** 109 Only show the close button on the currently active tab. 110 */ 111 closeButtonShowActiveOnly = 1, 112 /** 113 Show the close button on all tabs. 114 */ 115 closeButtonShowAlways = 2, 116 /** 117 Represents the size of the $(D closebuttondisplaypolicy) enum. 118 */ 119 closeButtonMax = 3, 120 } 121 /// 122 enum TabAlign : int 123 { 124 /** 125 Align the tabs to the left. 126 */ 127 alignLeft = 0, 128 /** 129 Align the tabs to the center. 130 */ 131 alignCenter = 1, 132 /** 133 Align the tabs to the right. 134 */ 135 alignRight = 2, 136 /** 137 Represents the size of the $(D tabalign) enum. 138 */ 139 alignMax = 3, 140 } 141 /// 142 enum Constants : int 143 { 144 alignLeft = 0, 145 closeButtonShowNever = 0, 146 alignCenter = 1, 147 closeButtonShowActiveOnly = 1, 148 closeButtonShowAlways = 2, 149 alignRight = 2, 150 alignMax = 3, 151 closeButtonMax = 3, 152 } 153 /** 154 155 */ 156 void _guiInput(InputEvent arg0) 157 { 158 Array _GODOT_args = Array.make(); 159 _GODOT_args.append(arg0); 160 String _GODOT_method_name = String("_gui_input"); 161 this.callv(_GODOT_method_name, _GODOT_args); 162 } 163 /** 164 165 */ 166 void _onMouseExited() 167 { 168 Array _GODOT_args = Array.make(); 169 String _GODOT_method_name = String("_on_mouse_exited"); 170 this.callv(_GODOT_method_name, _GODOT_args); 171 } 172 /** 173 174 */ 175 void _updateHover() 176 { 177 Array _GODOT_args = Array.make(); 178 String _GODOT_method_name = String("_update_hover"); 179 this.callv(_GODOT_method_name, _GODOT_args); 180 } 181 /** 182 Adds a new tab. 183 */ 184 void addTab(in String title = gs!"", Texture icon = Texture.init) 185 { 186 checkClassBinding!(typeof(this))(); 187 ptrcall!(void)(GDNativeClassBinding.addTab, _godot_object, title, icon); 188 } 189 /** 190 Moves the scroll view to make the tab visible. 191 */ 192 void ensureTabVisible(in long idx) 193 { 194 checkClassBinding!(typeof(this))(); 195 ptrcall!(void)(GDNativeClassBinding.ensureTabVisible, _godot_object, idx); 196 } 197 /** 198 199 */ 200 long getCurrentTab() const 201 { 202 checkClassBinding!(typeof(this))(); 203 return ptrcall!(long)(GDNativeClassBinding.getCurrentTab, _godot_object); 204 } 205 /** 206 207 */ 208 bool getDragToRearrangeEnabled() const 209 { 210 checkClassBinding!(typeof(this))(); 211 return ptrcall!(bool)(GDNativeClassBinding.getDragToRearrangeEnabled, _godot_object); 212 } 213 /** 214 Returns `true` if the offset buttons (the ones that appear when there's not enough space for all tabs) are visible. 215 */ 216 bool getOffsetButtonsVisible() const 217 { 218 checkClassBinding!(typeof(this))(); 219 return ptrcall!(bool)(GDNativeClassBinding.getOffsetButtonsVisible, _godot_object); 220 } 221 /** 222 Returns the previously active tab index. 223 */ 224 long getPreviousTab() const 225 { 226 checkClassBinding!(typeof(this))(); 227 return ptrcall!(long)(GDNativeClassBinding.getPreviousTab, _godot_object); 228 } 229 /** 230 231 */ 232 bool getScrollingEnabled() const 233 { 234 checkClassBinding!(typeof(this))(); 235 return ptrcall!(bool)(GDNativeClassBinding.getScrollingEnabled, _godot_object); 236 } 237 /** 238 Returns `true` if select with right mouse button is enabled. 239 */ 240 bool getSelectWithRmb() const 241 { 242 checkClassBinding!(typeof(this))(); 243 return ptrcall!(bool)(GDNativeClassBinding.getSelectWithRmb, _godot_object); 244 } 245 /** 246 247 */ 248 Tabs.TabAlign getTabAlign() const 249 { 250 checkClassBinding!(typeof(this))(); 251 return ptrcall!(Tabs.TabAlign)(GDNativeClassBinding.getTabAlign, _godot_object); 252 } 253 /** 254 255 */ 256 Tabs.CloseButtonDisplayPolicy getTabCloseDisplayPolicy() const 257 { 258 checkClassBinding!(typeof(this))(); 259 return ptrcall!(Tabs.CloseButtonDisplayPolicy)(GDNativeClassBinding.getTabCloseDisplayPolicy, _godot_object); 260 } 261 /** 262 Returns the number of tabs. 263 */ 264 long getTabCount() const 265 { 266 checkClassBinding!(typeof(this))(); 267 return ptrcall!(long)(GDNativeClassBinding.getTabCount, _godot_object); 268 } 269 /** 270 Returns `true` if the tab at index `tab_idx` is disabled. 271 */ 272 bool getTabDisabled(in long tab_idx) const 273 { 274 checkClassBinding!(typeof(this))(); 275 return ptrcall!(bool)(GDNativeClassBinding.getTabDisabled, _godot_object, tab_idx); 276 } 277 /** 278 Returns the $(D Texture) for the tab at index `tab_idx` or `null` if the tab has no $(D Texture). 279 */ 280 Ref!Texture getTabIcon(in long tab_idx) const 281 { 282 checkClassBinding!(typeof(this))(); 283 return ptrcall!(Texture)(GDNativeClassBinding.getTabIcon, _godot_object, tab_idx); 284 } 285 /** 286 Returns the number of hidden tabs offsetted to the left. 287 */ 288 long getTabOffset() const 289 { 290 checkClassBinding!(typeof(this))(); 291 return ptrcall!(long)(GDNativeClassBinding.getTabOffset, _godot_object); 292 } 293 /** 294 Returns tab $(D Rect2) with local position and size. 295 */ 296 Rect2 getTabRect(in long tab_idx) const 297 { 298 checkClassBinding!(typeof(this))(); 299 return ptrcall!(Rect2)(GDNativeClassBinding.getTabRect, _godot_object, tab_idx); 300 } 301 /** 302 Returns the title of the tab at index `tab_idx`. Tab titles default to the name of the indexed child node, but this can be overridden with $(D setTabTitle). 303 */ 304 String getTabTitle(in long tab_idx) const 305 { 306 checkClassBinding!(typeof(this))(); 307 return ptrcall!(String)(GDNativeClassBinding.getTabTitle, _godot_object, tab_idx); 308 } 309 /** 310 Returns the $(D Tabs)' rearrange group ID. 311 */ 312 long getTabsRearrangeGroup() const 313 { 314 checkClassBinding!(typeof(this))(); 315 return ptrcall!(long)(GDNativeClassBinding.getTabsRearrangeGroup, _godot_object); 316 } 317 /** 318 Moves a tab from `from` to `to`. 319 */ 320 void moveTab(in long from, in long to) 321 { 322 checkClassBinding!(typeof(this))(); 323 ptrcall!(void)(GDNativeClassBinding.moveTab, _godot_object, from, to); 324 } 325 /** 326 Removes the tab at index `tab_idx`. 327 */ 328 void removeTab(in long tab_idx) 329 { 330 checkClassBinding!(typeof(this))(); 331 ptrcall!(void)(GDNativeClassBinding.removeTab, _godot_object, tab_idx); 332 } 333 /** 334 335 */ 336 void setCurrentTab(in long tab_idx) 337 { 338 checkClassBinding!(typeof(this))(); 339 ptrcall!(void)(GDNativeClassBinding.setCurrentTab, _godot_object, tab_idx); 340 } 341 /** 342 343 */ 344 void setDragToRearrangeEnabled(in bool enabled) 345 { 346 checkClassBinding!(typeof(this))(); 347 ptrcall!(void)(GDNativeClassBinding.setDragToRearrangeEnabled, _godot_object, enabled); 348 } 349 /** 350 351 */ 352 void setScrollingEnabled(in bool enabled) 353 { 354 checkClassBinding!(typeof(this))(); 355 ptrcall!(void)(GDNativeClassBinding.setScrollingEnabled, _godot_object, enabled); 356 } 357 /** 358 If `true`, enables selecting a tab with the right mouse button. 359 */ 360 void setSelectWithRmb(in bool enabled) 361 { 362 checkClassBinding!(typeof(this))(); 363 ptrcall!(void)(GDNativeClassBinding.setSelectWithRmb, _godot_object, enabled); 364 } 365 /** 366 367 */ 368 void setTabAlign(in long _align) 369 { 370 checkClassBinding!(typeof(this))(); 371 ptrcall!(void)(GDNativeClassBinding.setTabAlign, _godot_object, _align); 372 } 373 /** 374 375 */ 376 void setTabCloseDisplayPolicy(in long policy) 377 { 378 checkClassBinding!(typeof(this))(); 379 ptrcall!(void)(GDNativeClassBinding.setTabCloseDisplayPolicy, _godot_object, policy); 380 } 381 /** 382 If `disabled` is `false`, hides the tab at index `tab_idx`. 383 $(B Note:) Its title text will remain unless it is also removed with $(D setTabTitle). 384 */ 385 void setTabDisabled(in long tab_idx, in bool disabled) 386 { 387 checkClassBinding!(typeof(this))(); 388 ptrcall!(void)(GDNativeClassBinding.setTabDisabled, _godot_object, tab_idx, disabled); 389 } 390 /** 391 Sets an `icon` for the tab at index `tab_idx`. 392 */ 393 void setTabIcon(in long tab_idx, Texture icon) 394 { 395 checkClassBinding!(typeof(this))(); 396 ptrcall!(void)(GDNativeClassBinding.setTabIcon, _godot_object, tab_idx, icon); 397 } 398 /** 399 Sets a `title` for the tab at index `tab_idx`. 400 */ 401 void setTabTitle(in long tab_idx, in String title) 402 { 403 checkClassBinding!(typeof(this))(); 404 ptrcall!(void)(GDNativeClassBinding.setTabTitle, _godot_object, tab_idx, title); 405 } 406 /** 407 Defines the rearrange group ID. Choose for each $(D Tabs) the same value to dragging tabs between $(D Tabs). Enable drag with `set_drag_to_rearrange_enabled(true)`. 408 */ 409 void setTabsRearrangeGroup(in long group_id) 410 { 411 checkClassBinding!(typeof(this))(); 412 ptrcall!(void)(GDNativeClassBinding.setTabsRearrangeGroup, _godot_object, group_id); 413 } 414 /** 415 Select tab at index `tab_idx`. 416 */ 417 @property long currentTab() 418 { 419 return getCurrentTab(); 420 } 421 /// ditto 422 @property void currentTab(long v) 423 { 424 setCurrentTab(v); 425 } 426 /** 427 If `true`, tabs can be rearranged with mouse drag. 428 */ 429 @property bool dragToRearrangeEnabled() 430 { 431 return getDragToRearrangeEnabled(); 432 } 433 /// ditto 434 @property void dragToRearrangeEnabled(bool v) 435 { 436 setDragToRearrangeEnabled(v); 437 } 438 /** 439 if `true`, the mouse's scroll wheel can be used to navigate the scroll view. 440 */ 441 @property bool scrollingEnabled() 442 { 443 return getScrollingEnabled(); 444 } 445 /// ditto 446 @property void scrollingEnabled(bool v) 447 { 448 setScrollingEnabled(v); 449 } 450 /** 451 The alignment of all tabs. See $(D tabalign) for details. 452 */ 453 @property Tabs.TabAlign tabAlign() 454 { 455 return getTabAlign(); 456 } 457 /// ditto 458 @property void tabAlign(long v) 459 { 460 setTabAlign(v); 461 } 462 /** 463 Sets when the close button will appear on the tabs. See $(D closebuttondisplaypolicy) for details. 464 */ 465 @property Tabs.CloseButtonDisplayPolicy tabCloseDisplayPolicy() 466 { 467 return getTabCloseDisplayPolicy(); 468 } 469 /// ditto 470 @property void tabCloseDisplayPolicy(long v) 471 { 472 setTabCloseDisplayPolicy(v); 473 } 474 }