Skip to content

Commit

Permalink
karm-kira: Moved resizable there and added it to the zoo.
Browse files Browse the repository at this point in the history
  • Loading branch information
sleepy-monax committed Nov 16, 2024
1 parent ccf3e12 commit bac6305
Show file tree
Hide file tree
Showing 7 changed files with 70 additions and 45 deletions.
2 changes: 2 additions & 0 deletions src/apps/hideo-zoo/app.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "page-hsv-square.h"
#include "page-navbar.h"
#include "page-radio.h"
#include "page-resizable.h"
#include "page-rows.h"
#include "page-side-nav.h"
#include "page-side-panel.h"
Expand All @@ -36,6 +37,7 @@ static Array PAGES = {
&PAGE_HSV_SQUARE,
&PAGE_NAVBAR,
&PAGE_RADIO,
&PAGE_RESIZABLE,
&PAGE_ROWS,
&PAGE_SIDE_PANEL,
&PAGE_SIDENAV,
Expand Down
26 changes: 26 additions & 0 deletions src/apps/hideo-zoo/page-resizable.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#pragma once

#include <karm-kira/resizable.h>
#include <karm-ui/layout.h>
#include <mdi/view-compact.h>

#include "model.h"

namespace Hideo::Zoo {

static inline Page PAGE_RESIZABLE{
Mdi::VIEW_COMPACT,
"Resizable",
"A control that allows the user to resize an element.",
[] {
return Ui::hflow(
Ui::labelMedium("One") | Ui::center() | Kr::resizable(Kr::ResizeHandle::END, 200, NONE),
Ui::vflow(
Ui::labelMedium("Two") | Ui::center() | Kr::resizable(Kr::ResizeHandle::BOTTOM, 200, NONE),
Ui::labelMedium("Three") | Ui::center() | Ui::grow()
) | Ui::grow()
);
},
};

} // namespace Hideo::Zoo
52 changes: 26 additions & 26 deletions src/libs/karm-ui/resizable.cpp → src/libs/karm-kira/resizable.cpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
#include "resizable.h"

namespace Karm::Ui {
namespace Karm::Kira {

struct Resizable : public ProxyNode<Resizable> {
struct Resizable : public Ui::ProxyNode<Resizable> {
Math::Vec2i _size;
OnChange<Math::Vec2i> _onChange;
Ui::OnChange<Math::Vec2i> _onChange;

Resizable(Child child, Math::Vec2i size, OnChange<Math::Vec2i> onChange)
Resizable(Ui::Child child, Math::Vec2i size, Ui::OnChange<Math::Vec2i> onChange)
: ProxyNode<Resizable>(child),
_size(size),
_onChange(std::move(onChange)) {}
Expand All @@ -19,10 +19,10 @@ struct Resizable : public ProxyNode<Resizable> {
}

void bubble(App::Event &e) override {
if (auto de = e.is<DragEvent>()) {
if (de->type == DragEvent::DRAG) {
if (auto de = e.is<Ui::DragEvent>()) {
if (de->type == Ui::DragEvent::DRAG) {
_size = _size + de->delta;
auto minSize = child().size({}, Hint::MIN);
auto minSize = child().size({}, Ui::Hint::MIN);
_size = _size.max(minSize);
if (_onChange) {
_onChange(*this, _size);
Expand All @@ -36,56 +36,56 @@ struct Resizable : public ProxyNode<Resizable> {
ProxyNode<Resizable>::bubble(e);
}

Math::Vec2i size(Math::Vec2i s, Hint hint) override {
Math::Vec2i size(Math::Vec2i s, Ui::Hint hint) override {
return child()
.size(s, hint)
.max(_size);
}
};

Child resizable(Child child, Math::Vec2i size, OnChange<Math::Vec2i> onChange) {
Ui::Child resizable(Ui::Child child, Math::Vec2i size, Ui::OnChange<Math::Vec2i> onChange) {
return makeStrong<Resizable>(child, size, std::move(onChange));
}

static Child _resizeHandle(Math::Vec2i dir) {
return empty(4) |
box({
.backgroundFill = GRAY800,
static Ui::Child _resizeHandle(Math::Vec2i dir) {
return Ui::empty(4) |
Ui::box({
.backgroundFill = Ui::GRAY800,
}) |
dragRegion(dir);
Ui::dragRegion(dir);
}

Child resizable(Child child, ResizeHandle handlePosition, Math::Vec2i size, OnChange<Math::Vec2i> onChange) {
Ui::Child resizable(Ui::Child child, ResizeHandle handlePosition, Math::Vec2i size, Ui::OnChange<Math::Vec2i> onChange) {
if (handlePosition == ResizeHandle::TOP) {
return stack(
return Ui::stack(
child,
vflow(
Ui::vflow(
_resizeHandle({0, -1})
)
) |
resizable(size, std::move(onChange));
} else if (handlePosition == ResizeHandle::START) {
return stack(
return Ui::stack(
child,
hflow(
Ui::hflow(
_resizeHandle({-1, 0})
)
) |
resizable(size, std::move(onChange));
} else if (handlePosition == ResizeHandle::BOTTOM) {
return stack(
return Ui::stack(
child,
hflow(
grow(NONE),
Ui::vflow(
Ui::grow(NONE),
_resizeHandle({0, 1})
)
) |
resizable(size, std::move(onChange));
} else if (handlePosition == ResizeHandle::END) {
return stack(
return Ui::stack(
child,
vflow(
grow(NONE),
Ui::hflow(
Ui::grow(NONE),
_resizeHandle({1, 0})
)
) |
Expand All @@ -95,4 +95,4 @@ Child resizable(Child child, ResizeHandle handlePosition, Math::Vec2i size, OnCh
}
}

} // namespace Karm::Ui
} // namespace Karm::Kira
22 changes: 12 additions & 10 deletions src/libs/karm-ui/resizable.h → src/libs/karm-kira/resizable.h
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
#pragma once

#include "drag.h"
#include "input.h"
#include <karm-ui/drag.h>
#include <karm-ui/input.h>

namespace Karm::Ui {
#include "_prelude.h"

namespace Karm::Kira {

enum struct ResizeHandle {
TOP,
Expand All @@ -12,20 +14,20 @@ enum struct ResizeHandle {
END
};

Ui::Child resizable(Ui::Child child, Math::Vec2i size, OnChange<Math::Vec2i> onChange);
Ui::Child resizable(Ui::Child child, Math::Vec2i size, Ui::OnChange<Math::Vec2i> onChange);

Ui::Child resizable(Ui::Child child, ResizeHandle handlePosition, Math::Vec2i size, OnChange<Math::Vec2i> onChange);
Ui::Child resizable(Ui::Child child, ResizeHandle handlePosition, Math::Vec2i size, Ui::OnChange<Math::Vec2i> onChange);

static inline auto resizable(Math::Vec2i size, OnChange<Math::Vec2i> onChange) {
return [size, onChange = std::move(onChange)](Ui::Child child) mutable -> Child {
static inline auto resizable(Math::Vec2i size, Ui::OnChange<Math::Vec2i> onChange) {
return [size, onChange = std::move(onChange)](Ui::Child child) mutable -> Ui::Child {
return resizable(child, size, std::move(onChange));
};
}

static inline auto resizable(ResizeHandle handlePosition, Math::Vec2i size, OnChange<Math::Vec2i> onChange) {
return [handlePosition, size, onChange = std::move(onChange)](Ui::Child child) mutable -> Child {
static inline auto resizable(ResizeHandle handlePosition, Math::Vec2i size, Ui::OnChange<Math::Vec2i> onChange) {
return [handlePosition, size, onChange = std::move(onChange)](Ui::Child child) mutable -> Ui::Child {
return resizable(child, handlePosition, size, std::move(onChange));
};
}

} // namespace Karm::Ui
} // namespace Karm::Kira
4 changes: 2 additions & 2 deletions src/web/vaev-browser/app.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include <karm-kira/context-menu.h>
#include <karm-kira/dialog.h>
#include <karm-kira/error-page.h>
#include <karm-kira/resizable.h>
#include <karm-kira/scaffold.h>
#include <karm-kira/side-panel.h>
#include <karm-mime/mime.h>
Expand All @@ -10,7 +11,6 @@
#include <karm-ui/input.h>
#include <karm-ui/layout.h>
#include <karm-ui/popover.h>
#include <karm-ui/resizable.h>
#include <karm-ui/scroll.h>
#include <mdi/alert-decagram.h>
#include <mdi/arrow-left.h>
Expand Down Expand Up @@ -231,7 +231,7 @@ Ui::Child appContent(State const &s) {
return webview(s);
return Ui::hflow(
webview(s) | Ui::grow(),
sidePanel(s) | Ui::resizable(Ui::ResizeHandle::START, {320}, NONE)
sidePanel(s) | Kr::resizable(Kr::ResizeHandle::START, {320}, NONE)
);
}

Expand Down
4 changes: 2 additions & 2 deletions src/web/vaev-browser/inspect.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#include <karm-kira/resizable.h>
#include <karm-kira/side-panel.h>
#include <karm-ui/input.h>
#include <karm-ui/layout.h>
#include <karm-ui/reducer.h>
#include <karm-ui/resizable.h>
#include <karm-ui/scroll.h>
#include <karm-ui/view.h>
#include <mdi/chevron-down.h>
Expand Down Expand Up @@ -146,7 +146,7 @@ Ui::Child computedStyles() {
Ui::Child inspect(Strong<Vaev::Markup::Document> n, InspectState const &s, Ui::Action<InspectorAction> a) {
return Ui::vflow(
node(n, s, a) | Ui::vscroll() | Ui::grow(),
computedStyles() | Ui::resizable(Ui::ResizeHandle::TOP, {128}, NONE)
computedStyles() | Kr::resizable(Kr::ResizeHandle::TOP, {128}, NONE)
);
}

Expand Down
5 changes: 0 additions & 5 deletions src/web/vaev-driver/res/start-page.xhtml
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,6 @@
font-size: 1.2rem;
}

.search-container {
display: flex;
flex-direction: column;
width: 60%;
}

.recent {
display: flex;
Expand Down

0 comments on commit bac6305

Please sign in to comment.