From e068ad9e28b14bfb500d49aaa71dc053b470d7c5 Mon Sep 17 00:00:00 2001 From: Andrew Belt Date: Wed, 6 Jun 2018 11:15:57 -0400 Subject: [PATCH] Add example icon to toolbar --- include/ui.hpp | 6 +++++ res/icons/LICENSE.md | 2 ++ res/icons/file.svg | 56 +++++++++++++++++++++++++++++++++++++++++++ src/app/Toolbar.cpp | 14 +++++++++++ src/ui/Button.cpp | 1 + src/ui/IconButton.cpp | 19 +++++++++++++++ 6 files changed, 98 insertions(+) create mode 100644 res/icons/LICENSE.md create mode 100644 res/icons/file.svg create mode 100644 src/ui/IconButton.cpp diff --git a/include/ui.hpp b/include/ui.hpp index 57e6fa47..4ddd5a19 100644 --- a/include/ui.hpp +++ b/include/ui.hpp @@ -154,6 +154,12 @@ struct Button : OpaqueWidget { void onDragDrop(EventDragDrop &e) override; }; +struct IconButton : Button { + SVGWidget *sw; + IconButton(); + void setSVG(std::shared_ptr svg); +}; + struct ChoiceButton : Button { void draw(NVGcontext *vg) override; }; diff --git a/res/icons/LICENSE.md b/res/icons/LICENSE.md new file mode 100644 index 00000000..cbff1d61 --- /dev/null +++ b/res/icons/LICENSE.md @@ -0,0 +1,2 @@ +SVG icons in this directory are licensed under the CC BY 4.0 License by Font Awesome. +https://fontawesome.com/license diff --git a/res/icons/file.svg b/res/icons/file.svg new file mode 100644 index 00000000..a369c472 --- /dev/null +++ b/res/icons/file.svg @@ -0,0 +1,56 @@ + + + + + + image/svg+xml + + + + + + + + + diff --git a/src/app/Toolbar.cpp b/src/app/Toolbar.cpp index b1d5a9a1..7da3be57 100644 --- a/src/app/Toolbar.cpp +++ b/src/app/Toolbar.cpp @@ -1,11 +1,22 @@ #include "app.hpp" #include "window.hpp" #include "engine.hpp" +#include "asset.hpp" namespace rack { +struct NewButton : IconButton { + NewButton() { + setSVG(SVG::load(assetGlobal("res/icons/file.svg"))); + } + void onAction(EventAction &e) override { + gRackWidget->reset(); + } +}; + + struct NewItem : MenuItem { void onAction(EventAction &e) override { gRackWidget->reset(); @@ -114,6 +125,9 @@ Toolbar::Toolbar() { layout->spacing = 5; addChild(layout); + NewButton *newButton = new NewButton(); + layout->addChild(newButton); + ChoiceButton *fileChoice = new FileChoice(); fileChoice->box.size.x = 100; fileChoice->text = "File"; diff --git a/src/ui/Button.cpp b/src/ui/Button.cpp index 4491c44b..b39457ba 100644 --- a/src/ui/Button.cpp +++ b/src/ui/Button.cpp @@ -5,6 +5,7 @@ namespace rack { void Button::draw(NVGcontext *vg) { bndToolButton(vg, 0.0, 0.0, box.size.x, box.size.y, BND_CORNER_NONE, state, -1, text.c_str()); + Widget::draw(vg); } void Button::onMouseEnter(EventMouseEnter &e) { diff --git a/src/ui/IconButton.cpp b/src/ui/IconButton.cpp new file mode 100644 index 00000000..31fa427e --- /dev/null +++ b/src/ui/IconButton.cpp @@ -0,0 +1,19 @@ +#include "ui.hpp" + + +namespace rack { + + +IconButton::IconButton() { + box.size.x = BND_WIDGET_HEIGHT; + sw = new SVGWidget(); + sw->box.pos = Vec(2.75, 1.75); + addChild(sw); +} + +void IconButton::setSVG(std::shared_ptr svg) { + sw->setSVG(svg); +} + + +} // namespace rack