Skip to content

Commit d657c81

Browse files
committed
karm-kira: Fix panel resizing.
1 parent 82e7589 commit d657c81

4 files changed

Lines changed: 17 additions & 13 deletions

File tree

src/apps/hideo-zoo/pages.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -438,9 +438,9 @@ Page PAGE_RESIZABLE{
438438
"A control that allows the user to resize an element.",
439439
[] {
440440
return Ui::hflow(
441-
Ui::labelMedium("One") | Ui::center() | Kr::resizable(Kr::ResizeHandle::END, 200, Ui::SINK<Math::Vec2i>),
441+
Ui::labelMedium("One") | Ui::center() | Kr::resizable(Kr::ResizeHandle::END, 200, NONE),
442442
Ui::vflow(
443-
Ui::labelMedium("Two") | Ui::center() | Kr::resizable(Kr::ResizeHandle::BOTTOM, 200, Ui::SINK<Math::Vec2i>),
443+
Ui::labelMedium("Two") | Ui::center() | Kr::resizable(Kr::ResizeHandle::BOTTOM, 200, NONE),
444444
Ui::labelMedium("Three") | Ui::center() | Ui::grow()
445445
) | Ui::grow()
446446
);

src/libs/karm-kira/resizable.cpp

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ export enum struct ResizeHandle {
1818

1919
struct Resizable : Ui::ProxyNode<Resizable> {
2020
Math::Vec2i _size;
21-
Ui::Send<Math::Vec2i> _onChange;
21+
Opt<Ui::Send<Math::Vec2i>> _onChange;
2222

23-
Resizable(Ui::Child child, Math::Vec2i size, Ui::Send<Math::Vec2i> onChange)
23+
Resizable(Ui::Child child, Math::Vec2i size, Opt<Ui::Send<Math::Vec2i>> onChange)
2424
: ProxyNode<Resizable>(child),
2525
_size(size),
2626
_onChange(std::move(onChange)) {}
@@ -37,7 +37,11 @@ struct Resizable : Ui::ProxyNode<Resizable> {
3737
_size = _size + de->delta;
3838
auto minSize = child().size({}, Ui::Hint::MIN);
3939
_size = _size.max(minSize);
40-
_onChange(*this, _size);
40+
if (_onChange) {
41+
_onChange(*this, _size);
42+
} else {
43+
Ui::shouldLayout(*this);
44+
}
4145
e.accept();
4246
}
4347
}
@@ -52,11 +56,11 @@ struct Resizable : Ui::ProxyNode<Resizable> {
5256
}
5357
};
5458

55-
export Ui::Child resizable(Ui::Child child, Math::Vec2i size, Ui::Send<Math::Vec2i> onChange) {
59+
export Ui::Child resizable(Ui::Child child, Math::Vec2i size, Opt<Ui::Send<Math::Vec2i>> onChange) {
5660
return makeRc<Resizable>(child, size, std::move(onChange));
5761
}
5862

59-
export auto resizable(Math::Vec2i size, Ui::Send<Math::Vec2i> onChange) {
63+
export auto resizable(Math::Vec2i size, Opt<Ui::Send<Math::Vec2i>> onChange) {
6064
return [size, onChange = std::move(onChange)](Ui::Child child) mutable -> Ui::Child {
6165
return resizable(child, size, std::move(onChange));
6266
};
@@ -70,7 +74,7 @@ static Ui::Child _resizeHandle(Math::Vec2i dir) {
7074
Ui::dragRegion(dir);
7175
}
7276

73-
export Ui::Child resizable(Ui::Child child, ResizeHandle handlePosition, Math::Vec2i size, Ui::Send<Math::Vec2i> onChange) {
77+
export Ui::Child resizable(Ui::Child child, ResizeHandle handlePosition, Math::Vec2i size, Opt<Ui::Send<Math::Vec2i>> onChange) {
7478
if (handlePosition == ResizeHandle::TOP) {
7579
return Ui::stack(
7680
child,
@@ -110,9 +114,9 @@ export Ui::Child resizable(Ui::Child child, ResizeHandle handlePosition, Math::V
110114
}
111115
}
112116

113-
export auto resizable(ResizeHandle handlePosition, Math::Vec2i size, Ui::Send<Math::Vec2i> onChange) {
114-
return [handlePosition, size, onChange = std::move(onChange)](Ui::Child child) mutable -> Ui::Child {
115-
return resizable(child, handlePosition, size, std::move(onChange));
117+
export auto resizable(ResizeHandle handlePosition, Math::Vec2i size, Opt<Ui::Send<Math::Vec2i>> onChange) {
118+
return [handlePosition, size, onChange](Ui::Child child) mutable -> Ui::Child {
119+
return resizable(child, handlePosition, size, onChange);
116120
};
117121
}
118122

src/web/vaev-browser/app.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,7 @@ Ui::Child appContent(State const& s) {
370370
}
371371
return Ui::hflow(
372372
webview(s) | Ui::grow(),
373-
sidePanel(s) | Kr::resizable(Kr::ResizeHandle::START, {320}, Ui::SINK<Math::Vec2i>)
373+
sidePanel(s) | Kr::resizable(Kr::ResizeHandle::START, {320}, NONE)
374374
);
375375
}
376376

src/web/vaev-browser/inspect.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ Ui::Child computedStyles() {
179179
export Ui::Child inspect(Gc::Ref<Vaev::Dom::Document> n, InspectState const& s, Ui::Action<InspectorAction> a) {
180180
return Ui::vflow(
181181
node(n, s, a) | Ui::vscroll() | Ui::grow(),
182-
computedStyles() | Kr::resizable(Kr::ResizeHandle::TOP, {128}, Ui::SINK<Math::Vec2i>)
182+
computedStyles() | Kr::resizable(Kr::ResizeHandle::TOP, {128}, NONE)
183183
);
184184
}
185185

0 commit comments

Comments
 (0)