Toasts in the top right, newest first
This commit is contained in:
1 parent
eb03fc9d1d
commit
4962eac7a8
1 file changed
+6
-4
+6
-4
@@ -706,13 +706,14 @@ void Ui::text_draw(Play& play, ImVec2 screen)
|
|||||||
ImGui::PopFont();
|
ImGui::PopFont();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Fading messages stacked down from the top right, newest first.
|
||||||
void Ui::toasts_draw(Play& play)
|
void Ui::toasts_draw(Play& play)
|
||||||
{
|
{
|
||||||
ImGuiStyle& style = ImGui::GetStyle();
|
ImGuiStyle& style = ImGui::GetStyle();
|
||||||
ImGuiViewport* viewport = ImGui::GetMainViewport();
|
ImGuiViewport* viewport = ImGui::GetMainViewport();
|
||||||
ImDrawList* drawList = ImGui::GetForegroundDrawList();
|
ImDrawList* drawList = ImGui::GetForegroundDrawList();
|
||||||
float height = ImGui::GetTextLineHeightWithSpacing() + style.WindowPadding.y * 2;
|
float height = ImGui::GetTextLineHeightWithSpacing() + style.WindowPadding.y * 2;
|
||||||
float bottom = viewport->WorkPos.y + viewport->WorkSize.y - play.inset - TOGGLE_HEIGHT - style.WindowPadding.y;
|
float right = viewport->WorkPos.x + viewport->WorkSize.x - style.WindowPadding.x;
|
||||||
for (int i = 0; i < (int)play.toasts.size(); i++)
|
for (int i = 0; i < (int)play.toasts.size(); i++)
|
||||||
{
|
{
|
||||||
Toast& toast = play.toasts[i];
|
Toast& toast = play.toasts[i];
|
||||||
@@ -721,9 +722,10 @@ void Ui::toasts_draw(Play& play)
|
|||||||
color.w = (float)toast.life / TOAST_LIFE;
|
color.w = (float)toast.life / TOAST_LIFE;
|
||||||
return ImGui::GetColorU32(color);
|
return ImGui::GetColorU32(color);
|
||||||
};
|
};
|
||||||
ImVec2 position = {viewport->WorkPos.x + style.WindowPadding.x, bottom - height * (play.toasts.size() - i)};
|
float width = ImGui::CalcTextSize(toast.message.c_str()).x + style.WindowPadding.x * 2;
|
||||||
ImVec2 end = {position.x + ImGui::CalcTextSize(toast.message.c_str()).x + style.WindowPadding.x * 2,
|
float age = play.toasts.size() - 1 - i;
|
||||||
position.y + height};
|
ImVec2 position = {right - width, viewport->WorkPos.y + style.WindowPadding.y + height * age};
|
||||||
|
ImVec2 end = {right, position.y + height};
|
||||||
drawList->AddRectFilled(position, end, color_get(ImGuiCol_WindowBg), style.WindowRounding);
|
drawList->AddRectFilled(position, end, color_get(ImGuiCol_WindowBg), style.WindowRounding);
|
||||||
drawList->AddRect(position, end, color_get(ImGuiCol_Border), style.WindowRounding);
|
drawList->AddRect(position, end, color_get(ImGuiCol_Border), style.WindowRounding);
|
||||||
drawList->AddText({position.x + style.WindowPadding.x, position.y + style.WindowPadding.y},
|
drawList->AddText({position.x + style.WindowPadding.x, position.y + style.WindowPadding.y},
|
||||||
|
|||||||
Reference in new issue
Block a user