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:
1 parent
40f6b554b5
commit
7afdf709c3
176 files changed
+20500
-19048
No files matched your search
+41
-37
@@ -8,17 +8,17 @@
|
||||
|
||||
#include "types.h"
|
||||
|
||||
constexpr auto LIFETIME = 4.0f;
|
||||
constexpr auto FADE_THRESHOLD = 1.0f;
|
||||
constexpr auto LIFETIME = 4.0f;
|
||||
constexpr auto FADE_THRESHOLD = 1.0f;
|
||||
|
||||
Toast::Toast(const std::string& message)
|
||||
{
|
||||
Toast::Toast(const std::string& message)
|
||||
{
|
||||
this->message = message;
|
||||
lifetime = LIFETIME;
|
||||
}
|
||||
}
|
||||
|
||||
void Toasts::update()
|
||||
{
|
||||
void Toasts::update()
|
||||
{
|
||||
auto borderColor = ImGui::GetStyleColorVec4(ImGuiCol_Border);
|
||||
auto textColor = ImGui::GetStyleColorVec4(ImGuiCol_Text);
|
||||
|
||||
@@ -28,43 +28,47 @@
|
||||
|
||||
for (int i = (int)toasts.size() - 1; i >= 0; --i)
|
||||
{
|
||||
Toast& toast = toasts[i];
|
||||
Toast& toast = toasts[i];
|
||||
|
||||
if (toast.lifetime <= 0.0f)
|
||||
{
|
||||
toasts.erase(toasts.begin() + i);
|
||||
i--;
|
||||
continue;
|
||||
}
|
||||
if (toast.lifetime <= 0.0f)
|
||||
{
|
||||
toasts.erase(toasts.begin() + i);
|
||||
i--;
|
||||
continue;
|
||||
}
|
||||
|
||||
toast.lifetime -= ImGui::GetIO().DeltaTime;
|
||||
toast.lifetime -= ImGui::GetIO().DeltaTime;
|
||||
|
||||
auto alpha = toast.lifetime <= FADE_THRESHOLD ? toast.lifetime / FADE_THRESHOLD : 1.0f;
|
||||
borderColor.w = alpha;
|
||||
textColor.w = alpha;
|
||||
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);
|
||||
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::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);
|
||||
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)); }
|
||||
void Toasts::push(const std::string& message)
|
||||
{
|
||||
toasts.emplace_back(Toast(message));
|
||||
}
|
||||
|
||||
Toasts toasts;
|
||||
Reference in new issue
Block a user