Format like smack-a-brother, and write comments as sentences

Four-space indents, braces on their own lines, and one-statement bodies without braces.
Semicolons in comments became full stops.
Designated initializers may leave fields out without a warning.
This commit is contained in:
shweet committed 2026-11-22 17:30:03 -05:00
1 parent 40f6b554b5
commit 7afdf709c3
176 files changed
+20500 -19048

No files matched your search

+89 -91
View File
@@ -4,110 +4,108 @@
#include "path.h"
constexpr int LIBRARY_CARD_LINES = 2;
constexpr int LIBRARY_CARD_LINES = 2;
static auto& libraries_get(Model& model) { return model.content.libraries; }
static auto& libraries_get(Model& model)
{
return model.content.libraries;
}
void libraries_update(Panel& panel)
{
void libraries_update(Panel& panel)
{
auto& [manager, settings, resources, dialog, clipboard, document, state] = panel;
auto& libraries = document.model.content.libraries;
auto selection = document.selected_ids_get(SelectionKind::LIBRARIES);
if (dialog.is_selected(Dialog::LIBRARY_OPEN))
{
command_push(panel,
[&state, paths = dialog.paths](Document& document)
{
document.libraries_add(paths);
state.newId = document.focused_id_get(SelectionKind::LIBRARIES);
});
dialog.reset();
command_push(panel, [&state, paths = dialog.paths](Document& document) {
document.libraries_add(paths);
state.newId = document.focused_id_get(SelectionKind::LIBRARIES);
});
dialog.reset();
}
if (ImGui::Begin(localize.get(LABEL_LIBRARIES_WINDOW), &settings.windowIsLibraries))
{
auto isOne = [selection]() { return selection.size() == 1; };
auto loaded_get = [&](int id) { return document.library_get(document.model, id); };
// Opens the library as its own tab, or switches to it when it already is one.
auto open = [&](int id)
{
manager.command_push({.runManager = [path = document.library_path_get(id)](Manager& manager)
{
if (auto index = manager.path_index_get(path); index != -1)
return manager.tab_select(index);
manager.open(path);
}});
};
auto isOne = [selection]() {
return selection.size() == 1;
};
auto loaded_get = [&](int id) {
return document.library_get(document.model, id);
};
// Opens the library as its own tab, or switches to it when it already is one.
auto open = [&](int id) {
manager.command_push({.runManager = [path = document.library_path_get(id)](Manager& manager) {
if (auto index = manager.path_index_get(path); index != -1)
return manager.tab_select(index);
manager.open(path);
}});
};
Actions actions = {};
actions.add(ACTION_OPEN, isOne, [&]() { open(*selection.begin()); }, TOOLTIP_LIBRARY_OPEN);
actions.add(ACTION_OPEN_DIRECTORY, isOne,
[&]() { directory_open(dialog, document, item_get(libraries, *selection.begin())->path); });
actions.add(ACTION_ADD, {}, [&]() { dialog.file_open(Dialog::LIBRARY_OPEN, true); }, TOOLTIP_LIBRARY_ADD);
content_remove_action_add(actions, panel, ElementType::LIBRARY, SelectionKind::LIBRARIES);
actions.add(
ACTION_RELOAD, [selection]() { return !selection.empty(); },
[&]()
{
command_push(panel,
[selection](Document& document)
{
for (auto id : selection)
if (auto library = item_get(document.model.content.libraries, id))
{
document.library_reload(id);
toast_log(Level::INFO, TOAST_RELOAD_LIBRARY, id, path_to_utf8(library->path));
}
});
},
TOOLTIP_RELOAD_LIBRARIES);
items_clipboard_actions_add<Library>(actions, panel, SelectionKind::LIBRARIES, EDIT_PASTE_LIBRARIES,
TOAST_DESERIALIZE_LIBRARIES_FAILED, libraries_get);
Actions actions = {};
actions.add(ACTION_OPEN, isOne, [&]() { open(*selection.begin()); }, TOOLTIP_LIBRARY_OPEN);
actions.add(ACTION_OPEN_DIRECTORY, isOne,
[&]() { directory_open(dialog, document, item_get(libraries, *selection.begin())->path); });
actions.add(ACTION_ADD, {}, [&]() { dialog.file_open(Dialog::LIBRARY_OPEN, true); }, TOOLTIP_LIBRARY_ADD);
content_remove_action_add(actions, panel, ElementType::LIBRARY, SelectionKind::LIBRARIES);
actions.add(
ACTION_RELOAD, [selection]() { return !selection.empty(); },
[&]() {
command_push(panel, [selection](Document& document) {
for (auto id : selection)
if (auto library = item_get(document.model.content.libraries, id))
{
document.library_reload(id);
toast_log(Level::INFO, TOAST_RELOAD_LIBRARY, id, path_to_utf8(library->path));
}
});
},
TOOLTIP_RELOAD_LIBRARIES);
items_clipboard_actions_add<Library>(actions, panel, SelectionKind::LIBRARIES, EDIT_PASTE_LIBRARIES,
TOAST_DESERIALIZE_LIBRARIES_FAILED, libraries_get);
ListRows rows{
.label_get =
[&](int id)
{
auto pathString = path_to_utf8(item_get(libraries, id)->path);
return std::vformat(localize.get(FORMAT_SOUND), std::make_format_args(id, pathString));
},
.tooltip_draw =
[&](int id)
{
auto loaded = loaded_get(id);
tooltip_name_draw(resources, path_to_utf8(item_get(libraries, id)->path));
ImGui::Text("%s: %d", localize.get(BASIC_ID), id);
if (loaded && loaded->model.isValid)
{
auto animations = loaded->model.animations_get();
auto count = animations.size();
ImGui::SeparatorText(
std::vformat(localize.get(FORMAT_LIBRARY_ANIMATIONS), std::make_format_args(count)).c_str());
for (auto [index, animation] : animations)
ImGui::BulletText("%s", animation->name.c_str());
ImGui::Separator();
ImGui::TextUnformatted(localize.get(TOOLTIP_LIBRARY_OPEN));
}
else
{
ImGui::Spacing();
ImGui::TextWrapped("%s", localize.get(TOOLTIP_LIBRARY_INVALID));
}
},
.image_get =
[&](int id)
{
auto loaded = loaded_get(id);
auto isValid = loaded && loaded->model.isValid;
auto& texture = resources.icons[isValid ? ICON_ANIMATION : ICON_NONE];
return CardImage{.texture = &texture, .size = glm::vec2(texture.size), .isValid = isValid};
},
.activate = open,
.cardLines = LIBRARY_CARD_LINES};
list_panel_draw(
panel, actions, {{ACTION_ADD, ACTION_REMOVE, ACTION_RELOAD, ACTION_OPEN}},
[&]() { content_list_draw(panel, SelectionKind::LIBRARIES, item_ids_get(libraries), rows); }, true);
ListRows rows{
.label_get =
[&](int id) {
auto pathString = path_to_utf8(item_get(libraries, id)->path);
return std::vformat(localize.get(FORMAT_SOUND), std::make_format_args(id, pathString));
},
.tooltip_draw =
[&](int id) {
auto loaded = loaded_get(id);
tooltip_name_draw(resources, path_to_utf8(item_get(libraries, id)->path));
ImGui::Text("%s: %d", localize.get(BASIC_ID), id);
if (loaded && loaded->model.isValid)
{
auto animations = loaded->model.animations_get();
auto count = animations.size();
ImGui::SeparatorText(
std::vformat(localize.get(FORMAT_LIBRARY_ANIMATIONS), std::make_format_args(count))
.c_str());
for (auto [index, animation] : animations)
ImGui::BulletText("%s", animation->name.c_str());
ImGui::Separator();
ImGui::TextUnformatted(localize.get(TOOLTIP_LIBRARY_OPEN));
}
else
{
ImGui::Spacing();
ImGui::TextWrapped("%s", localize.get(TOOLTIP_LIBRARY_INVALID));
}
},
.image_get =
[&](int id) {
auto loaded = loaded_get(id);
auto isValid = loaded && loaded->model.isValid;
auto& texture = resources.icons[isValid ? ICON_ANIMATION : ICON_NONE];
return CardImage{.texture = &texture, .size = glm::vec2(texture.size), .isValid = isValid};
},
.activate = open,
.cardLines = LIBRARY_CARD_LINES};
list_panel_draw(
panel, actions, {{ACTION_ADD, ACTION_REMOVE, ACTION_RELOAD, ACTION_OPEN}},
[&]() { content_list_draw(panel, SelectionKind::LIBRARIES, item_ids_get(libraries), rows); }, true);
}
ImGui::End();
}
}