1 /** 2 Button control that provides selectable options when pressed. 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.optionbutton; 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.button; 25 import godot.basebutton; 26 import godot.control; 27 import godot.canvasitem; 28 import godot.node; 29 import godot.texture; 30 import godot.popupmenu; 31 /** 32 Button control that provides selectable options when pressed. 33 34 OptionButton is a type button that provides a selectable list of items when pressed. The item selected becomes the "current" item and is displayed as the button text. 35 See also $(D BaseButton) which contains common properties and methods associated with this node. 36 */ 37 @GodotBaseClass struct OptionButton 38 { 39 package(godot) enum string _GODOT_internal_name = "OptionButton"; 40 public: 41 @nogc nothrow: 42 union { /** */ godot_object _godot_object; /** */ Button _GODOT_base; } 43 alias _GODOT_base this; 44 alias BaseClasses = AliasSeq!(typeof(_GODOT_base), typeof(_GODOT_base).BaseClasses); 45 package(godot) __gshared bool _classBindingInitialized = false; 46 package(godot) static struct GDNativeClassBinding 47 { 48 __gshared: 49 @GodotName("_focused") GodotMethod!(void, long) _focused; 50 @GodotName("_get_items") GodotMethod!(Array) _getItems; 51 @GodotName("_select_int") GodotMethod!(void, long) _selectInt; 52 @GodotName("_selected") GodotMethod!(void, long) _selected; 53 @GodotName("_set_items") GodotMethod!(void, Array) _setItems; 54 @GodotName("add_icon_item") GodotMethod!(void, Texture, String, long) addIconItem; 55 @GodotName("add_item") GodotMethod!(void, String, long) addItem; 56 @GodotName("add_separator") GodotMethod!(void) addSeparator; 57 @GodotName("clear") GodotMethod!(void) clear; 58 @GodotName("get_item_count") GodotMethod!(long) getItemCount; 59 @GodotName("get_item_icon") GodotMethod!(Texture, long) getItemIcon; 60 @GodotName("get_item_id") GodotMethod!(long, long) getItemId; 61 @GodotName("get_item_index") GodotMethod!(long, long) getItemIndex; 62 @GodotName("get_item_metadata") GodotMethod!(Variant, long) getItemMetadata; 63 @GodotName("get_item_text") GodotMethod!(String, long) getItemText; 64 @GodotName("get_popup") GodotMethod!(PopupMenu) getPopup; 65 @GodotName("get_selected") GodotMethod!(long) getSelected; 66 @GodotName("get_selected_id") GodotMethod!(long) getSelectedId; 67 @GodotName("get_selected_metadata") GodotMethod!(Variant) getSelectedMetadata; 68 @GodotName("is_item_disabled") GodotMethod!(bool, long) isItemDisabled; 69 @GodotName("remove_item") GodotMethod!(void, long) removeItem; 70 @GodotName("select") GodotMethod!(void, long) select; 71 @GodotName("set_item_disabled") GodotMethod!(void, long, bool) setItemDisabled; 72 @GodotName("set_item_icon") GodotMethod!(void, long, Texture) setItemIcon; 73 @GodotName("set_item_id") GodotMethod!(void, long, long) setItemId; 74 @GodotName("set_item_metadata") GodotMethod!(void, long, Variant) setItemMetadata; 75 @GodotName("set_item_text") GodotMethod!(void, long, String) setItemText; 76 } 77 /// 78 pragma(inline, true) bool opEquals(in OptionButton other) const 79 { return _godot_object.ptr is other._godot_object.ptr; } 80 /// 81 pragma(inline, true) typeof(null) opAssign(typeof(null) n) 82 { _godot_object.ptr = n; return null; } 83 /// 84 pragma(inline, true) bool opEquals(typeof(null) n) const 85 { return _godot_object.ptr is n; } 86 /// 87 size_t toHash() const @trusted { return cast(size_t)_godot_object.ptr; } 88 mixin baseCasts; 89 /// Construct a new instance of OptionButton. 90 /// Note: use `memnew!OptionButton` instead. 91 static OptionButton _new() 92 { 93 static godot_class_constructor constructor; 94 if(constructor is null) constructor = _godot_api.godot_get_class_constructor("OptionButton"); 95 if(constructor is null) return typeof(this).init; 96 return cast(OptionButton)(constructor()); 97 } 98 @disable new(size_t s); 99 /** 100 101 */ 102 void _focused(in long arg0) 103 { 104 Array _GODOT_args = Array.make(); 105 _GODOT_args.append(arg0); 106 String _GODOT_method_name = String("_focused"); 107 this.callv(_GODOT_method_name, _GODOT_args); 108 } 109 /** 110 111 */ 112 Array _getItems() const 113 { 114 Array _GODOT_args = Array.make(); 115 String _GODOT_method_name = String("_get_items"); 116 return this.callv(_GODOT_method_name, _GODOT_args).as!(RefOrT!Array); 117 } 118 /** 119 120 */ 121 void _selectInt(in long arg0) 122 { 123 Array _GODOT_args = Array.make(); 124 _GODOT_args.append(arg0); 125 String _GODOT_method_name = String("_select_int"); 126 this.callv(_GODOT_method_name, _GODOT_args); 127 } 128 /** 129 130 */ 131 void _selected(in long arg0) 132 { 133 Array _GODOT_args = Array.make(); 134 _GODOT_args.append(arg0); 135 String _GODOT_method_name = String("_selected"); 136 this.callv(_GODOT_method_name, _GODOT_args); 137 } 138 /** 139 140 */ 141 void _setItems(in Array arg0) 142 { 143 Array _GODOT_args = Array.make(); 144 _GODOT_args.append(arg0); 145 String _GODOT_method_name = String("_set_items"); 146 this.callv(_GODOT_method_name, _GODOT_args); 147 } 148 /** 149 Adds an item, with a `texture` icon, text `label` and (optionally) `id`. If no `id` is passed, the item index will be used as the item's ID. New items are appended at the end. 150 */ 151 void addIconItem(Texture texture, in String label, in long id = -1) 152 { 153 checkClassBinding!(typeof(this))(); 154 ptrcall!(void)(GDNativeClassBinding.addIconItem, _godot_object, texture, label, id); 155 } 156 /** 157 Adds an item, with text `label` and (optionally) `id`. If no `id` is passed, the item index will be used as the item's ID. New items are appended at the end. 158 */ 159 void addItem(in String label, in long id = -1) 160 { 161 checkClassBinding!(typeof(this))(); 162 ptrcall!(void)(GDNativeClassBinding.addItem, _godot_object, label, id); 163 } 164 /** 165 Adds a separator to the list of items. Separators help to group items. Separator also takes up an index and is appended at the end. 166 */ 167 void addSeparator() 168 { 169 checkClassBinding!(typeof(this))(); 170 ptrcall!(void)(GDNativeClassBinding.addSeparator, _godot_object); 171 } 172 /** 173 Clears all the items in the $(D OptionButton). 174 */ 175 void clear() 176 { 177 checkClassBinding!(typeof(this))(); 178 ptrcall!(void)(GDNativeClassBinding.clear, _godot_object); 179 } 180 /** 181 Returns the amount of items in the OptionButton, including separators. 182 */ 183 long getItemCount() const 184 { 185 checkClassBinding!(typeof(this))(); 186 return ptrcall!(long)(GDNativeClassBinding.getItemCount, _godot_object); 187 } 188 /** 189 Returns the icon of the item at index `idx`. 190 */ 191 Ref!Texture getItemIcon(in long idx) const 192 { 193 checkClassBinding!(typeof(this))(); 194 return ptrcall!(Texture)(GDNativeClassBinding.getItemIcon, _godot_object, idx); 195 } 196 /** 197 Returns the ID of the item at index `idx`. 198 */ 199 long getItemId(in long idx) const 200 { 201 checkClassBinding!(typeof(this))(); 202 return ptrcall!(long)(GDNativeClassBinding.getItemId, _godot_object, idx); 203 } 204 /** 205 Returns the index of the item with the given `id`. 206 */ 207 long getItemIndex(in long id) const 208 { 209 checkClassBinding!(typeof(this))(); 210 return ptrcall!(long)(GDNativeClassBinding.getItemIndex, _godot_object, id); 211 } 212 /** 213 Retrieves the metadata of an item. Metadata may be any type and can be used to store extra information about an item, such as an external string ID. 214 */ 215 Variant getItemMetadata(in long idx) const 216 { 217 checkClassBinding!(typeof(this))(); 218 return ptrcall!(Variant)(GDNativeClassBinding.getItemMetadata, _godot_object, idx); 219 } 220 /** 221 Returns the text of the item at index `idx`. 222 */ 223 String getItemText(in long idx) const 224 { 225 checkClassBinding!(typeof(this))(); 226 return ptrcall!(String)(GDNativeClassBinding.getItemText, _godot_object, idx); 227 } 228 /** 229 Returns the $(D PopupMenu) contained in this button. 230 */ 231 PopupMenu getPopup() const 232 { 233 checkClassBinding!(typeof(this))(); 234 return ptrcall!(PopupMenu)(GDNativeClassBinding.getPopup, _godot_object); 235 } 236 /** 237 238 */ 239 long getSelected() const 240 { 241 checkClassBinding!(typeof(this))(); 242 return ptrcall!(long)(GDNativeClassBinding.getSelected, _godot_object); 243 } 244 /** 245 Returns the ID of the selected item, or `0` if no item is selected. 246 */ 247 long getSelectedId() const 248 { 249 checkClassBinding!(typeof(this))(); 250 return ptrcall!(long)(GDNativeClassBinding.getSelectedId, _godot_object); 251 } 252 /** 253 Gets the metadata of the selected item. Metadata for items can be set using $(D setItemMetadata). 254 */ 255 Variant getSelectedMetadata() const 256 { 257 checkClassBinding!(typeof(this))(); 258 return ptrcall!(Variant)(GDNativeClassBinding.getSelectedMetadata, _godot_object); 259 } 260 /** 261 Returns `true` if the item at index `idx` is disabled. 262 */ 263 bool isItemDisabled(in long idx) const 264 { 265 checkClassBinding!(typeof(this))(); 266 return ptrcall!(bool)(GDNativeClassBinding.isItemDisabled, _godot_object, idx); 267 } 268 /** 269 Removes the item at index `idx`. 270 */ 271 void removeItem(in long idx) 272 { 273 checkClassBinding!(typeof(this))(); 274 ptrcall!(void)(GDNativeClassBinding.removeItem, _godot_object, idx); 275 } 276 /** 277 Selects an item by index and makes it the current item. This will work even if the item is disabled. 278 */ 279 void select(in long idx) 280 { 281 checkClassBinding!(typeof(this))(); 282 ptrcall!(void)(GDNativeClassBinding.select, _godot_object, idx); 283 } 284 /** 285 Sets whether the item at index `idx` is disabled. 286 Disabled items are drawn differently in the dropdown and are not selectable by the user. If the current selected item is set as disabled, it will remain selected. 287 */ 288 void setItemDisabled(in long idx, in bool disabled) 289 { 290 checkClassBinding!(typeof(this))(); 291 ptrcall!(void)(GDNativeClassBinding.setItemDisabled, _godot_object, idx, disabled); 292 } 293 /** 294 Sets the icon of the item at index `idx`. 295 */ 296 void setItemIcon(in long idx, Texture texture) 297 { 298 checkClassBinding!(typeof(this))(); 299 ptrcall!(void)(GDNativeClassBinding.setItemIcon, _godot_object, idx, texture); 300 } 301 /** 302 Sets the ID of the item at index `idx`. 303 */ 304 void setItemId(in long idx, in long id) 305 { 306 checkClassBinding!(typeof(this))(); 307 ptrcall!(void)(GDNativeClassBinding.setItemId, _godot_object, idx, id); 308 } 309 /** 310 Sets the metadata of an item. Metadata may be of any type and can be used to store extra information about an item, such as an external string ID. 311 */ 312 void setItemMetadata(VariantArg1)(in long idx, in VariantArg1 metadata) 313 { 314 checkClassBinding!(typeof(this))(); 315 ptrcall!(void)(GDNativeClassBinding.setItemMetadata, _godot_object, idx, metadata); 316 } 317 /** 318 Sets the text of the item at index `idx`. 319 */ 320 void setItemText(in long idx, in String text) 321 { 322 checkClassBinding!(typeof(this))(); 323 ptrcall!(void)(GDNativeClassBinding.setItemText, _godot_object, idx, text); 324 } 325 /** 326 327 */ 328 @property Array items() 329 { 330 return _getItems(); 331 } 332 /// ditto 333 @property void items(Array v) 334 { 335 _setItems(v); 336 } 337 /** 338 The index of the currently selected item, or `-1` if no item is selected. 339 */ 340 @property long selected() 341 { 342 return getSelected(); 343 } 344 /// ditto 345 @property void selected(long v) 346 { 347 _selectInt(v); 348 } 349 }