UI: Implement initial document stack logic

This commit is contained in:
Luke Street
2026-04-30 17:21:55 -06:00
parent 1c9e1c0a66
commit 62edb3abc6
9 changed files with 64 additions and 61 deletions
+18 -6
View File
@@ -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();