Skip to content

Commit e1b6423

Browse files
committed
karm+vaev: Update from upstream.
1 parent 4658068 commit e1b6423

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+796
-376
lines changed

src/apps/hideo-zoo/page-print-dialog.h

+3-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@ static inline Page PAGE_PRINT_DIALOG{
1919
[](auto &n) {
2020
Ui::showDialog(
2121
n,
22-
Kr::printDialog()
22+
Kr::printDialog([](Print::Settings const &Settings) -> Vec<Strong<Scene::Page>> {
23+
return {makeStrong<Scene::Page>(Settings.paper.size().cast<isize>())};
24+
})
2325
);
2426
},
2527
"Show dialog"

src/clis/serv/res/public/style.css

-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ html,
1717
}
1818

1919

20-
/* A simple CSS framework that tries to mimic the look and feel of karm-ui. */
2120

2221
:root {
2322
--k-gray050: #fafafa;

src/libs/karm-base/tests/test-vec.cpp

+15
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,19 @@ test$("vec-default-constructed") {
1313
return Ok();
1414
}
1515

16+
test$("vec-push-front-slice") {
17+
Vec<int> vec = {4, 5};
18+
Array els{1, 2, 3};
19+
vec.pushFront(els);
20+
21+
expectEq$(vec.len(), 5uz);
22+
expectEq$(vec[0], 1);
23+
expectEq$(vec[1], 2);
24+
expectEq$(vec[2], 3);
25+
expectEq$(vec[3], 4);
26+
expectEq$(vec[4], 5);
27+
28+
return Ok();
29+
}
30+
1631
} // namespace Karm::Base::Tests

