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

+109 -80
View File
@@ -5,25 +5,33 @@
#include "ui/layout.h"
#include "ui/shortcut.h"
static bool is_action_shortcut_valid(int shortcutType) { return shortcutType >= 0 && shortcutType < SHORTCUT_COUNT; }
static bool is_action_shortcut_valid(int shortcutType)
{
return shortcutType >= 0 && shortcutType < SHORTCUT_COUNT;
}
static std::string action_shortcut_text_get(const Action& action, Settings& settings)
{
if (!is_action_shortcut_valid(action.shortcut)) return {};
static std::string action_shortcut_text_get(const Action& action, Settings& settings)
{
if (!is_action_shortcut_valid(action.shortcut))
return {};
return settings.*SHORTCUT_MEMBERS[action.shortcut];
}
}
static ImGuiKeyChord action_chord_get(const Action& action, Manager& manager)
{
if (!is_action_shortcut_valid(action.shortcut)) return ImGuiKey_None;
static ImGuiKeyChord action_chord_get(const Action& action, Manager& manager)
{
if (!is_action_shortcut_valid(action.shortcut))
return ImGuiKey_None;
return manager.chords[action.shortcut];
}
}
bool is_action_enabled(const Action& action) { return !action.isEnabled || action.isEnabled(); }
bool is_action_enabled(const Action& action)
{
return !action.isEnabled || action.isEnabled();
}
Action action_make(ActionType type, std::function<bool()> isEnabled, std::function<void()> run, StringType tooltip,
int shortcut)
{
Action action_make(ActionType type, std::function<bool()> isEnabled, std::function<void()> run, StringType tooltip,
int shortcut)
{
auto info = ACTION_INFOS[type];
return {.type = type,
.label = info.label,
@@ -31,110 +39,131 @@
.shortcut = shortcut == ACTION_COUNT ? info.shortcut : shortcut,
.isEnabled = std::move(isEnabled),
.run = std::move(run)};
}
}
void Actions::add(Action action) { items.push_back(std::move(action)); }
void Actions::add(Action action)
{
items.push_back(std::move(action));
}
void Actions::add(ActionType type, std::function<bool()> isEnabled, std::function<void()> run, StringType tooltip,
int shortcut)
{
void Actions::add(ActionType type, std::function<bool()> isEnabled, std::function<void()> run, StringType tooltip,
int shortcut)
{
add(action_make(type, std::move(isEnabled), std::move(run), tooltip, shortcut));
}
}
void Actions::separator() { items.push_back({.isSeparator = true}); }
void Actions::separator()
{
items.push_back({.isSeparator = true});
}
void actions_undo_redo_add(Actions& actions, Manager& manager, Document& document)
{
void actions_undo_redo_add(Actions& actions, Manager& manager, Document& document)
{
actions.add(
ACTION_UNDO, [&document]() { return document.is_able_to_undo(); }, [&manager]()
{ manager.command_push({manager.selected, [](Manager&, Document& document) { document.undo(); }}); });
ACTION_UNDO, [&document]() { return document.is_able_to_undo(); },
[&manager]() {
manager.command_push({manager.selected, [](Manager&, Document& document) { document.undo(); }});
});
actions.add(
ACTION_REDO, [&document]() { return document.is_able_to_redo(); }, [&manager]()
{ manager.command_push({manager.selected, [](Manager&, Document& document) { document.redo(); }}); });
}
ACTION_REDO, [&document]() { return document.is_able_to_redo(); },
[&manager]() {
manager.command_push({manager.selected, [](Manager&, Document& document) { document.redo(); }});
});
}
static void action_items_menu_draw(std::vector<Action>& items, Settings& settings)
{
static void action_items_menu_draw(std::vector<Action>& items, Settings& settings)
{
bool isPreviousSeparator = false;
for (auto& action : items)
{
if (action.isSeparator)
{
if (!isPreviousSeparator) ImGui::Separator();
isPreviousSeparator = true;
continue;
}
isPreviousSeparator = false;
if (!action.children.empty())
{
if (ImGui::BeginMenu(localize.get(action.label), is_action_enabled(action)))
if (action.isSeparator)
{
action_items_menu_draw(action.children, settings);
ImGui::EndMenu();
if (!isPreviousSeparator)
ImGui::Separator();
isPreviousSeparator = true;
continue;
}
continue;
}
isPreviousSeparator = false;
auto shortcutText = action_shortcut_text_get(action, settings);
auto shortcutLabel = shortcutText.empty() ? nullptr : shortcutText.c_str();
if (ImGui::MenuItem(localize.get(action.label), shortcutLabel, false, is_action_enabled(action)) && action.run)
action.run();
if (action.tooltip != STRING_UNDEFINED && ImGui::IsItemHovered(ImGuiHoveredFlags_AllowWhenDisabled))
ImGui::SetItemTooltip("%s", localize.get(action.tooltip));
if (!action.children.empty())
{
if (ImGui::BeginMenu(localize.get(action.label), is_action_enabled(action)))
{
action_items_menu_draw(action.children, settings);
ImGui::EndMenu();
}
continue;
}
auto shortcutText = action_shortcut_text_get(action, settings);
auto shortcutLabel = shortcutText.empty() ? nullptr : shortcutText.c_str();
if (ImGui::MenuItem(localize.get(action.label), shortcutLabel, false, is_action_enabled(action)) && action.run)
action.run();
if (action.tooltip != STRING_UNDEFINED && ImGui::IsItemHovered(ImGuiHoveredFlags_AllowWhenDisabled))
ImGui::SetItemTooltip("%s", localize.get(action.tooltip));
}
}
}
void actions_menu_draw(Actions& actions, Settings& settings) { action_items_menu_draw(actions.items, settings); }
void actions_menu_draw(Actions& actions, Settings& settings)
{
action_items_menu_draw(actions.items, settings);
}
bool actions_context_window_draw(const char* label, Actions& actions, Settings& settings, ImGuiPopupFlags flags,
ImGuiHoveredFlags hoveredFlags)
{
bool actions_context_window_draw(const char* label, Actions& actions, Settings& settings, ImGuiPopupFlags flags,
ImGuiHoveredFlags hoveredFlags)
{
auto mouseButton = flags & ImGuiPopupFlags_MouseButtonMask_;
if (ImGui::IsMouseReleased(mouseButton) &&
ImGui::IsWindowHovered(ImGuiHoveredFlags_AllowWhenBlockedByPopup | hoveredFlags))
if (!(flags & ImGuiPopupFlags_NoOpenOverItems) || !ImGui::IsAnyItemHovered()) ImGui::OpenPopup(label, flags);
if (!(flags & ImGuiPopupFlags_NoOpenOverItems) || !ImGui::IsAnyItemHovered())
ImGui::OpenPopup(label, flags);
if (!ImGui::BeginPopup(label, ImGuiWindowFlags_NoMove)) return false;
if (!ImGui::BeginPopup(label, ImGuiWindowFlags_NoMove))
return false;
actions_menu_draw(actions, settings);
ImGui::EndPopup();
return true;
}
}
bool actions_popup_draw(const char* label, Actions& actions, Settings& settings)
{
if (!ImGui::BeginPopup(label, ImGuiWindowFlags_NoMove)) return false;
bool actions_popup_draw(const char* label, Actions& actions, Settings& settings)
{
if (!ImGui::BeginPopup(label, ImGuiWindowFlags_NoMove))
return false;
actions_menu_draw(actions, settings);
ImGui::EndPopup();
return true;
}
}
void actions_shortcuts_update(Actions& actions, Manager& manager, ShortcutScope shortcutType)
{
void actions_shortcuts_update(Actions& actions, Manager& manager, ShortcutScope shortcutType)
{
for (auto& action : actions.items)
{
if (action.isSeparator || !action.run || !is_action_enabled(action)) continue;
auto chord = action_chord_get(action, manager);
if (!shortcut(chord, shortcutType)) continue;
action.run();
break;
if (action.isSeparator || !action.run || !is_action_enabled(action))
continue;
auto chord = action_chord_get(action, manager);
if (!shortcut(chord, shortcutType))
continue;
action.run();
break;
}
}
}
void action_button_draw(Action& action, Manager& manager, Settings& settings, ImVec2 widgetSize, bool& isSameLine)
{
if (isSameLine) ImGui::SameLine();
void action_button_draw(Action& action, Manager& manager, Settings& settings, ImVec2 widgetSize, bool& isSameLine)
{
if (isSameLine)
ImGui::SameLine();
ImGui::BeginDisabled(!is_action_enabled(action));
shortcut(action_chord_get(action, manager));
if (ImGui::Button(localize.get(action.label), widgetSize) && action.run) action.run();
if (ImGui::Button(localize.get(action.label), widgetSize) && action.run)
action.run();
ImGui::EndDisabled();
if (action.tooltip != STRING_UNDEFINED)
{
auto shortcutText = action_shortcut_text_get(action, settings);
if (shortcutText.empty())
ImGui::SetItemTooltip("%s", localize.get(action.tooltip));
else
set_item_tooltip_shortcut(localize.get(action.tooltip), shortcutText);
auto shortcutText = action_shortcut_text_get(action, settings);
if (shortcutText.empty())
ImGui::SetItemTooltip("%s", localize.get(action.tooltip));
else
set_item_tooltip_shortcut(localize.get(action.tooltip), shortcutText);
}
isSameLine = true;
}
}