mirror of
https://github.com/TwilitRealm/dusklight
synced 2026-08-04 08:48:45 -04:00
UI: Implement initial document stack logic
This commit is contained in:
+18
-6
@@ -47,20 +47,32 @@ void handle_event(const SDL_Event& event) noexcept {
|
||||
// TODO
|
||||
}
|
||||
|
||||
Document& add_document(std::unique_ptr<Document> doc) noexcept {
|
||||
Document& push_document(std::unique_ptr<Document> doc, bool show) noexcept {
|
||||
if (auto* doc = top_document()) {
|
||||
doc->hide();
|
||||
}
|
||||
Document& ret = *doc;
|
||||
sDocuments.push_back(std::move(doc));
|
||||
if (show) {
|
||||
ret.show();
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
void remove_document(Document& doc) noexcept {
|
||||
const auto it = std::find_if(sDocuments.begin(), sDocuments.end(),
|
||||
[&doc](const std::unique_ptr<Document>& current) { return current.get() == &doc; });
|
||||
if (it != sDocuments.end()) {
|
||||
sDocuments.erase(it);
|
||||
void pop_document() noexcept {
|
||||
sDocuments.pop_back();
|
||||
if (auto* doc = top_document()) {
|
||||
doc->show();
|
||||
}
|
||||
}
|
||||
|
||||
Document* top_document() noexcept {
|
||||
if (sDocuments.empty()) {
|
||||
return nullptr;
|
||||
}
|
||||
return sDocuments.back().get();
|
||||
}
|
||||
|
||||
void update() noexcept {
|
||||
for (const auto& doc : sDocuments) {
|
||||
doc->update();
|
||||
|
||||
Reference in New Issue
Block a user