Files
Editor2D/include/App/LayerView.hpp

75 lines
1.7 KiB
C++

#pragma once
#include <JUI/Widgets/Window.hpp>
#include <JUI/Widgets/Button.hpp>
#include <JUI/Widgets/ScrollingRect.hpp>
#include <JUI/Widgets/ListLayout.hpp>
#include <JUI/Widgets/Checkbox.hpp>
#include <Data/Level.hpp>
using namespace JUI::UDimLiterals;
class LayerView : public JUI::Window
{
public:
Event<std::string, bool> LayerVisibilityToggled;
Event<std::string> ActiveLayerSelected;
LayerView() : JUI::Window()
{
this->Title("Layers");
Name("LayerView");
scroller = new JUI::ScrollingRect(this->Content());
scroller->Size({100_percent, 100_percent});
layout = new JUI::VerticalListLayout(this->Content());
}
explicit LayerView(Widget* parent) : LayerView()
{
Parent(parent);
}
void UpdateComponents(const Level* level)
{
for (auto entry : entry_elements) {
entry->Parent(nullptr);
delete entry;
}
entry_elements.clear();
for (auto layer : level->layers)
{
auto* rect = new JUI::Rect(layout);
rect->Size({100_percent, 20_px});
auto* vis_chk = new JUI::Checkbox(rect);
vis_chk->Size({20_px, 20_px});
auto* label = new JUI::TextButton(rect);
label->Name("Label");
label->Position({20_px, 0_px});
label->Size({100_percent-20_px, 20_px});
label->Content(layer->name);
label->TextColor(Colors::Black);
label->OnReleaseEvent += [this, label, layer] (auto a, auto b, auto c) mutable {
ActiveLayerSelected.Invoke(layer->name);
label->BaseBGColor(Colors::Gray);
};
vis_chk->OnReleaseEvent += [this, layer](auto a, auto b, auto c) mutable {
LayerVisibilityToggled.Invoke(layer->name, !layer->visible);
};
entry_elements.push_back(rect);
}
}
std::vector<Widget*> entry_elements;
JUI::ScrollingRect* scroller = nullptr;
JUI::VerticalListLayout* layout = nullptr;
};