@@ -20,11 +20,9 @@ namespace GUI {
20
20
Splitter::Splitter (Orientation orientation)
21
21
: m_orientation (orientation)
22
22
{
23
- REGISTER_INT_PROPERTY (" first_resizee_minimum_size" , first_resizee_minimum_size, set_first_resizee_minimum_size);
24
- REGISTER_INT_PROPERTY (" second_resizee_minimum_size" , second_resizee_minimum_size, set_second_resizee_minimum_size);
25
- REGISTER_ENUM_PROPERTY (" fixed_resizee" , fixed_resizee, set_fixed_resizee, FixedResizee,
26
- { FixedResizee::First, " First" },
27
- { FixedResizee::Second, " Second" });
23
+ REGISTER_ENUM_PROPERTY (" opportunistic_resizee" , opportunisitic_resizee, set_opportunisitic_resizee, OpportunisticResizee,
24
+ { OpportunisticResizee::First, " First" },
25
+ { OpportunisticResizee::Second, " Second" });
28
26
29
27
set_background_role (ColorRole::Button);
30
28
set_layout<BoxLayout>(orientation);
@@ -197,7 +195,6 @@ void Splitter::recompute_grabbables()
197
195
set_hovered_grabbable (&m_grabbables[old_hovered_index.value ()]);
198
196
}
199
197
200
- // FIXME: Respect the child widgets min and max sizes
201
198
void Splitter::mousemove_event (MouseEvent& event)
202
199
{
203
200
auto * grabbable = grabbable_at (event.position ());
@@ -206,50 +203,33 @@ void Splitter::mousemove_event(MouseEvent& event)
206
203
override_cursor (grabbable != nullptr );
207
204
return ;
208
205
}
209
- auto delta = event.position () - m_resize_origin;
210
206
if (!m_first_resizee || !m_second_resizee) {
211
- // One or both of the resizees were deleted during an ongoing resize, screw this.
212
207
m_resizing = false ;
213
208
return ;
214
209
}
215
- auto new_first_resizee_size = m_first_resizee_start_size;
216
- auto new_second_resizee_size = m_second_resizee_start_size;
217
210
218
- new_first_resizee_size.set_primary_size_for_orientation (m_orientation, new_first_resizee_size.primary_size_for_orientation (m_orientation) + delta.primary_offset_for_orientation (m_orientation));
219
- new_second_resizee_size.set_primary_size_for_orientation (m_orientation, new_second_resizee_size.primary_size_for_orientation (m_orientation) - delta.primary_offset_for_orientation (m_orientation));
220
-
221
- if (new_first_resizee_size.primary_size_for_orientation (m_orientation) < m_first_resizee_minimum_size) {
222
- int correction = m_first_resizee_minimum_size - new_first_resizee_size.primary_size_for_orientation (m_orientation);
223
- new_first_resizee_size.set_primary_size_for_orientation (m_orientation, new_first_resizee_size.primary_size_for_orientation (m_orientation) + correction);
224
- new_second_resizee_size.set_primary_size_for_orientation (m_orientation, new_second_resizee_size.primary_size_for_orientation (m_orientation) - correction);
225
- }
226
- if (new_second_resizee_size.primary_size_for_orientation (m_orientation) < m_second_resizee_minimum_size) {
227
- int correction = m_second_resizee_minimum_size - new_second_resizee_size.primary_size_for_orientation (m_orientation);
228
- new_second_resizee_size.set_primary_size_for_orientation (m_orientation, new_second_resizee_size.primary_size_for_orientation (m_orientation) + correction);
229
- new_first_resizee_size.set_primary_size_for_orientation (m_orientation, new_first_resizee_size.primary_size_for_orientation (m_orientation) - correction);
230
- }
211
+ auto delta = (event.position () - m_resize_origin).primary_offset_for_orientation (m_orientation);
212
+ auto new_first_resizee_size = clamp (m_first_resizee_start_size.primary_size_for_orientation (m_orientation) + delta, 0 , m_first_resizee_max_size);
213
+ auto new_second_resizee_size = clamp (m_second_resizee_start_size.primary_size_for_orientation (m_orientation) - delta, 0 , m_second_resizee_max_size);
231
214
232
215
if (m_orientation == Orientation::Horizontal) {
233
- if (fixed_resizee () == FixedResizee::First) {
234
- m_first_resizee->set_fixed_width (new_first_resizee_size.width ());
235
- m_second_resizee->set_min_width (SpecialDimension::Shrink);
236
- m_second_resizee->set_max_width (SpecialDimension::Grow);
216
+ if (opportunisitic_resizee () == OpportunisticResizee::First) {
217
+ m_first_resizee->set_preferred_width (SpecialDimension::OpportunisticGrow);
218
+ m_second_resizee->set_preferred_width (new_second_resizee_size);
237
219
} else {
238
- VERIFY (fixed_resizee () == FixedResizee::Second);
239
- m_second_resizee->set_fixed_width (new_second_resizee_size.width ());
240
- m_first_resizee->set_min_width (SpecialDimension::Shrink);
241
- m_first_resizee->set_max_width (SpecialDimension::Grow);
220
+ VERIFY (opportunisitic_resizee () == OpportunisticResizee::Second);
221
+ m_second_resizee->set_preferred_width (SpecialDimension::OpportunisticGrow);
222
+ m_first_resizee->set_preferred_width (new_first_resizee_size);
242
223
}
243
224
} else {
244
- if (fixed_resizee () == FixedResizee ::First) {
245
- m_first_resizee->set_fixed_height (new_first_resizee_size. height () );
246
- m_second_resizee->set_min_height (SpecialDimension::Shrink );
247
- m_second_resizee-> set_max_height (SpecialDimension::Grow);
225
+ if (opportunisitic_resizee () == OpportunisticResizee ::First) {
226
+ m_first_resizee->set_preferred_height (SpecialDimension::OpportunisticGrow );
227
+ m_second_resizee->set_preferred_height (new_second_resizee_size );
228
+
248
229
} else {
249
- VERIFY (fixed_resizee () == FixedResizee::Second);
250
- m_second_resizee->set_fixed_height (new_second_resizee_size.height ());
251
- m_first_resizee->set_min_height (SpecialDimension::Shrink);
252
- m_first_resizee->set_max_height (SpecialDimension::Grow);
230
+ VERIFY (opportunisitic_resizee () == OpportunisticResizee::Second);
231
+ m_second_resizee->set_preferred_height (SpecialDimension::OpportunisticGrow);
232
+ m_first_resizee->set_preferred_height (new_first_resizee_size);
253
233
}
254
234
}
255
235
@@ -272,13 +252,13 @@ void Splitter::custom_layout()
272
252
if (m_last_child_count > child_widgets.size ()) {
273
253
bool has_child_to_fill_space = false ;
274
254
for (auto & child : child_widgets) {
275
- if (child.max_size ().primary_size_for_orientation (m_orientation).is_grow ()) {
255
+ if (child.preferred_size ().primary_size_for_orientation (m_orientation).is_opportunistic_grow ()) {
276
256
has_child_to_fill_space = true ;
277
257
break ;
278
258
}
279
259
}
280
260
if (!has_child_to_fill_space)
281
- child_widgets.last ().set_preferred_size (SpecialDimension::Grow );
261
+ child_widgets.last ().set_preferred_size (SpecialDimension::OpportunisticGrow );
282
262
}
283
263
}
284
264
0 commit comments