1 /*
2  * This file is part of gtkD.
3  *
4  * gtkD is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU Lesser General Public License
6  * as published by the Free Software Foundation; either version 3
7  * of the License, or (at your option) any later version, with
8  * some exceptions, please read the COPYING file.
9  *
10  * gtkD is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public License
16  * along with gtkD; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA
18  */
19 
20 // generated automatically - do not change
21 // find conversion definition on APILookup.txt
22 // implement new conversion functionalities on the wrap.utils pakage
23 
24 
25 module gtk.Constraint;
26 
27 private import glib.ConstructionException;
28 private import gobject.ObjectG;
29 private import gtk.ConstraintTargetIF;
30 private import gtk.c.functions;
31 public  import gtk.c.types;
32 
33 
34 /**
35  * `GtkConstraint` describes a constraint between attributes of two widgets,
36  * expressed as a linear equation.
37  * 
38  * The typical equation for a constraint is:
39  * 
40  * ```
41  * target.target_attr = source.source_attr × multiplier + constant
42  * ```
43  * 
44  * Each `GtkConstraint` is part of a system that will be solved by a
45  * [class@Gtk.ConstraintLayout] in order to allocate and position each
46  * child widget or guide.
47  * 
48  * The source and target, as well as their attributes, of a `GtkConstraint`
49  * instance are immutable after creation.
50  */
51 public class Constraint : ObjectG
52 {
53 	/** the main Gtk struct */
54 	protected GtkConstraint* gtkConstraint;
55 
56 	/** Get the main Gtk struct */
57 	public GtkConstraint* getConstraintStruct(bool transferOwnership = false)
58 	{
59 		if (transferOwnership)
60 			ownedRef = false;
61 		return gtkConstraint;
62 	}
63 
64 	/** the main Gtk struct as a void* */
65 	protected override void* getStruct()
66 	{
67 		return cast(void*)gtkConstraint;
68 	}
69 
70 	/**
71 	 * Sets our main struct and passes it to the parent class.
72 	 */
73 	public this (GtkConstraint* gtkConstraint, bool ownedRef = false)
74 	{
75 		this.gtkConstraint = gtkConstraint;
76 		super(cast(GObject*)gtkConstraint, ownedRef);
77 	}
78 
79 
80 	/** */
81 	public static GType getType()
82 	{
83 		return gtk_constraint_get_type();
84 	}
85 
86 	/**
87 	 * Creates a new constraint representing a relation between a layout
88 	 * attribute on a source and a layout attribute on a target.
89 	 *
90 	 * Params:
91 	 *     target = the target of the constraint
92 	 *     targetAttribute = the attribute of `target` to be set
93 	 *     relation = the relation equivalence between `target_attribute` and `source_attribute`
94 	 *     source = the source of the constraint
95 	 *     sourceAttribute = the attribute of `source` to be read
96 	 *     multiplier = a multiplication factor to be applied to `source_attribute`
97 	 *     constant = a constant factor to be added to `source_attribute`
98 	 *     strength = the strength of the constraint
99 	 *
100 	 * Returns: the newly created constraint
101 	 *
102 	 * Throws: ConstructionException GTK+ fails to create the object.
103 	 */
104 	public this(ConstraintTargetIF target, GtkConstraintAttribute targetAttribute, GtkConstraintRelation relation, ConstraintTargetIF source, GtkConstraintAttribute sourceAttribute, double multiplier, double constant, int strength)
105 	{
106 		auto __p = gtk_constraint_new((target is null) ? null : target.getConstraintTargetStruct(), targetAttribute, relation, (source is null) ? null : source.getConstraintTargetStruct(), sourceAttribute, multiplier, constant, strength);
107 
108 		if(__p is null)
109 		{
110 			throw new ConstructionException("null returned by new");
111 		}
112 
113 		this(cast(GtkConstraint*) __p, true);
114 	}
115 
116 	/**
117 	 * Creates a new constraint representing a relation between a layout
118 	 * attribute on a target and a constant value.
119 	 *
120 	 * Params:
121 	 *     target = a the target of the constraint
122 	 *     targetAttribute = the attribute of `target` to be set
123 	 *     relation = the relation equivalence between `target_attribute` and `constant`
124 	 *     constant = a constant factor to be set on `target_attribute`
125 	 *     strength = the strength of the constraint
126 	 *
127 	 * Returns: the newly created constraint
128 	 *
129 	 * Throws: ConstructionException GTK+ fails to create the object.
130 	 */
131 	public this(ConstraintTargetIF target, GtkConstraintAttribute targetAttribute, GtkConstraintRelation relation, double constant, int strength)
132 	{
133 		auto __p = gtk_constraint_new_constant((target is null) ? null : target.getConstraintTargetStruct(), targetAttribute, relation, constant, strength);
134 
135 		if(__p is null)
136 		{
137 			throw new ConstructionException("null returned by new_constant");
138 		}
139 
140 		this(cast(GtkConstraint*) __p, true);
141 	}
142 
143 	/**
144 	 * Retrieves the constant factor added to the source attributes' value.
145 	 *
146 	 * Returns: a constant factor
147 	 */
148 	public double getConstant()
149 	{
150 		return gtk_constraint_get_constant(gtkConstraint);
151 	}
152 
153 	/**
154 	 * Retrieves the multiplication factor applied to the source
155 	 * attribute's value.
156 	 *
157 	 * Returns: a multiplication factor
158 	 */
159 	public double getMultiplier()
160 	{
161 		return gtk_constraint_get_multiplier(gtkConstraint);
162 	}
163 
164 	/**
165 	 * The order relation between the terms of the constraint.
166 	 *
167 	 * Returns: a relation type
168 	 */
169 	public GtkConstraintRelation getRelation()
170 	{
171 		return gtk_constraint_get_relation(gtkConstraint);
172 	}
173 
174 	/**
175 	 * Retrieves the [iface@Gtk.ConstraintTarget] used as the source for the
176 	 * constraint.
177 	 *
178 	 * If the source is set to `NULL` at creation, the constraint will use
179 	 * the widget using the [class@Gtk.ConstraintLayout] as the source.
180 	 *
181 	 * Returns: the source of the constraint
182 	 */
183 	public ConstraintTargetIF getSource()
184 	{
185 		auto __p = gtk_constraint_get_source(gtkConstraint);
186 
187 		if(__p is null)
188 		{
189 			return null;
190 		}
191 
192 		return ObjectG.getDObject!(ConstraintTargetIF)(cast(GtkConstraintTarget*) __p);
193 	}
194 
195 	/**
196 	 * Retrieves the attribute of the source to be read by the constraint.
197 	 *
198 	 * Returns: the source's attribute
199 	 */
200 	public GtkConstraintAttribute getSourceAttribute()
201 	{
202 		return gtk_constraint_get_source_attribute(gtkConstraint);
203 	}
204 
205 	/**
206 	 * Retrieves the strength of the constraint.
207 	 *
208 	 * Returns: the strength value
209 	 */
210 	public int getStrength()
211 	{
212 		return gtk_constraint_get_strength(gtkConstraint);
213 	}
214 
215 	/**
216 	 * Retrieves the [iface@Gtk.ConstraintTarget] used as the target for
217 	 * the constraint.
218 	 *
219 	 * If the targe is set to `NULL` at creation, the constraint will use
220 	 * the widget using the [class@Gtk.ConstraintLayout] as the target.
221 	 *
222 	 * Returns: a #GtkConstraintTarget
223 	 */
224 	public ConstraintTargetIF getTarget()
225 	{
226 		auto __p = gtk_constraint_get_target(gtkConstraint);
227 
228 		if(__p is null)
229 		{
230 			return null;
231 		}
232 
233 		return ObjectG.getDObject!(ConstraintTargetIF)(cast(GtkConstraintTarget*) __p);
234 	}
235 
236 	/**
237 	 * Retrieves the attribute of the target to be set by the constraint.
238 	 *
239 	 * Returns: the target's attribute
240 	 */
241 	public GtkConstraintAttribute getTargetAttribute()
242 	{
243 		return gtk_constraint_get_target_attribute(gtkConstraint);
244 	}
245 
246 	/**
247 	 * Checks whether the constraint is attached to a [class@Gtk.ConstraintLayout],
248 	 * and it is contributing to the layout.
249 	 *
250 	 * Returns: `TRUE` if the constraint is attached
251 	 */
252 	public bool isAttached()
253 	{
254 		return gtk_constraint_is_attached(gtkConstraint) != 0;
255 	}
256 
257 	/**
258 	 * Checks whether the constraint describes a relation between an attribute
259 	 * on the [property@Gtk.Constraint:target] and a constant value.
260 	 *
261 	 * Returns: `TRUE` if the constraint is a constant relation
262 	 */
263 	public bool isConstant()
264 	{
265 		return gtk_constraint_is_constant(gtkConstraint) != 0;
266 	}
267 
268 	/**
269 	 * Checks whether the constraint is a required relation for solving the
270 	 * constraint layout.
271 	 *
272 	 * Returns: %TRUE if the constraint is required
273 	 */
274 	public bool isRequired()
275 	{
276 		return gtk_constraint_is_required(gtkConstraint) != 0;
277 	}
278 }