src/libs/karm-base/vec.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ struct _Vec {
8888
void pushFront(T &&value) { _buf.insert(0, std::move(value)); }
8989

9090
void pushFront(Sliceable<T> auto &other) {
91-
for (auto &v : other)
91+
for (auto &v : iterRev(other))
9292
pushFront(v);
9393
}
9494

src/libs/karm-gfx/cpu/canvas.cpp

+15-5
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,9 @@ void CpuCanvas::clip(FillRule) {
190190
// MARK: Shape Operations ------------------------------------------------------
191191

192192
[[gnu::flatten]] void CpuCanvas::_fillRect(Math::Recti r, Gfx::Color color) {
193-
r = current().trans.apply(r.cast<f64>()).cast<isize>();
193+
// FIXME: Properly handle offaxis rectangles
194+
r = current().trans.apply(r.cast<f64>()).bound().cast<isize>();
195+
194196
r = current().clip.clipTo(r);
195197

196198
if (color.alpha == 255) {
@@ -226,7 +228,9 @@ void CpuCanvas::fill(Math::Recti r, Math::Radiif radii) {
226228
}
227229

228230
void CpuCanvas::clip(Math::Rectf rect) {
229-
rect = current().trans.apply(rect.cast<f64>());
231+
// FIXME: Properly handle offaxis rectangles
232+
rect = current().trans.apply(rect.cast<f64>()).bound();
233+
230234
current().clip = rect.cast<isize>().clipTo(current().clip);
231235
}
232236

@@ -257,7 +261,9 @@ void CpuCanvas::clear(Color color) {
257261
}
258262

259263
void CpuCanvas::clear(Math::Recti rect, Color color) {
260-
rect = current().trans.apply(rect.cast<f64>()).cast<isize>();
264+
// FIXME: Properly handle offaxis rectangles
265+
rect = current().trans.apply(rect.cast<f64>()).bound().cast<isize>();
266+
261267
rect = current().clip.clipTo(rect);
262268
mutPixels()
263269
.clip(rect)
@@ -312,7 +318,9 @@ void CpuCanvas::plot(Math::Recti rect, Color color) {
312318
Pixels src, Math::Recti srcRect, auto srcFmt,
313319
MutPixels dest, Math::Recti destRect, auto destFmt
314320
) {
315-
destRect = current().trans.apply(destRect.cast<f64>()).cast<isize>();
321+
// FIXME: Properly handle offaxis rectangles
322+
destRect = current().trans.apply(destRect.cast<f64>()).bound().cast<isize>();
323+
316324
auto clipDest = current().clip.clipTo(destRect);
317325

318326
auto hratio = srcRect.height / (f64)destRect.height;
@@ -355,7 +363,9 @@ void CpuCanvas::apply(Filter filter) {
355363
}
356364

357365
void CpuCanvas::apply(Filter filter, Math::Recti r) {
358-
r = current().trans.apply(r.cast<f64>()).cast<isize>();
366+
// FIXME: Properly handle offaxis rectangles
367+
r = current().trans.apply(r.cast<f64>()).bound().cast<isize>();
368+
359369
r = current().clip.clipTo(r);
360370

361371
filter.apply(mutPixels().clip(r));

src/libs/karm-kira/print-dialog.cpp

+82-46
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#include <karm-app/form-factor.h>
2+
#include <karm-print/paper.h>
23
#include <karm-ui/layout.h>
4+
#include <karm-ui/reducer.h>
35
#include <karm-ui/scroll.h>
46

57
#include "checkbox.h"
@@ -10,12 +12,29 @@
1012

1113
namespace Karm::Kira {
1214

13-
Ui::Child _printSelect(usize index) {
15+
// MARK: Model -----------------------------------------------------------------
16+
17+
struct State {
18+
PrintPreview preview;
19+
Print::Settings settings = {};
20+
Vec<Strong<Scene::Page>> pages = preview(settings);
21+
};
22+
23+
using Action = Union<None>;
24+
25+
void reduce(State &, Action) {
26+
}
27+
28+
using Model = Ui::Model<State, Action, reduce>;
29+
30+
// MARK: Dialog ----------------------------------------------------------------
31+
32+
Ui::Child _printSelect(State const &s, usize index) {
1433
return Ui::hflow(
1534
8,
1635
Math::Align::CENTER,
1736
checkbox(true, NONE),
18-
Ui::labelMedium("Page {} of 3", index + 1)
37+
Ui::labelMedium("Page {} of {}", index + 1, s.pages.len())
1938
) |
2039
Ui::box({
2140
.margin = 8,
@@ -27,56 +46,61 @@ Ui::Child _printSelect(usize index) {
2746
});
2847
}
2948

30-
Ui::Child _printPaper(usize index) {
49+
Ui::Child _printPaper(State const &s, usize index) {
3150
auto scale = 1.;
3251
auto isMobile = App::useFormFactor() == App::FormFactor::MOBILE;
3352
if (isMobile) {
3453
scale = 0.5;
3554
}
3655

3756
return Ui::stack(
38-
Ui::empty(Math::Vec2f{320 * scale, 452 * scale}.cast<isize>()) |
39-
Ui::box({
40-
.borderRadii = 6,
41-
.borderWidth = 1,
42-
.borderFill = Gfx::BLACK.withOpacity(0.1),
43-
.backgroundFill = Gfx::WHITE,
44-
}),
45-
_printSelect(index) | Ui::align(Math::Align::BOTTOM_END)
46-
);
57+
Ui::canvas(s.pages[index]) |
58+
Ui::box({
59+
.borderRadii = 6,
60+
.borderWidth = 1,
61+
.borderFill = Ui::GRAY50.withOpacity(0.1),
62+
.backgroundFill = Gfx::WHITE,
63+
}),
64+
_printSelect(s, index) | Ui::align(Math::Align::BOTTOM_END)
65+
) |
66+
Ui::pinSize(Math::Vec2f{320 * scale, 452 * scale}.cast<isize>());
4767
}
4868

49-
Ui::Child _printPreviewMobile() {
69+
Ui::Child _printPreviewMobile(State const &s) {
70+
Ui::Children pages;
71+
for (usize i = 0; i < s.pages.len(); ++i) {
72+
pages.pushBack(_printPaper(s, i));
73+
}
74+
5075
return Ui::hflow(
5176
8,
5277
Math::Align::CENTER,
53-
_printPaper(0),
54-
_printPaper(1),
55-
_printPaper(2)
78+
std::move(pages)
5679
) |
5780
Ui::insets(32) |
5881
Ui::hscroll() |
5982
Ui::box(
6083
{
61-
.borderRadii = {0, 0, 0, 12},
6284
.backgroundFill = Ui::GRAY950,
6385
}
6486
);
6587
}
6688

67-
Ui::Child _printPreview() {
89+
Ui::Child _printPreview(State const &s) {
90+
Ui::Children pages;
91+
for (usize i = 0; i < s.pages.len(); ++i) {
92+
pages.pushBack(_printPaper(s, i));
93+
}
94+
6895
return Ui::vflow(
6996
8,
7097
Math::Align::CENTER,
71-
_printPaper(0),
72-
_printPaper(1),
73-
_printPaper(2)
98+
std::move(pages)
7499
) |
75100
Ui::insets(32) |
76101
Ui::vscroll() |
77102
Ui::box(
78103
{
79-
.borderRadii = {0, 0, 0, 12},
80104
.backgroundFill = Ui::GRAY950,
81105
}
82106
);
@@ -106,6 +130,24 @@ Ui::Child _destinationSelect() {
106130
);
107131
}
108132

133+
Ui::Child _paperSelect() {
134+
return select(selectValue("A4"s), [] -> Ui::Children {
135+
Vec<Ui::Child> groups;
136+
137+
for (auto &serie : Print::SERIES) {
138+
Vec<Ui::Child> items;
139+
items.pushBack(selectLabel(serie.name));
140+
for (auto const &stock : serie.stocks) {
141+
items.pushBack(selectItem(Ui::NOP, stock.name));
142+
}
143+
144+
groups.pushBack(selectGroup(std::move(items)));
145+
}
146+
147+
return groups;
148+
});
149+
}
150+
109151
Ui::Child _printSettings() {
110152
return Ui::vflow(
111153
rowContent(
@@ -158,18 +200,11 @@ Ui::Child _printSettings() {
158200
NONE,
159201
Karm::Ui::Slots{[] -> Ui::Children {
160202
return {
161-
selectRow(
162-
selectValue("A4"s),
163-
[] -> Ui::Children {
164-
return {
165-
selectItem(Ui::NOP, "A3"s),
166-
selectItem(Ui::NOP, "A4"s),
167-
selectItem(Ui::NOP, "A5"s),
168-
selectItem(Ui::NOP, "Letter"s),
169-
selectItem(Ui::NOP, "Legal"s),
170-
};
171-
},
172-
"Paper size"s
203+
rowContent(
204+
NONE,
205+
"Paper"s,
206+
NONE,
207+
_paperSelect()
173208
),
174209
selectRow(
175210
selectValue("1"s),
@@ -213,11 +248,11 @@ Ui::Child _printControls() {
213248
Ui::minSize({320, Ui::UNCONSTRAINED});
214249
}
215250

216-
Ui::Child _printDialog() {
251+
Ui::Child _printDialog(State const &s) {
217252
return dialogContent({
218253
dialogTitleBar("Print"s),
219254
Ui::hflow(
220-
_printPreview(),
255+
_printPreview(s),
221256
_printControls() | Ui::grow()
222257
) | Ui::maxSize({Ui::UNCONSTRAINED, 500}) |
223258
Ui::grow(),
@@ -229,16 +264,17 @@ Ui::Child _printDialog() {
229264
});
230265
}
231266

232-
Ui::Child _printDialogMobile() {
267+
Ui::Child _printDialogMobile(State const &s) {
233268
return dialogContent({
234269
dialogTitleBar("Print"s),
235270
Ui::separator(),
236271
Ui::vflow(
237-
_printPreviewMobile(),
272+
_printPreviewMobile(s),
238273
Ui::separator(),
239274
titleRow("Settings"s),
240275
_printSettings()
241-
) | Ui::vscroll() |
276+
) | Ui::minSize(500) |
277+
Ui::vscroll() |
242278
Ui::grow(),
243279
Ui::separator(),
244280
dialogFooter({
@@ -248,13 +284,13 @@ Ui::Child _printDialogMobile() {
248284
});
249285
}
250286

251-
Ui::Child printDialog() {
252-
auto isMobile = App::useFormFactor() == App::FormFactor::MOBILE;
253-
254-
if (isMobile) {
255-
return _printDialogMobile();
256-
}
257-
return _printDialog();
287+
Ui::Child printDialog(PrintPreview preview) {
288+
return Ui::reducer<Model>({preview}, [](State const &s) {
289+
auto isMobile = App::useFormFactor() == App::FormFactor::MOBILE;
290+
if (isMobile)
291+
return _printDialogMobile(s);
292+
return _printDialog(s);
293+
});
258294
}
259295

260296
} // namespace Karm::Kira

src/libs/karm-kira/print-dialog.h

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
#pragma once
22

3+
#include <karm-scene/page.h>
34
#include <karm-ui/input.h>
45

56
#include "_prelude.h"
67

78
namespace Karm::Kira {
89

9-
Ui::Child printDialog();
10+
using PrintPreview = SharedFunc<Vec<Strong<Scene::Page>>(Print::Settings const &)>;
11+
12+
Ui::Child printDialog(PrintPreview preview);
1013

1114
} // namespace Karm::Kira

src/libs/karm-kira/row.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,10 @@ Ui::Child rowContent(Opt<Ui::Child> leading, String title, Opt<String> subtitle,
3333
auto t = subtitle
3434
? Ui::vflow(
3535
8,
36-
Ui::labelLarge(title),
37-
Ui::labelMedium(*subtitle)
36+
Ui::labelMedium(title),
37+
Ui::labelSmall(*subtitle)
3838
)
39-
: Ui::labelLarge(title);
39+
: Ui::labelMedium(title);
4040

4141
auto trail = trailing
4242
? *trailing |

src/libs/karm-math/path.cpp

+14
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,20 @@
55

66
namespace Karm::Math {
77

8+
Math::Rectf Path::bound() {
9+
if (isEmpty(_verts))
10+
return {};
11+
12+
if (_bound)
13+
return *_bound;
14+
15+
Math::Rectf rect = {_verts[0], 0};
16+
for (auto &p : _verts)
17+
rect = rect.mergeWith(p);
18+
_bound = rect;
19+
return rect;
20+
}
21+
822
// MARK: Flattening ------------------------------------------------------------
923

1024
void Path::_flattenClose() {

src/libs/karm-math/path.h

+4
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,10 @@ struct Path {
9898
});
9999
}
100100

101+
Opt<Math::Rectf> _bound;
102+
103+
Math::Rectf bound();
104+
101105
// MARK: Flattening --------------------------------------------------------
102106

103107
void _flattenClose();

0 commit comments

Comments
 (0)