Stage 8a: panels as plain functions; content selection on the uid Selection
- New panel kit (imgui/window/panel.*): list/card drawing with multi-select, rename, arrow keys, drag hooks and tooltips; a list panel helper for the context menu, shortcuts and footer; panels build their Actions inline. - Layers, nulls, events, sounds, spritesheets, regions, shaders and animations are plain functions over a small persistent state struct. - Content items are selected by uid in the shared Selection (one kind per content type, plus a focus per kind); regions are those of the focused spritesheet. Selection survives undo, paste and removal like the timeline's. - Combo labels are computed when drawn (Document::choices_get). - Deletes the Window callback framework, WINDOW_FLAGS, Storage and the per-window selection snapshot fields. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
e50d76c784
commit
d08f59d7ba
37 files changed
+2355
-2578
No files matched your search
+64
-1
@@ -39,12 +39,75 @@ namespace anm2ed
|
||||
selection.focus = model.handle_get(reference);
|
||||
}
|
||||
|
||||
// (id, uid) of every content item a kind selects from.
|
||||
std::vector<std::pair<int, std::uint64_t>> content_keys_get(const Selection& selection, const model::Model& model,
|
||||
SelectionKind kind)
|
||||
{
|
||||
std::vector<std::pair<int, std::uint64_t>> keys{};
|
||||
auto add = [&](const auto& items)
|
||||
{
|
||||
for (const auto& item : items)
|
||||
keys.emplace_back(item.id, item.uid);
|
||||
};
|
||||
auto& content = model.content;
|
||||
if (kind == SelectionKind::SPRITESHEETS) add(content.spritesheets);
|
||||
if (kind == SelectionKind::SHADERS) add(content.shaders);
|
||||
if (kind == SelectionKind::LAYERS) add(content.layers);
|
||||
if (kind == SelectionKind::NULLS) add(content.nulls);
|
||||
if (kind == SelectionKind::EVENTS) add(content.events);
|
||||
if (kind == SelectionKind::SOUNDS) add(content.sounds);
|
||||
if (kind == SelectionKind::REGIONS)
|
||||
if (auto spritesheet = model::item_get(content.spritesheets,
|
||||
selection_focus_id_get(selection, model, SelectionKind::SPRITESHEETS)))
|
||||
add(spritesheet->regions);
|
||||
return keys;
|
||||
}
|
||||
|
||||
std::set<int> selection_ids_get(const Selection& selection, const model::Model& model, SelectionKind kind)
|
||||
{
|
||||
std::set<int> ids{};
|
||||
auto uids = selection.uids.find(kind);
|
||||
if (uids == selection.uids.end()) return ids;
|
||||
for (auto [id, uid] : content_keys_get(selection, model, kind))
|
||||
if (uids->second.contains(uid)) ids.insert(id);
|
||||
return ids;
|
||||
}
|
||||
|
||||
void selection_ids_set(Selection& selection, const model::Model& model, SelectionKind kind, const std::set<int>& ids)
|
||||
{
|
||||
auto& uids = selection.uids[kind];
|
||||
uids.clear();
|
||||
for (auto [id, uid] : content_keys_get(selection, model, kind))
|
||||
if (ids.contains(id)) uids.insert(uid);
|
||||
}
|
||||
|
||||
int selection_focus_id_get(const Selection& selection, const model::Model& model, SelectionKind kind)
|
||||
{
|
||||
auto focus = selection.focuses.find(kind);
|
||||
if (focus == selection.focuses.end()) return -1;
|
||||
for (auto [id, uid] : content_keys_get(selection, model, kind))
|
||||
if (uid == focus->second) return id;
|
||||
return -1;
|
||||
}
|
||||
|
||||
void selection_focus_id_set(Selection& selection, const model::Model& model, SelectionKind kind, int id)
|
||||
{
|
||||
selection.focuses.erase(kind);
|
||||
for (auto [itemId, uid] : content_keys_get(selection, model, kind))
|
||||
if (itemId == id)
|
||||
{
|
||||
selection.focuses[kind] = uid;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// After an edit: drops uids that no longer exist, and moves a focus whose element was removed to its nearest
|
||||
// survivor (a frame at the same index of its track, the animation's root track, or the nearest animation).
|
||||
void selection_follow(Selection& selection, const model::Model& model, const model::UidIndex& index, Reference before)
|
||||
{
|
||||
for (auto& [kind, uids] : selection.uids)
|
||||
std::erase_if(uids, [&](std::uint64_t uid) { return !index.contains(uid); });
|
||||
if (kind < SelectionKind::SPRITESHEETS)
|
||||
std::erase_if(uids, [&](std::uint64_t uid) { return !index.contains(uid); });
|
||||
|
||||
auto [animationUid, itemUid, frameUid] = selection.focus;
|
||||
auto is_removed = [&](std::uint64_t uid) { return uid && !index.contains(uid); };
|
||||
|
||||
Reference in new issue
Block a user