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

+120 -120
View File
@@ -19,25 +19,25 @@
#include "ui/change_all_frame_properties.h"
// Panels are plain functions: each draws from the document and its selection, and queues edits as commands.
inline constexpr auto DRAG_DROP_SOURCE_FLAGS =
ImGuiDragDropFlags_SourceNoPreviewTooltip | ImGuiDragDropFlags_SourceNoHoldToOpenOthers;
inline constexpr ImVec4 CARD_TINT_INVALID = ImVec4(1.0f, 0.25f, 0.25f, 1.0f);
inline constexpr ImVec4 CARD_TINT_VALID = ImVec4(1.0f, 1.0f, 1.0f, 1.0f);
inline constexpr auto DRAG_DROP_SOURCE_FLAGS =
ImGuiDragDropFlags_SourceNoPreviewTooltip | ImGuiDragDropFlags_SourceNoHoldToOpenOthers;
inline constexpr ImVec4 CARD_TINT_INVALID = ImVec4(1.0f, 0.25f, 0.25f, 1.0f);
inline constexpr ImVec4 CARD_TINT_VALID = ImVec4(1.0f, 1.0f, 1.0f, 1.0f);
using Footer = std::vector<std::vector<ActionType>>;
using Footer = std::vector<std::vector<ActionType>>;
struct CardImage
{
struct CardImage
{
const Image* texture = nullptr;
glm::vec2 size{};
glm::vec2 uvMin{};
glm::vec2 uvMax{1.0f};
bool isValid = false;
};
};
// What a list panel remembers between frames.
struct PanelState
{
// What a list panel remembers between frames.
struct PanelState
{
int newId = -1;
int scrollId = -1;
int renameId = -1;
@@ -52,17 +52,17 @@
// A removal waiting on its confirmation, since what it removes is in use.
struct Removal
{
ElementType type = {};
SelectionKind kind = {};
std::set<int> ids;
int spritesheetId = -1;
std::vector<std::string> lines;
ElementType type = {};
SelectionKind kind = {};
std::set<int> ids;
int spritesheetId = -1;
std::vector<std::string> lines;
} removal{};
};
};
// Everything a panel draws with, for one frame. Commands get the document again when they run.
struct Panel
{
// Everything a panel draws with, for one frame. Commands get the document again when they run.
struct Panel
{
Manager& manager;
Settings& settings;
Resources& resources;
@@ -70,12 +70,12 @@
Clipboard& clipboard;
Document& document;
PanelState& state;
};
};
// How a list shows its keys; only `label_get` is required. With `image_get` the rows are cards; `children_draw` draws
// under a key.
struct ListRows
{
// How a list shows its keys. Only `label_get` is required. With `image_get` the rows are cards. `children_draw` draws
// under a key.
struct ListRows
{
std::function<std::string(int)> label_get{};
std::function<std::string(int)> name_get{};
std::function<void(int, const std::string&)> rename{};
@@ -88,34 +88,34 @@
std::function<bool(int, int)> drag_drop_update{};
int cardLines = 0;
bool isFocusItalic = false;
};
};
enum class PopupButton
{
enum class PopupButton
{
NONE,
CONFIRM,
CANCEL
};
};
bool is_drag_drop_active();
void command_push(const Panel&, std::function<void(Document&)>);
bool row_draw(Panel&, std::set<int>&, int&, const ListRows&, int, int, int);
void list_draw(Panel&, const std::vector<int>&, std::set<int>&, int&, const ListRows&);
void content_list_draw(Panel&, SelectionKind, const std::vector<int>&, const ListRows&);
int list_select_begin(Panel&, std::set<int>&, int&, const ListRows&, const std::vector<int>&);
void list_select_end(Panel&, std::set<int>&, int&, const ListRows&, int);
void list_panel_draw(Panel&, Actions&, const Footer&, const std::function<void()>&, bool = false, Actions* = nullptr);
bool tooltip_begin(const PanelState&, bool = true);
void tooltip_end();
void tooltip_name_draw(Resources&, const std::string&);
void tooltip_image_draw(const CardImage&, const std::function<void()>&);
void directory_open(Dialog&, Document&, const std::filesystem::path&);
std::filesystem::path asset_path_get(Document&, const std::filesystem::path&);
PopupButton popup_buttons_draw(Manager&, const char*, bool = true, StringType = BASIC_CANCEL);
void content_remove_action_add(Actions&, Panel&, ElementType, SelectionKind, int = -1);
bool is_drag_drop_active();
void command_push(const Panel&, std::function<void(Document&)>);
bool row_draw(Panel&, std::set<int>&, int&, const ListRows&, int, int, int);
void list_draw(Panel&, const std::vector<int>&, std::set<int>&, int&, const ListRows&);
void content_list_draw(Panel&, SelectionKind, const std::vector<int>&, const ListRows&);
int list_select_begin(Panel&, std::set<int>&, int&, const ListRows&, const std::vector<int>&);
void list_select_end(Panel&, std::set<int>&, int&, const ListRows&, int);
void list_panel_draw(Panel&, Actions&, const Footer&, const std::function<void()>&, bool = false, Actions* = nullptr);
bool tooltip_begin(const PanelState&, bool = true);
void tooltip_end();
void tooltip_name_draw(Resources&, const std::string&);
void tooltip_image_draw(const CardImage&, const std::function<void()>&);
void directory_open(Dialog&, Document&, const std::filesystem::path&);
std::filesystem::path asset_path_get(Document&, const std::filesystem::path&);
PopupButton popup_buttons_draw(Manager&, const char*, bool = true, StringType = BASIC_CANCEL);
void content_remove_action_add(Actions&, Panel&, ElementType, SelectionKind, int = -1);
struct SpritesheetsPanel
{
struct SpritesheetsPanel
{
PanelState state = {};
PopupHelper mergePopup = PopupHelper(LABEL_SPRITESHEETS_MERGE_POPUP, POPUP_SMALL_NO_HEIGHT);
PopupHelper packPopup = PopupHelper(LABEL_SPRITESHEETS_PACK_POPUP, POPUP_SMALL_NO_HEIGHT);
@@ -123,105 +123,104 @@
std::set<int> mergeIds;
std::set<int> saveIds;
int packId = -1;
};
};
struct RegionsPanel
{
struct RegionsPanel
{
PanelState state = {};
PopupHelper propertiesPopup = PopupHelper(LABEL_REGION_PROPERTIES, POPUP_SMALL_NO_HEIGHT);
PopupHelper exportPopup = PopupHelper(LABEL_EXPORT_REGION, POPUP_SMALL_NO_HEIGHT);
Region editRegion = {};
int editId = -1;
int exportId = -1;
};
};
struct AnimationsPanel
{
struct AnimationsPanel
{
PanelState state = {};
PopupHelper mergePopup = PopupHelper(LABEL_ANIMATIONS_MERGE_POPUP);
MultiSelectStorage mergeSelection = {};
std::vector<int> mergeKeys;
int mergeReference = -1;
};
};
struct FramePropertiesPanel
{
struct FramePropertiesPanel
{
ChangeAllFrameProperties changeAllFrameProperties = {};
bool isBatchMode = false;
};
};
class Taskbar;
class Documents;
class Taskbar;
class Documents;
void animations_update(Panel&, AnimationsPanel&);
void layers_update(Panel&);
void nulls_update(Panel&);
void events_update(Panel&);
void sounds_update(Panel&);
std::string layer_label_get(const Layer&);
void layer_source_tooltip_draw(const Document&, const Layer&);
void layer_source_tooltip_draw(const Document&, const Layer&);
Layer item_edit_layer_get(const Manager::ItemEdit&);
Null item_edit_null_get(const Manager::ItemEdit&);
void layer_source_draw(Document&, Manager::ItemEdit&);
void libraries_update(Panel&);
void spritesheets_update(Panel&, SpritesheetsPanel&);
void regions_update(Panel&, RegionsPanel&);
void frame_properties_update(Manager&, Settings&, FramePropertiesPanel&);
void onionskin_update(Manager&, Settings&);
void tools_update(Manager&, Settings&, Resources&, PopupHelper&);
void welcome_update(Manager&, Resources&, Dialog&, Taskbar&, Documents&);
void animations_update(Panel&, AnimationsPanel&);
void layers_update(Panel&);
void nulls_update(Panel&);
void events_update(Panel&);
void sounds_update(Panel&);
std::string layer_label_get(const Layer&);
void layer_source_tooltip_draw(const Document&, const Layer&);
void layer_source_tooltip_draw(const Document&, const Layer&);
Layer item_edit_layer_get(const Manager::ItemEdit&);
Null item_edit_null_get(const Manager::ItemEdit&);
void layer_source_draw(Document&, Manager::ItemEdit&);
void libraries_update(Panel&);
void spritesheets_update(Panel&, SpritesheetsPanel&);
void regions_update(Panel&, RegionsPanel&);
void frame_properties_update(Manager&, Settings&, FramePropertiesPanel&);
void onionskin_update(Manager&, Settings&);
void tools_update(Manager&, Settings&, Resources&, PopupHelper&);
void welcome_update(Manager&, Resources&, Dialog&, Taskbar&, Documents&);
template <class Items> std::vector<int> item_ids_get(const Items& items)
{
template <class Items> std::vector<int> item_ids_get(const Items& items)
{
std::vector<int> ids;
for (auto& item : items)
ids.push_back(item.id);
ids.push_back(item.id);
return ids;
}
}
template <class Items> void items_copy(Clipboard& clipboard, const Items& items, const std::set<int>& ids)
{
template <class Items> void items_copy(Clipboard& clipboard, const Items& items, const std::set<int>& ids)
{
std::string text;
for (auto id : ids)
if (auto item = item_get(items, id)) text += item_to_string(*item);
if (!text.empty()) clipboard.set(text);
}
if (auto item = item_get(items, id))
text += item_to_string(*item);
if (!text.empty())
clipboard.set(text);
}
// Pastes clipboard items into a content list with fresh ids and selects the last one.
template <class Item, class ItemsGet>
void items_paste(const Panel& panel, SelectionKind kind, StringType edit, StringType failToast, ItemsGet items_get)
{
// Pastes clipboard items into a content list with fresh ids and selects the last one.
template <class Item, class ItemsGet>
void items_paste(const Panel& panel, SelectionKind kind, StringType edit, StringType failToast, ItemsGet items_get)
{
auto text = panel.clipboard.get();
auto& state = panel.state;
command_push(panel,
[&state, kind, edit, failToast, text, items_get](Document& document)
{
std::string errorString;
auto pasted = items_from_string<Item>(text, &errorString);
if (pasted.empty()) return toast_log(Level::ERROR, failToast, errorString);
document.edit_apply(edit,
[&](Model& model)
{
auto& items = items_get(model);
for (auto& item : pasted)
{
item.id = item_next_id_get(items);
items.push_back(std::move(item));
}
});
auto id = items_get(document.model).back().id;
document.selected_ids_set(kind, {id});
document.focused_id_set(kind, id);
state.newId = id;
});
}
command_push(panel, [&state, kind, edit, failToast, text, items_get](Document& document) {
std::string errorString;
auto pasted = items_from_string<Item>(text, &errorString);
if (pasted.empty())
return toast_log(Level::ERROR, failToast, errorString);
document.edit_apply(edit, [&](Model& model) {
auto& items = items_get(model);
for (auto& item : pasted)
{
item.id = item_next_id_get(items);
items.push_back(std::move(item));
}
});
auto id = items_get(document.model).back().id;
document.selected_ids_set(kind, {id});
document.focused_id_set(kind, id);
state.newId = id;
});
}
// Copy and paste for a content list, after a separator.
template <class Item, class ItemsGet>
void items_clipboard_actions_add(Actions& actions, Panel& panel, SelectionKind kind, StringType pasteEdit,
StringType failToast, ItemsGet items_get)
{
// Copy and paste for a content list, after a separator.
template <class Item, class ItemsGet>
void items_clipboard_actions_add(Actions& actions, Panel& panel, SelectionKind kind, StringType pasteEdit,
StringType failToast, ItemsGet items_get)
{
auto selection = panel.document.selected_ids_get(kind);
actions.separator();
actions.add(
@@ -229,6 +228,7 @@
[&panel, selection, items_get]() { items_copy(panel.clipboard, items_get(panel.document.model), selection); });
actions.add(
ACTION_PASTE, [&panel]() { return !panel.clipboard.is_empty(); },
[&panel, kind, pasteEdit, failToast, items_get]()
{ items_paste<Item>(panel, kind, pasteEdit, failToast, items_get); });
}
[&panel, kind, pasteEdit, failToast, items_get]() {
items_paste<Item>(panel, kind, pasteEdit, failToast, items_get);
});
}