Skip to content

Commit e36d07f

Browse files
authored
Add flex_grow to last element in resizable (#799)
1 parent 7972642 commit e36d07f

File tree

1 file changed

+16
-8
lines changed

1 file changed

+16
-8
lines changed

Diff for: src/views/resizable.rs

+16-8
Original file line numberDiff line numberDiff line change
@@ -380,12 +380,14 @@ impl ResizableStack {
380380

381381
let child = self.id.with_children(|c| c[handle_idx]);
382382
let offset = self.style_offsets[handle_idx];
383+
let is_last = handle_idx == self.style_offsets.len() - 1;
383384
child.update_style(
384385
offset,
385386
Style::new()
386387
.width(new_width)
387-
.max_width(new_width)
388-
.min_width(20.),
388+
.min_width(20.)
389+
.apply_if(!is_last, |s| s.max_width(new_width))
390+
.apply_if(is_last, |s| s.flex_grow(1.)),
389391
);
390392

391393
// Calculate next width based on actual applied change
@@ -394,12 +396,14 @@ impl ResizableStack {
394396

395397
let child = self.id.with_children(|c| c[handle_idx + 1]);
396398
let offset = self.style_offsets[handle_idx + 1];
399+
let is_last = handle_idx + 1 == self.style_offsets.len() - 1;
397400
child.update_style(
398401
offset,
399402
Style::new()
400403
.width(next_width)
401-
.max_width(next_width)
402-
.min_width(20.),
404+
.min_width(20.)
405+
.apply_if(!is_last, |s| s.max_width(next_width))
406+
.apply_if(is_last, |s| s.flex_grow(1.)),
403407
);
404408
}
405409
FlexDirection::Column | FlexDirection::ColumnReverse => {
@@ -425,12 +429,14 @@ impl ResizableStack {
425429

426430
let child = self.id.with_children(|c| c[handle_idx]);
427431
let offset = self.style_offsets[handle_idx];
432+
let is_last = handle_idx == self.style_offsets.len() - 1;
428433
child.update_style(
429434
offset,
430435
Style::new()
431436
.height(new_height)
432-
.max_height(new_height)
433-
.min_height(20.),
437+
.min_height(20.)
438+
.apply_if(!is_last, |s| s.max_height(new_height))
439+
.apply_if(is_last, |s| s.flex_grow(1.)),
434440
);
435441

436442
// Calculate next height based on actual applied change
@@ -439,12 +445,14 @@ impl ResizableStack {
439445

440446
let child = self.id.with_children(|c| c[handle_idx + 1]);
441447
let offset = self.style_offsets[handle_idx + 1];
448+
let is_last = handle_idx + 1 == self.style_offsets.len() - 1;
442449
child.update_style(
443450
offset,
444451
Style::new()
445452
.height(next_height)
446-
.max_height(next_height)
447-
.min_height(20.),
453+
.min_height(20.)
454+
.apply_if(!is_last, |s| s.max_height(next_height))
455+
.apply_if(is_last, |s| s.flex_grow(1.)),
448456
);
449457
}
450458
}

0 commit comments

Comments
 (0)