1 /** 2 Container that preserves its child controls' aspect ratio. 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.aspectratiocontainer; 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.container; 25 /** 26 Container that preserves its child controls' aspect ratio. 27 28 Arranges child controls in a way to preserve their aspect ratio automatically whenever the container is resized. Solves the problem where the container size is dynamic and the contents' size needs to adjust accordingly without losing proportions. 29 */ 30 @GodotBaseClass struct AspectRatioContainer 31 { 32 package(godot) enum string _GODOT_internal_name = "AspectRatioContainer"; 33 public: 34 @nogc nothrow: 35 union { /** */ godot_object _godot_object; /** */ Container _GODOT_base; } 36 alias _GODOT_base this; 37 alias BaseClasses = AliasSeq!(typeof(_GODOT_base), typeof(_GODOT_base).BaseClasses); 38 package(godot) __gshared bool _classBindingInitialized = false; 39 package(godot) static struct GDNativeClassBinding 40 { 41 __gshared: 42 @GodotName("get_alignment_horizontal") GodotMethod!(AspectRatioContainer.AlignMode) getAlignmentHorizontal; 43 @GodotName("get_alignment_vertical") GodotMethod!(AspectRatioContainer.AlignMode) getAlignmentVertical; 44 @GodotName("get_ratio") GodotMethod!(double) getRatio; 45 @GodotName("get_stretch_mode") GodotMethod!(AspectRatioContainer.StretchMode) getStretchMode; 46 @GodotName("set_alignment_horizontal") GodotMethod!(void, long) setAlignmentHorizontal; 47 @GodotName("set_alignment_vertical") GodotMethod!(void, long) setAlignmentVertical; 48 @GodotName("set_ratio") GodotMethod!(void, double) setRatio; 49 @GodotName("set_stretch_mode") GodotMethod!(void, long) setStretchMode; 50 } 51 /// 52 pragma(inline, true) bool opEquals(in AspectRatioContainer other) const 53 { return _godot_object.ptr is other._godot_object.ptr; } 54 /// 55 pragma(inline, true) typeof(null) opAssign(typeof(null) n) 56 { _godot_object.ptr = n; return null; } 57 /// 58 pragma(inline, true) bool opEquals(typeof(null) n) const 59 { return _godot_object.ptr is n; } 60 /// 61 size_t toHash() const @trusted { return cast(size_t)_godot_object.ptr; } 62 mixin baseCasts; 63 /// Construct a new instance of AspectRatioContainer. 64 /// Note: use `memnew!AspectRatioContainer` instead. 65 static AspectRatioContainer _new() 66 { 67 static godot_class_constructor constructor; 68 if(constructor is null) constructor = _godot_api.godot_get_class_constructor("AspectRatioContainer"); 69 if(constructor is null) return typeof(this).init; 70 return cast(AspectRatioContainer)(constructor()); 71 } 72 @disable new(size_t s); 73 /// 74 enum AlignMode : int 75 { 76 /** 77 Aligns child controls with the beginning (left or top) of the container. 78 */ 79 alignBegin = 0, 80 /** 81 Aligns child controls with the center of the container. 82 */ 83 alignCenter = 1, 84 /** 85 Aligns child controls with the end (right or bottom) of the container. 86 */ 87 alignEnd = 2, 88 } 89 /// 90 enum StretchMode : int 91 { 92 /** 93 The height of child controls is automatically adjusted based on the width of the container. 94 */ 95 stretchWidthControlsHeight = 0, 96 /** 97 The width of child controls is automatically adjusted based on the height of the container. 98 */ 99 stretchHeightControlsWidth = 1, 100 /** 101 The bounding rectangle of child controls is automatically adjusted to fit inside the container while keeping the aspect ratio. 102 */ 103 stretchFit = 2, 104 /** 105 The width and height of child controls is automatically adjusted to make their bounding rectangle cover the entire area of the container while keeping the aspect ratio. 106 When the bounding rectangle of child controls exceed the container's size and $(D Control.rectClipContent) is enabled, this allows to show only the container's area restricted by its own bounding rectangle. 107 */ 108 stretchCover = 3, 109 } 110 /// 111 enum Constants : int 112 { 113 stretchWidthControlsHeight = 0, 114 alignBegin = 0, 115 stretchHeightControlsWidth = 1, 116 alignCenter = 1, 117 alignEnd = 2, 118 stretchFit = 2, 119 stretchCover = 3, 120 } 121 /** 122 123 */ 124 AspectRatioContainer.AlignMode getAlignmentHorizontal() const 125 { 126 checkClassBinding!(typeof(this))(); 127 return ptrcall!(AspectRatioContainer.AlignMode)(GDNativeClassBinding.getAlignmentHorizontal, _godot_object); 128 } 129 /** 130 131 */ 132 AspectRatioContainer.AlignMode getAlignmentVertical() const 133 { 134 checkClassBinding!(typeof(this))(); 135 return ptrcall!(AspectRatioContainer.AlignMode)(GDNativeClassBinding.getAlignmentVertical, _godot_object); 136 } 137 /** 138 139 */ 140 double getRatio() const 141 { 142 checkClassBinding!(typeof(this))(); 143 return ptrcall!(double)(GDNativeClassBinding.getRatio, _godot_object); 144 } 145 /** 146 147 */ 148 AspectRatioContainer.StretchMode getStretchMode() const 149 { 150 checkClassBinding!(typeof(this))(); 151 return ptrcall!(AspectRatioContainer.StretchMode)(GDNativeClassBinding.getStretchMode, _godot_object); 152 } 153 /** 154 155 */ 156 void setAlignmentHorizontal(in long alignment_horizontal) 157 { 158 checkClassBinding!(typeof(this))(); 159 ptrcall!(void)(GDNativeClassBinding.setAlignmentHorizontal, _godot_object, alignment_horizontal); 160 } 161 /** 162 163 */ 164 void setAlignmentVertical(in long alignment_vertical) 165 { 166 checkClassBinding!(typeof(this))(); 167 ptrcall!(void)(GDNativeClassBinding.setAlignmentVertical, _godot_object, alignment_vertical); 168 } 169 /** 170 171 */ 172 void setRatio(in double ratio) 173 { 174 checkClassBinding!(typeof(this))(); 175 ptrcall!(void)(GDNativeClassBinding.setRatio, _godot_object, ratio); 176 } 177 /** 178 179 */ 180 void setStretchMode(in long stretch_mode) 181 { 182 checkClassBinding!(typeof(this))(); 183 ptrcall!(void)(GDNativeClassBinding.setStretchMode, _godot_object, stretch_mode); 184 } 185 /** 186 Specifies the horizontal relative position of child controls. 187 */ 188 @property AspectRatioContainer.AlignMode alignmentHorizontal() 189 { 190 return getAlignmentHorizontal(); 191 } 192 /// ditto 193 @property void alignmentHorizontal(long v) 194 { 195 setAlignmentHorizontal(v); 196 } 197 /** 198 Specifies the vertical relative position of child controls. 199 */ 200 @property AspectRatioContainer.AlignMode alignmentVertical() 201 { 202 return getAlignmentVertical(); 203 } 204 /// ditto 205 @property void alignmentVertical(long v) 206 { 207 setAlignmentVertical(v); 208 } 209 /** 210 The aspect ratio to enforce on child controls. This is the width divided by the height. The ratio depends on the $(D stretchMode). 211 */ 212 @property double ratio() 213 { 214 return getRatio(); 215 } 216 /// ditto 217 @property void ratio(double v) 218 { 219 setRatio(v); 220 } 221 /** 222 The stretch mode used to align child controls. 223 */ 224 @property AspectRatioContainer.StretchMode stretchMode() 225 { 226 return getStretchMode(); 227 } 228 /// ditto 229 @property void stretchMode(long v) 230 { 231 setStretchMode(v); 232 } 233 }