summaryrefslogtreecommitdiff
path: root/ui/toolbar.cpp
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2021-12-22 12:16:38 +0000
committerDan Goodliffe <dan@randomdan.homeip.net>2021-12-22 12:16:38 +0000
commite806d41c8703ddc4bcaf2186d0c1701bd1e1ada3 (patch)
tree1612baf22456c0b5a1bef82980177afb34b2756c /ui/toolbar.cpp
parentWindow handles UIComponent rendering (diff)
downloadilt-e806d41c8703ddc4bcaf2186d0c1701bd1e1ada3.tar.bz2
ilt-e806d41c8703ddc4bcaf2186d0c1701bd1e1ada3.tar.xz
ilt-e806d41c8703ddc4bcaf2186d0c1701bd1e1ada3.zip
Initial commit with some basic UI
Diffstat (limited to 'ui/toolbar.cpp')
-rw-r--r--ui/toolbar.cpp33
1 files changed, 33 insertions, 0 deletions
diff --git a/ui/toolbar.cpp b/ui/toolbar.cpp
new file mode 100644
index 0000000..c8febce
--- /dev/null
+++ b/ui/toolbar.cpp
@@ -0,0 +1,33 @@
+#include "toolbar.h"
+#include "ui/iconButton.h"
+#include "ui/uiComponent.h"
+#include "uiComponentPlacer.h"
+#include <SDL2/SDL.h>
+#include <glm/glm.hpp>
+
+Toolbar::Toolbar(const std::initializer_list<InitInfo> & initInfo) : UIComponent {{{}, {}}}
+{
+ UIComponentPlacer placer {{10, 10}, 5, 1};
+ for (const auto & ii : initInfo) {
+ icons.create(ii.first, placer.next(ICON_SIZE), ii.second);
+ }
+ this->position.size = placer.getLimit();
+}
+
+void
+Toolbar::render(const UIShader & uiShader, const Position & parentPos) const
+{
+ const auto absPos = this->position + parentPos;
+ icons.apply(&UIComponent::render, uiShader, absPos);
+}
+
+bool
+Toolbar::handleInput(const SDL_Event & e, const Position & parentPos)
+{
+ const auto absPos = this->position + parentPos;
+ if (absPos & e.button) {
+ icons.applyOne(&UIComponent::handleInput, e, absPos);
+ return true;
+ }
+ return false;
+}