@@ -95,8 +95,147 @@ namespace cycfi::elements
95
95
}
96
96
}
97
97
98
+ bool resizable_base::cursor (context const & ctx, point p, cursor_tracking /* status */ )
99
+ {
100
+ auto outer = ctx.bounds .inset (-5 );
101
+ auto inner = ctx.bounds .inset (5 );
102
+ if (ctx.enabled && is_enabled () && outer.includes (p) && !inner.includes (p))
103
+ {
104
+ auto const & b = ctx.bounds ;
105
+ bool h_resize = false ;
106
+ bool v_resize = false ;
107
+ if (p.x > b.left - 5 && p.x < b.left + 5 )
108
+ h_resize = true ;
109
+ else if (p.x > b.right - 5 && p.x < b.right + 5 )
110
+ h_resize = true ;
111
+
112
+ if (p.y > b.top - 5 && p.y < b.top + 5 )
113
+ v_resize = true ;
114
+ else if (p.y > b.bottom - 5 && p.y < b.bottom + 5 )
115
+ v_resize = true ;
116
+
117
+ if (h_resize != v_resize)
118
+ set_cursor (h_resize? cursor_type::h_resize : cursor_type::v_resize);
119
+ return true ;
120
+ }
121
+ return false ;
122
+ }
123
+
124
+ element* resizable_base::hit_test (context const & ctx, point p, bool leaf, bool control)
125
+ {
126
+ auto outer = ctx.bounds .inset (-5 );
127
+ auto inner = ctx.bounds .inset (5 );
128
+ if (ctx.enabled && is_enabled () && outer.includes (p) && !inner.includes (p))
129
+ return this ;
130
+ return proxy_base::hit_test (ctx, p, leaf, control);
131
+ }
132
+
133
+ bool resizable_base::click (context const & ctx, mouse_button btn)
134
+ {
135
+ if (proxy_base::click (ctx, btn))
136
+ return true ;
137
+
138
+ if (ctx.enabled && is_enabled ())
139
+ {
140
+ bool r = tracker::click (ctx, btn);
141
+ auto state = get_state ();
142
+ if (state)
143
+ {
144
+ auto outer = ctx.bounds .inset (-5 );
145
+ auto inner = ctx.bounds .inset (5 );
146
+ if (outer.includes (btn.pos ) && !inner.includes (btn.pos ))
147
+ {
148
+ auto const & b = ctx.bounds ;
149
+ if (btn.pos .x > b.left - 5 && btn.pos .x < b.left + 5 )
150
+ state->_handle = resizable_tracker_info::left;
151
+ else if (btn.pos .x > b.right - 5 && btn.pos .x < b.right + 5 )
152
+ state->_handle = resizable_tracker_info::right;
153
+
154
+ if (btn.pos .y > b.top - 5 && btn.pos .y < b.top + 5 )
155
+ state->_handle |= resizable_tracker_info::top;
156
+ else if (btn.pos .y > b.bottom - 5 && btn.pos .y < b.bottom + 5 )
157
+ state->_handle |= resizable_tracker_info::bottom;
158
+ }
159
+ }
160
+ return r;
161
+ }
162
+ return false ;
163
+ }
164
+
165
+ void resizable_base::drag (context const & ctx, mouse_button btn)
166
+ {
167
+ auto state = get_state ();
168
+ if (!state)
169
+ {
170
+ proxy_base::drag (ctx, btn);
171
+ }
172
+ else
173
+ {
174
+ tracker::drag (ctx, btn);
175
+ }
176
+ }
177
+
178
+ void resizable_base::keep_tracking (context const & ctx, tracker_info& track_info)
179
+ {
180
+ if (track_info.current != track_info.previous )
181
+ {
182
+ auto fl = find_parent<floating_element*>(ctx);
183
+ if (fl)
184
+ {
185
+ auto p = track_info.current ;
186
+ auto b = fl->bounds ();
187
+ if (auto state = get_state (); state && state->_handle )
188
+ {
189
+ if (state->_handle & resizable_tracker_info::left)
190
+ b.left = p.x ;
191
+ else if (state->_handle & resizable_tracker_info::right)
192
+ b.right = p.x ;
193
+
194
+ if (state->_handle & resizable_tracker_info::top)
195
+ b.top = p.y ;
196
+ else if (state->_handle & resizable_tracker_info::bottom)
197
+ b.bottom = p.y ;
198
+
199
+ auto width = b.width ();
200
+ auto height = b.height ();
201
+ auto ob = fl->bounds ();
202
+
203
+ auto limits = fl->subject ().limits (ctx);
204
+
205
+ // Constrain width
206
+ if (width < limits.min .x || width > limits.max .x )
207
+ {
208
+ if (state->_handle & resizable_tracker_info::left)
209
+ b.left = ob.left ;
210
+ else if (state->_handle & resizable_tracker_info::right)
211
+ b.right = ob.right ;
212
+ }
213
+
214
+ // Constrain height
215
+ if (height < limits.min .y || height > limits.max .y )
216
+ {
217
+ if (state->_handle & resizable_tracker_info::top)
218
+ b.top = ob.top ;
219
+ else if (state->_handle & resizable_tracker_info::bottom)
220
+ b.bottom = ob.bottom ;
221
+ }
222
+ if (b != ob)
223
+ {
224
+ fl->bounds (b);
225
+ ctx.view .refresh ();
226
+ }
227
+ }
228
+ }
229
+ }
230
+ }
231
+
98
232
void close_floating_element (context& ctx, floating_element* fl)
99
233
{
100
234
ctx.view .remove (fl->shared_from_this ());
101
235
}
236
+
237
+ void minimize_floating_element (context& ctx, floating_element* fl)
238
+ {
239
+ ctx.view .remove (fl->shared_from_this ());
240
+ }
102
241
}
0 commit comments