1 /*
2  * This file is part of d-handy.
3  *
4  * d-handy 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  * d-handy 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 d-handy; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA
18  */
19 module handy.SwipeableT;
20 
21 public  import gobject.ObjectG;
22 public  import gobject.Signals;
23 public  import handy.SwipeTracker;
24 public  import handy.c.functions;
25 public  import handy.c.types;
26 public  import std.algorithm;
27 
28 
29 /** */
30 public template SwipeableT(TStruct)
31 {
32 	/** Get the main Gtk struct */
33 	public HdySwipeable* getSwipeableStruct(bool transferOwnership = false)
34 	{
35 		if (transferOwnership)
36 			ownedRef = false;
37 		return cast(HdySwipeable*)getStruct();
38 	}
39 
40 
41 	/**
42 	 * Emits HdySwipeable::child-switched signal. This should be called when the
43 	 * widget switches visible child widget.
44 	 *
45 	 * @duration can be 0 if the child is switched without animation.
46 	 *
47 	 * Params:
48 	 *     index = the index of the child to switch to
49 	 *     duration = Animation duration in milliseconds
50 	 *
51 	 * Since: 1.0
52 	 */
53 	public void emitChildSwitched(uint index, long duration)
54 	{
55 		hdy_swipeable_emit_child_switched(getSwipeableStruct(), index, duration);
56 	}
57 
58 	/**
59 	 * Gets the progress @self will snap back to after the gesture is canceled.
60 	 *
61 	 * Returns: the cancel progress, unitless
62 	 *
63 	 * Since: 1.0
64 	 */
65 	public double getCancelProgress()
66 	{
67 		return hdy_swipeable_get_cancel_progress(getSwipeableStruct());
68 	}
69 
70 	/**
71 	 * Gets the swipe distance of @self. This corresponds to how many pixels
72 	 * 1 unit represents.
73 	 *
74 	 * Returns: the swipe distance in pixels
75 	 *
76 	 * Since: 1.0
77 	 */
78 	public double getDistance()
79 	{
80 		return hdy_swipeable_get_distance(getSwipeableStruct());
81 	}
82 
83 	/**
84 	 * Gets the current progress of @self
85 	 *
86 	 * Returns: the current progress, unitless
87 	 *
88 	 * Since: 1.0
89 	 */
90 	public double getProgress()
91 	{
92 		return hdy_swipeable_get_progress(getSwipeableStruct());
93 	}
94 
95 	/**
96 	 * Gets the snap points of @self. Each snap point represents a progress value
97 	 * that is considered acceptable to end the swipe on.
98 	 *
99 	 * Returns: the snap points of
100 	 *     @self. The array must be freed with g_free().
101 	 *
102 	 * Since: 1.0
103 	 */
104 	public double[] getSnapPoints()
105 	{
106 		int nSnapPoints;
107 
108 		auto __p = hdy_swipeable_get_snap_points(getSwipeableStruct(), &nSnapPoints);
109 
110 		return __p[0 .. nSnapPoints];
111 	}
112 
113 	/**
114 	 * Gets the area @self can start a swipe from for the given direction and
115 	 * gesture type.
116 	 * This can be used to restrict swipes to only be possible from a certain area,
117 	 * for example, to only allow edge swipes, or to have a draggable element and
118 	 * ignore swipes elsewhere.
119 	 *
120 	 * Swipe area is only considered for direct swipes (as in, not initiated by
121 	 * #HdySwipeGroup).
122 	 *
123 	 * If not implemented, the default implementation returns the allocation of
124 	 * @self, allowing swipes from anywhere.
125 	 *
126 	 * Params:
127 	 *     navigationDirection = the direction of the swipe
128 	 *     isDrag = whether the swipe is caused by a dragging gesture
129 	 *     rect = a pointer to a #GdkRectangle to store the swipe area
130 	 *
131 	 * Since: 1.0
132 	 */
133 	public void getSwipeArea(HdyNavigationDirection navigationDirection, bool isDrag, out GdkRectangle rect)
134 	{
135 		hdy_swipeable_get_swipe_area(getSwipeableStruct(), navigationDirection, isDrag, &rect);
136 	}
137 
138 	/**
139 	 * Gets the #HdySwipeTracker used by this swipeable widget.
140 	 *
141 	 * Returns: the swipe tracker
142 	 *
143 	 * Since: 1.0
144 	 */
145 	public SwipeTracker getSwipeTracker()
146 	{
147 		auto __p = hdy_swipeable_get_swipe_tracker(getSwipeableStruct());
148 
149 		if(__p is null)
150 		{
151 			return null;
152 		}
153 
154 		return ObjectG.getDObject!(SwipeTracker)(cast(HdySwipeTracker*) __p);
155 	}
156 
157 	/**
158 	 * See HdySwipeable::child-switched.
159 	 *
160 	 * Params:
161 	 *     index = the index of the child to switch to
162 	 *     duration = Animation duration in milliseconds
163 	 *
164 	 * Since: 1.0
165 	 */
166 	public void switchChild(uint index, long duration)
167 	{
168 		hdy_swipeable_switch_child(getSwipeableStruct(), index, duration);
169 	}
170 
171 	/**
172 	 * This signal should be emitted when the widget's visible child is changed.
173 	 *
174 	 * @duration can be 0 if the child is switched without animation.
175 	 *
176 	 * This is used by #HdySwipeGroup, applications should not connect to it.
177 	 *
178 	 * Params:
179 	 *     index = the index of the child to switch to
180 	 *     duration = Animation duration in milliseconds
181 	 *
182 	 * Since: 1.0
183 	 */
184 	gulong addOnChildSwitched(void delegate(uint, long, SwipeableIF) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
185 	{
186 		return Signals.connect(this, "child-switched", dlg, connectFlags ^ ConnectFlags.SWAPPED);
187 	}
188 }