diff --git a/src/libs/karm-scene/base.h b/src/libs/karm-scene/base.h index 1754a0b..29451dd 100644 --- a/src/libs/karm-scene/base.h +++ b/src/libs/karm-scene/base.h @@ -2,10 +2,14 @@ #include #include -#include +#include namespace Karm::Scene { +struct PaintOptions { + bool showBackgroundGraphics = true; +}; + struct Node { isize zIndex = 0; @@ -17,9 +21,9 @@ struct Node { /// The bounding rectangle of the node virtual Math::Rectf bound() { return {}; } - virtual void paint(Gfx::Canvas &, Math::Rectf = Math::Rectf::MAX) {} + virtual void paint(Gfx::Canvas &, Math::Rectf = Math::Rectf::MAX, PaintOptions = {}) {} - virtual void print(Print::Printer &) {} + virtual void print(Print::Printer &, PaintOptions = {.showBackgroundGraphics = false}) {} virtual void repr(Io::Emit &e) const { e("(node z:{})", zIndex); diff --git a/src/libs/karm-scene/box.h b/src/libs/karm-scene/box.h index 1b7aff3..9168249 100644 --- a/src/libs/karm-scene/box.h +++ b/src/libs/karm-scene/box.h @@ -19,15 +19,17 @@ struct Box : public Node { return _bound; } - void paint(Gfx::Canvas &ctx, Math::Rectf r) override { + void paint(Gfx::Canvas &ctx, Math::Rectf r, PaintOptions o) override { if (not r.colide(bound())) return; - for (auto &background : _backgrounds) { - ctx.beginPath(); - auto radii = _borders.radii.reduceOverlap(_bound.size()); - ctx.rect(_bound, radii); - ctx.fill(background); + if (o.showBackgroundGraphics) { + for (auto &background : _backgrounds) { + ctx.beginPath(); + auto radii = _borders.radii.reduceOverlap(_bound.size()); + ctx.rect(_bound, radii); + ctx.fill(background); + } } _borders.paint(ctx, _bound); diff --git a/src/libs/karm-scene/image.h b/src/libs/karm-scene/image.h index bb1aedc..f56e4b0 100644 --- a/src/libs/karm-scene/image.h +++ b/src/libs/karm-scene/image.h @@ -18,7 +18,7 @@ struct Image : public Node { return _bound; } - void paint(Gfx::Canvas &ctx, Math::Rectf r) override { + void paint(Gfx::Canvas &ctx, Math::Rectf r, PaintOptions) override { if (not r.colide(bound())) return; diff --git a/src/libs/karm-scene/page.h b/src/libs/karm-scene/page.h index 79a01cb..b94eb47 100644 --- a/src/libs/karm-scene/page.h +++ b/src/libs/karm-scene/page.h @@ -5,17 +5,18 @@ namespace Karm::Scene { struct Page : public Stack { - Math::Vec2i _size; + Print::PaperStock _paper; - Page(Math::Vec2i size, Opt transform = NONE) : Stack(transform), _size(size) {} + Page(Print::PaperStock paper, Opt transform = NONE) + : Stack(transform), _paper(paper) {} - void print(Print::Printer &doc) override { - Stack::print(doc); - paint(doc.beginPage(), _size.cast()); + void print(Print::Printer &doc, PaintOptions o) override { + Stack::print(doc, o); + paint(doc.beginPage(_paper), _paper.size().cast(), o); } Math::Rectf bound() override { - return _size.cast(); + return _paper.size().cast(); } void repr(Io::Emit &e) const override { diff --git a/src/libs/karm-scene/shape.h b/src/libs/karm-scene/shape.h index b3b7204..6263177 100644 --- a/src/libs/karm-scene/shape.h +++ b/src/libs/karm-scene/shape.h @@ -19,7 +19,7 @@ struct Shape : public Node { return _path.bound(); } - void paint(Gfx::Canvas &g, Math::Rectf r) override { + void paint(Gfx::Canvas &g, Math::Rectf r, PaintOptions) override { if (not bound().colide(r)) return; diff --git a/src/libs/karm-scene/stack.h b/src/libs/karm-scene/stack.h index 84b0acd..829c559 100644 --- a/src/libs/karm-scene/stack.h +++ b/src/libs/karm-scene/stack.h @@ -30,7 +30,7 @@ struct Stack : public Node { return rect; } - void paint(Gfx::Canvas &g, Math::Rectf r) override { + void paint(Gfx::Canvas &g, Math::Rectf r, PaintOptions o) override { if (not bound().colide(r)) return; @@ -40,15 +40,15 @@ struct Stack : public Node { } for (auto &child : _children) - child->paint(g, r); + child->paint(g, r, o); if (_transform) g.pop(); } - void print(Print::Printer &p) override { + void print(Print::Printer &p, PaintOptions o) override { for (auto &child : _children) - child->print(p); + child->print(p, o); } void repr(Io::Emit &e) const override { diff --git a/src/libs/karm-scene/text.h b/src/libs/karm-scene/text.h index 2401cc9..b8822a7 100644 --- a/src/libs/karm-scene/text.h +++ b/src/libs/karm-scene/text.h @@ -17,7 +17,7 @@ struct Text : public Node { return {_origin, _prose->size()}; } - void paint(Gfx::Canvas &g, Math::Rectf r) override { + void paint(Gfx::Canvas &g, Math::Rectf r, PaintOptions) override { if (not bound().colide(r)) return; diff --git a/src/libs/karm-ui/layout.cpp b/src/libs/karm-ui/layout.cpp index daf2124..0e4122c 100644 --- a/src/libs/karm-ui/layout.cpp +++ b/src/libs/karm-ui/layout.cpp @@ -233,6 +233,12 @@ struct Sizing : public ProxyNode { return _rect; } + void reconcile(Sizing &o) override { + _min = o._min; + _max = o._max; + ProxyNode::reconcile(o); + } + void layout(Math::Recti bound) override { _rect = bound; child().layout(bound); diff --git a/src/libs/karm-ui/view.cpp b/src/libs/karm-ui/view.cpp index 0debbd4..c043f7c 100644 --- a/src/libs/karm-ui/view.cpp +++ b/src/libs/karm-ui/view.cpp @@ -367,12 +367,14 @@ Child canvas(OnPaint onPaint) { struct SceneCanvas : public View { Strong _scene; + Scene::PaintOptions _options; - SceneCanvas(Strong scene) - : _scene(std::move(scene)) {} + SceneCanvas(Strong scene, Scene::PaintOptions options) + : _scene(std::move(scene)), _options(options) {} void reconcile(SceneCanvas &o) override { _scene = o._scene; + _options = o._options; View::reconcile(o); } @@ -388,7 +390,7 @@ struct SceneCanvas : public View { auto rectInScene = trans.inverse().apply(rect.cast()).bound(); - _scene->paint(g, Math::Rectf::MAX); + _scene->paint(g, Math::Rectf::MAX, _options); g.pop(); } @@ -402,8 +404,8 @@ struct SceneCanvas : public View { } }; -Child canvas(Strong child) { - return makeStrong(std::move(child)); +Child canvas(Strong child, Scene::PaintOptions options) { + return makeStrong(std::move(child), options); } // MARK: Filter ---------------------------------------------------------------- diff --git a/src/libs/karm-ui/view.h b/src/libs/karm-ui/view.h index f4beed3..b816af8 100644 --- a/src/libs/karm-ui/view.h +++ b/src/libs/karm-ui/view.h @@ -121,7 +121,7 @@ using OnPaint = Func; Child canvas(OnPaint onPaint); -Child canvas(Strong child); +Child canvas(Strong child, Scene::PaintOptions options = {}); // MARK: Blur ------------------------------------------------------------------