Flatten src into model, edit and ui, with .h headers

Resources and utilities sit directly in src. The ImGui windows, wizards, popups and helpers are in ui.
Headers that would shadow system ones are renamed: math_util, timestamp, subprocess, localization.
Includes are written from src.
This commit is contained in:
shweet committed 2026-11-22 17:12:05 -05:00
1 parent a515267e26
commit 7fb2c607c2
175 files changed
+537 -537

No files matched your search

+75
View File
@@ -0,0 +1,75 @@
#include "ui/toast.h"
#include "ui/layout.h"
#include <format>
#include <imgui/imgui.h>
#include "types.h"
using namespace anm2ed::types;
namespace anm2ed::imgui
{
constexpr auto LIFETIME = 4.0f;
constexpr auto FADE_THRESHOLD = 1.0f;
Toast::Toast(const std::string& message)
{
this->message = message;
lifetime = LIFETIME;
}
void Toasts::update()
{
auto borderColor = ImGui::GetStyleColorVec4(ImGuiCol_Border);
auto textColor = ImGui::GetStyleColorVec4(ImGuiCol_Text);
// The main window's bottom right corner (coordinates are the desktop's once windows can be detached).
auto viewport = ImGui::GetMainViewport();
auto position = to_vec2(viewport->Pos) + to_vec2(viewport->Size) - to_vec2(ImGui::GetStyle().ItemSpacing);
for (int i = (int)toasts.size() - 1; i >= 0; --i)
{
Toast& toast = toasts[i];
if (toast.lifetime <= 0.0f)
{
toasts.erase(toasts.begin() + i);
i--;
continue;
}
toast.lifetime -= ImGui::GetIO().DeltaTime;
auto alpha = toast.lifetime <= FADE_THRESHOLD ? toast.lifetime / FADE_THRESHOLD : 1.0f;
borderColor.w = alpha;
textColor.w = alpha;
ImGui::SetNextWindowPos(to_imvec2(position), ImGuiCond_None, {1.0f, 1.0f});
ImGui::SetNextWindowSize(ImVec2(0, ImGui::GetTextLineHeightWithSpacing() + ImGui::GetStyle().WindowPadding.y));
ImGui::PushStyleColor(ImGuiCol_Text, textColor);
ImGui::PushStyleColor(ImGuiCol_Border, borderColor);
ImGui::SetNextWindowBgAlpha(alpha);
if (ImGui::Begin(std::format("##Toast #{}", i).c_str(), nullptr,
ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove |
ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoScrollWithMouse |
ImGuiWindowFlags_NoSavedSettings | ImGuiWindowFlags_AlwaysAutoResize |
ImGuiWindowFlags_NoFocusOnAppearing | ImGuiWindowFlags_NoNav))
{
ImGui::TextUnformatted(toast.message.c_str());
position.y -= ImGui::GetWindowSize().y + ImGui::GetStyle().ItemSpacing.y;
if (ImGui::IsWindowHovered() && ImGui::IsMouseClicked(ImGuiMouseButton_Left)) toast.lifetime = 0.0f;
}
ImGui::End();
ImGui::PopStyleColor(2);
}
}
void Toasts::push(const std::string& message) { toasts.emplace_back(Toast(message)); }
}
anm2ed::imgui::Toasts toasts;