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.meta;
17 import godot.core;
18 import godot.c;
19 import godot.d.bind;
20 import godot.d.reference;
21 import godot.object;
22 import godot.resource;
23 import godot.reference;
24 /**
25 Base class for drawing stylized boxes for the UI.
26 
27 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.
28 */
29 @GodotBaseClass struct StyleBox
30 {
31 	enum string _GODOT_internal_name = "StyleBox";
32 public:
33 @nogc nothrow:
34 	union { godot_object _godot_object; Resource _GODOT_base; }
35 	alias _GODOT_base this;
36 	alias BaseClasses = AliasSeq!(typeof(_GODOT_base), typeof(_GODOT_base).BaseClasses);
37 	package(godot) __gshared bool _classBindingInitialized = false;
38 	package(godot) static struct _classBinding
39 	{
40 		__gshared:
41 		@GodotName("test_mask") GodotMethod!(bool, Vector2, Rect2) testMask;
42 		@GodotName("set_default_margin") GodotMethod!(void, long, double) setDefaultMargin;
43 		@GodotName("get_default_margin") GodotMethod!(double, long) getDefaultMargin;
44 		@GodotName("get_margin") GodotMethod!(double, long) getMargin;
45 		@GodotName("get_minimum_size") GodotMethod!(Vector2) getMinimumSize;
46 		@GodotName("get_center_size") GodotMethod!(Vector2) getCenterSize;
47 		@GodotName("get_offset") GodotMethod!(Vector2) getOffset;
48 		@GodotName("draw") GodotMethod!(void, RID, Rect2) draw;
49 	}
50 	bool opEquals(in StyleBox other) const { return _godot_object.ptr is other._godot_object.ptr; }
51 	StyleBox opAssign(T : typeof(null))(T n) { _godot_object.ptr = null; }
52 	bool opEquals(typeof(null) n) const { return _godot_object.ptr is null; }
53 	mixin baseCasts;
54 	static StyleBox _new()
55 	{
56 		static godot_class_constructor constructor;
57 		if(constructor is null) constructor = _godot_api.godot_get_class_constructor("StyleBox");
58 		if(constructor is null) return typeof(this).init;
59 		return cast(StyleBox)(constructor());
60 	}
61 	@disable new(size_t s);
62 	/**
63 	Test a position in a rectangle, return whether it passes the mask test.
64 	*/
65 	bool testMask(in Vector2 point, in Rect2 rect) const
66 	{
67 		checkClassBinding!(typeof(this))();
68 		return ptrcall!(bool)(_classBinding.testMask, _godot_object, point, rect);
69 	}
70 	/**
71 	
72 	*/
73 	void setDefaultMargin(in long margin, in double offset)
74 	{
75 		checkClassBinding!(typeof(this))();
76 		ptrcall!(void)(_classBinding.setDefaultMargin, _godot_object, margin, offset);
77 	}
78 	/**
79 	
80 	*/
81 	double getDefaultMargin(in long margin) const
82 	{
83 		checkClassBinding!(typeof(this))();
84 		return ptrcall!(double)(_classBinding.getDefaultMargin, _godot_object, margin);
85 	}
86 	/**
87 	Return the offset of margin "margin" (see MARGIN_* enum).
88 	*/
89 	double getMargin(in long margin) const
90 	{
91 		checkClassBinding!(typeof(this))();
92 		return ptrcall!(double)(_classBinding.getMargin, _godot_object, margin);
93 	}
94 	/**
95 	Return the minimum size that this stylebox can be shrunk to.
96 	*/
97 	Vector2 getMinimumSize() const
98 	{
99 		checkClassBinding!(typeof(this))();
100 		return ptrcall!(Vector2)(_classBinding.getMinimumSize, _godot_object);
101 	}
102 	/**
103 	
104 	*/
105 	Vector2 getCenterSize() const
106 	{
107 		checkClassBinding!(typeof(this))();
108 		return ptrcall!(Vector2)(_classBinding.getCenterSize, _godot_object);
109 	}
110 	/**
111 	Return the "offset" of a stylebox, this is a helper function, like writing `Vector2(style.get_margin(MARGIN_LEFT), style.get_margin(MARGIN_TOP))`.
112 	*/
113 	Vector2 getOffset() const
114 	{
115 		checkClassBinding!(typeof(this))();
116 		return ptrcall!(Vector2)(_classBinding.getOffset, _godot_object);
117 	}
118 	/**
119 	
120 	*/
121 	void draw(in RID canvas_item, in Rect2 rect) const
122 	{
123 		checkClassBinding!(typeof(this))();
124 		ptrcall!(void)(_classBinding.draw, _godot_object, canvas_item, rect);
125 	}
126 	/**
127 	
128 	*/
129 	@property double contentMarginLeft()
130 	{
131 		return getDefaultMargin(0);
132 	}
133 	/// ditto
134 	@property void contentMarginLeft(double v)
135 	{
136 		setDefaultMargin(0, v);
137 	}
138 	/**
139 	
140 	*/
141 	@property double contentMarginRight()
142 	{
143 		return getDefaultMargin(2);
144 	}
145 	/// ditto
146 	@property void contentMarginRight(double v)
147 	{
148 		setDefaultMargin(2, v);
149 	}
150 	/**
151 	
152 	*/
153 	@property double contentMarginTop()
154 	{
155 		return getDefaultMargin(1);
156 	}
157 	/// ditto
158 	@property void contentMarginTop(double v)
159 	{
160 		setDefaultMargin(1, v);
161 	}
162 	/**
163 	
164 	*/
165 	@property double contentMarginBottom()
166 	{
167 		return getDefaultMargin(3);
168 	}
169 	/// ditto
170 	@property void contentMarginBottom(double v)
171 	{
172 		setDefaultMargin(3, v);
173 	}
174 }