-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
karm-scene: Moved page to karm-scene + Added viewbox and transform.
- Loading branch information
1 parent
5c04132
commit 2743e7f
Showing
20 changed files
with
219 additions
and
80 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
#include <karm-ui/focus.h> | ||
#include <karm-ui/layout.h> | ||
#include <mdi/minus.h> | ||
#include <mdi/plus.h> | ||
|
||
#include "number.h" | ||
|
||
namespace Karm::Kira { | ||
|
||
Ui::Child number(f64 value, Ui::OnChange<f64> onChange, f64 step) { | ||
return Ui::hflow( | ||
Ui::button( | ||
[onChange, value, step](auto &n) { | ||
onChange(n, value - step); | ||
}, | ||
Ui::ButtonStyle::subtle(), | ||
Mdi::MINUS | ||
), | ||
Ui::labelMedium("{}", value) | Ui::insets({0, 4}) | Ui::center(), | ||
Ui::button( | ||
[onChange, value, step](auto &n) { | ||
onChange(n, value + step); | ||
}, | ||
Ui::ButtonStyle::subtle(), | ||
Mdi::PLUS | ||
) | ||
) | | ||
Ui::box({ | ||
.borderRadii = 4, | ||
.borderWidth = 1, | ||
.borderFill = Ui::GRAY800, | ||
}) | | ||
Ui::focusable(); | ||
} | ||
|
||
} // namespace Karm::Kira |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#pragma once | ||
|
||
#include <karm-ui/input.h> | ||
|
||
#include "_prelude.h" | ||
|
||
namespace Karm::Kira { | ||
|
||
Ui::Child number(f64 value, Ui::OnChange<f64> onChange, f64 step = 1); | ||
|
||
} // namespace Karm::Kira |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
#pragma once | ||
|
||
#include <karm-scene/base.h> | ||
#include <karm-scene/stack.h> | ||
#include <karm-scene/viewbox.h> | ||
|
||
#include "paper.h" | ||
#include "printer.h" | ||
|
||
namespace Karm::Print { | ||
|
||
struct Page { | ||
PaperStock _paper; | ||
Strong<Scene::Node> _content; | ||
|
||
Page(PaperStock paper, Opt<Strong<Scene::Node>> content = NONE) | ||
: _paper(paper), _content(content ? content.take() : makeStrong<Scene::Stack>()) {} | ||
|
||
Strong<Scene::Node> content() const { | ||
return makeStrong<Scene::Viewbox>(_paper.size(), _content); | ||
} | ||
|
||
void print(Print::Printer &doc, Scene::PaintOptions o = {.showBackgroundGraphics = false}) { | ||
auto &canvas = doc.beginPage(_paper); | ||
content()->paint(canvas, _paper.size().cast<f64>(), o); | ||
} | ||
|
||
void repr(Io::Emit &e) const { | ||
e("(page paper:{} root:{})", _paper, content()); | ||
} | ||
}; | ||
|
||
} // namespace Karm::Print |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,6 @@ | |
"type": "lib", | ||
"description": "2D scene graph library", | ||
"requires": [ | ||
"karm-gfx", | ||
"karm-print" | ||
"karm-gfx" | ||
] | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
#pragma once | ||
|
||
#include "base.h" | ||
|
||
namespace Karm::Scene { | ||
|
||
struct Transform : public Node { | ||
Strong<Node> _content; | ||
Math::Trans2f _transform; | ||
|
||
Transform(Strong<Node> content, Math::Trans2f transform) | ||
: _content(content), _transform(transform) {} | ||
|
||
void prepare() override { | ||
_content->prepare(); | ||
} | ||
|
||
Math::Rectf bound() override { | ||
return _transform | ||
.inverse() | ||
.apply(_content->bound()) | ||
.bound(); | ||
} | ||
|
||
void paint(Gfx::Canvas &g, Math::Rectf r, PaintOptions o) override { | ||
if (not bound().colide(r)) | ||
return; | ||
|
||
g.push(); | ||
g.transform(_transform); | ||
_content->paint(g, r, o); | ||
g.pop(); | ||
} | ||
|
||
void repr(Io::Emit &e) const override { | ||
e("(transform transform:{} content:{})", _transform, _content); | ||
} | ||
}; | ||
|
||
} // namespace Karm::Scene |
Oops, something went wrong.