1 /** 2 Base class for drawing stylized boxes for the UI. 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.stylebox; 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.resource; 24 import godot.reference; 25 import godot.canvasitem; 26 /** 27 Base class for drawing stylized boxes for the UI. 28 29 StyleBox is $(D Resource) that provides an abstract base class for drawing stylized boxes for the UI. StyleBoxes are used for drawing the styles of buttons, line edit backgrounds, tree backgrounds, etc. and also for testing a transparency mask for pointer signals. If mask test fails on a StyleBox assigned as mask to a control, clicks and motion signals will go through it to the one below. 30 $(B Note:) For children of $(D Control) that have $(I Theme Properties), the `focus` $(D StyleBox) is displayed over the `normal`, `hover` or `pressed` $(D StyleBox). This makes the `focus` $(D StyleBox) more reusable across different nodes. 31 */ 32 @GodotBaseClass struct StyleBox 33 { 34 package(godot) enum string _GODOT_internal_name = "StyleBox"; 35 public: 36 @nogc nothrow: 37 union { /** */ godot_object _godot_object; /** */ Resource _GODOT_base; } 38 alias _GODOT_base this; 39 alias BaseClasses = AliasSeq!(typeof(_GODOT_base), typeof(_GODOT_base).BaseClasses); 40 package(godot) __gshared bool _classBindingInitialized = false; 41 package(godot) static struct GDNativeClassBinding 42 { 43 __gshared: 44 @GodotName("draw") GodotMethod!(void, RID, Rect2) draw; 45 @GodotName("get_center_size") GodotMethod!(Vector2) getCenterSize; 46 @GodotName("get_current_item_drawn") GodotMethod!(CanvasItem) getCurrentItemDrawn; 47 @GodotName("get_default_margin") GodotMethod!(double, long) getDefaultMargin; 48 @GodotName("get_margin") GodotMethod!(double, long) getMargin; 49 @GodotName("get_minimum_size") GodotMethod!(Vector2) getMinimumSize; 50 @GodotName("get_offset") GodotMethod!(Vector2) getOffset; 51 @GodotName("set_default_margin") GodotMethod!(void, long, double) setDefaultMargin; 52 @GodotName("test_mask") GodotMethod!(bool, Vector2, Rect2) testMask; 53 } 54 /// 55 pragma(inline, true) bool opEquals(in StyleBox other) const 56 { return _godot_object.ptr is other._godot_object.ptr; } 57 /// 58 pragma(inline, true) typeof(null) opAssign(typeof(null) n) 59 { _godot_object.ptr = n; return null; } 60 /// 61 pragma(inline, true) bool opEquals(typeof(null) n) const 62 { return _godot_object.ptr is n; } 63 /// 64 size_t toHash() const @trusted { return cast(size_t)_godot_object.ptr; } 65 mixin baseCasts; 66 /// Construct a new instance of StyleBox. 67 /// Note: use `memnew!StyleBox` instead. 68 static StyleBox _new() 69 { 70 static godot_class_constructor constructor; 71 if(constructor is null) constructor = _godot_api.godot_get_class_constructor("StyleBox"); 72 if(constructor is null) return typeof(this).init; 73 return cast(StyleBox)(constructor()); 74 } 75 @disable new(size_t s); 76 /** 77 Draws this stylebox using a $(D CanvasItem) with given $(D RID). 78 You can get a $(D RID) value using $(D GodotObject.getInstanceId) on a $(D CanvasItem)-derived node. 79 */ 80 void draw(in RID canvas_item, in Rect2 rect) const 81 { 82 checkClassBinding!(typeof(this))(); 83 ptrcall!(void)(GDNativeClassBinding.draw, _godot_object, canvas_item, rect); 84 } 85 /** 86 Returns the size of this $(D StyleBox) without the margins. 87 */ 88 Vector2 getCenterSize() const 89 { 90 checkClassBinding!(typeof(this))(); 91 return ptrcall!(Vector2)(GDNativeClassBinding.getCenterSize, _godot_object); 92 } 93 /** 94 Returns the $(D CanvasItem) that handles its $(D constant CanvasItem.NOTIFICATION_DRAW) or $(D CanvasItem._draw) callback at this moment. 95 */ 96 CanvasItem getCurrentItemDrawn() const 97 { 98 checkClassBinding!(typeof(this))(); 99 return ptrcall!(CanvasItem)(GDNativeClassBinding.getCurrentItemDrawn, _godot_object); 100 } 101 /** 102 Returns the default value of the specified $(D margin). 103 */ 104 double getDefaultMargin(in long margin) const 105 { 106 checkClassBinding!(typeof(this))(); 107 return ptrcall!(double)(GDNativeClassBinding.getDefaultMargin, _godot_object, margin); 108 } 109 /** 110 Returns the content margin offset for the specified $(D margin). 111 Positive values reduce size inwards, unlike $(D Control)'s margin values. 112 */ 113 double getMargin(in long margin) const 114 { 115 checkClassBinding!(typeof(this))(); 116 return ptrcall!(double)(GDNativeClassBinding.getMargin, _godot_object, margin); 117 } 118 /** 119 Returns the minimum size that this stylebox can be shrunk to. 120 */ 121 Vector2 getMinimumSize() const 122 { 123 checkClassBinding!(typeof(this))(); 124 return ptrcall!(Vector2)(GDNativeClassBinding.getMinimumSize, _godot_object); 125 } 126 /** 127 Returns the "offset" of a stylebox. This helper function returns a value equivalent to `Vector2(style.get_margin(MARGIN_LEFT), style.get_margin(MARGIN_TOP))`. 128 */ 129 Vector2 getOffset() const 130 { 131 checkClassBinding!(typeof(this))(); 132 return ptrcall!(Vector2)(GDNativeClassBinding.getOffset, _godot_object); 133 } 134 /** 135 Sets the default value of the specified $(D margin) to given `offset` in pixels. 136 */ 137 void setDefaultMargin(in long margin, in double offset) 138 { 139 checkClassBinding!(typeof(this))(); 140 ptrcall!(void)(GDNativeClassBinding.setDefaultMargin, _godot_object, margin, offset); 141 } 142 /** 143 Test a position in a rectangle, return whether it passes the mask test. 144 */ 145 bool testMask(in Vector2 point, in Rect2 rect) const 146 { 147 checkClassBinding!(typeof(this))(); 148 return ptrcall!(bool)(GDNativeClassBinding.testMask, _godot_object, point, rect); 149 } 150 /** 151 The bottom margin for the contents of this style box. Increasing this value reduces the space available to the contents from the bottom. 152 If this value is negative, it is ignored and a child-specific margin is used instead. For example for $(D StyleBoxFlat) the border thickness (if any) is used instead. 153 It is up to the code using this style box to decide what these contents are: for example, a $(D Button) respects this content margin for the textual contents of the button. 154 $(D getMargin) should be used to fetch this value as consumer instead of reading these properties directly. This is because it correctly respects negative values and the fallback mentioned above. 155 */ 156 @property double contentMarginBottom() 157 { 158 return getDefaultMargin(3); 159 } 160 /// ditto 161 @property void contentMarginBottom(double v) 162 { 163 setDefaultMargin(3, v); 164 } 165 /** 166 The left margin for the contents of this style box. Increasing this value reduces the space available to the contents from the left. 167 Refer to $(D contentMarginBottom) for extra considerations. 168 */ 169 @property double contentMarginLeft() 170 { 171 return getDefaultMargin(0); 172 } 173 /// ditto 174 @property void contentMarginLeft(double v) 175 { 176 setDefaultMargin(0, v); 177 } 178 /** 179 The right margin for the contents of this style box. Increasing this value reduces the space available to the contents from the right. 180 Refer to $(D contentMarginBottom) for extra considerations. 181 */ 182 @property double contentMarginRight() 183 { 184 return getDefaultMargin(2); 185 } 186 /// ditto 187 @property void contentMarginRight(double v) 188 { 189 setDefaultMargin(2, v); 190 } 191 /** 192 The top margin for the contents of this style box. Increasing this value reduces the space available to the contents from the top. 193 Refer to $(D contentMarginBottom) for extra considerations. 194 */ 195 @property double contentMarginTop() 196 { 197 return getDefaultMargin(1); 198 } 199 /// ditto 200 @property void contentMarginTop(double v) 201 { 202 setDefaultMargin(1, v); 203 } 204 }