[UI] Slightly improved performance of on screen notifications and achievements
This commit is contained in:
@@ -113,9 +113,9 @@ void AchievementNotificationWindow::OnDraw(ImGuiIO& io) {
|
||||
return;
|
||||
}
|
||||
|
||||
const std::string longest_notification_text_line =
|
||||
GetTitle().size() > GetDescription().size() ? GetTitle().c_str()
|
||||
: GetDescription().c_str();
|
||||
const std::string_view longest_notification_text_line =
|
||||
GetTitle().size() > GetDescription().size() ? GetTitle()
|
||||
: GetDescription();
|
||||
|
||||
const ImVec2 screen_size = io.DisplaySize;
|
||||
const float window_scale =
|
||||
@@ -124,7 +124,7 @@ void AchievementNotificationWindow::OnDraw(ImGuiIO& io) {
|
||||
const float font_scale = default_font_size / io.Fonts->Fonts[0]->FontSize;
|
||||
const ImVec2 text_size = io.Fonts->Fonts[0]->CalcTextSizeA(
|
||||
default_font_size * default_notification_text_scale * window_scale,
|
||||
FLT_MAX, -1.0f, longest_notification_text_line.c_str());
|
||||
FLT_MAX, -1.0f, longest_notification_text_line.data());
|
||||
|
||||
const ImVec2 final_notification_size =
|
||||
CalculateNotificationSize(text_size, window_scale);
|
||||
@@ -169,7 +169,7 @@ void AchievementNotificationWindow::OnDraw(ImGuiIO& io) {
|
||||
|
||||
ImGui::SameLine();
|
||||
if (notification_draw_progress_ > 0.5f) {
|
||||
ImGui::TextColored(white_color, "%s", GetNotificationText().c_str());
|
||||
ImGui::TextColored(white_color, "%s", GetNotificationText().data());
|
||||
}
|
||||
}
|
||||
// Restore previous style
|
||||
@@ -187,9 +187,9 @@ void XNotifyWindow::OnDraw(ImGuiIO& io) {
|
||||
return;
|
||||
}
|
||||
|
||||
const std::string longest_notification_text_line =
|
||||
GetTitle().size() > GetDescription().size() ? GetTitle().c_str()
|
||||
: GetDescription().c_str();
|
||||
const std::string_view longest_notification_text_line =
|
||||
GetTitle().size() > GetDescription().size() ? GetTitle()
|
||||
: GetDescription();
|
||||
|
||||
const ImVec2 screen_size = io.DisplaySize;
|
||||
const float window_scale =
|
||||
@@ -198,7 +198,7 @@ void XNotifyWindow::OnDraw(ImGuiIO& io) {
|
||||
const float font_scale = default_font_size / io.Fonts->Fonts[0]->FontSize;
|
||||
const ImVec2 text_size = io.Fonts->Fonts[0]->CalcTextSizeA(
|
||||
default_font_size * default_notification_text_scale * window_scale,
|
||||
FLT_MAX, -1.0f, longest_notification_text_line.c_str());
|
||||
FLT_MAX, -1.0f, longest_notification_text_line.data());
|
||||
|
||||
const ImVec2 final_notification_size =
|
||||
CalculateNotificationSize(text_size, window_scale);
|
||||
@@ -247,7 +247,7 @@ void XNotifyWindow::OnDraw(ImGuiIO& io) {
|
||||
|
||||
ImGui::SameLine();
|
||||
if (notification_draw_progress_ > 0.5f) {
|
||||
ImGui::TextColored(white_color, "%s", GetDescription().c_str());
|
||||
ImGui::TextColored(white_color, "%s", GetDescription().data());
|
||||
}
|
||||
}
|
||||
// Restore previous style
|
||||
|
||||
@@ -48,9 +48,9 @@ void HostNotificationWindow::OnDraw(ImGuiIO& io) {
|
||||
return;
|
||||
}
|
||||
|
||||
const std::string longest_notification_text_line =
|
||||
GetTitle().size() > GetDescription().size() ? GetTitle().c_str()
|
||||
: GetDescription().c_str();
|
||||
const std::string_view longest_notification_text_line =
|
||||
GetTitle().size() > GetDescription().size() ? GetTitle()
|
||||
: GetDescription();
|
||||
|
||||
const ImVec2 screen_size = io.DisplaySize;
|
||||
const float window_scale =
|
||||
@@ -59,7 +59,7 @@ void HostNotificationWindow::OnDraw(ImGuiIO& io) {
|
||||
const float font_size = io.Fonts->Fonts[0]->FontSize;
|
||||
const ImVec2 text_size = io.Fonts->Fonts[0]->CalcTextSizeA(
|
||||
font_size * window_scale, FLT_MAX, -1.0f,
|
||||
longest_notification_text_line.c_str());
|
||||
longest_notification_text_line.data());
|
||||
|
||||
const ImVec2 notification_size =
|
||||
CalculateNotificationSize(text_size, window_scale);
|
||||
@@ -78,9 +78,9 @@ void HostNotificationWindow::OnDraw(ImGuiIO& io) {
|
||||
{
|
||||
ImGui::SetWindowFontScale(window_scale);
|
||||
|
||||
ImGui::Text("%s", GetTitle().c_str());
|
||||
ImGui::Text("%s", GetTitle().data());
|
||||
ImGui::Separator();
|
||||
ImGui::Text("%s", GetDescription().c_str());
|
||||
ImGui::Text("%s", GetDescription().data());
|
||||
}
|
||||
ImGui::End();
|
||||
}
|
||||
|
||||
@@ -27,7 +27,13 @@ ImGuiNotification::ImGuiNotification(ui::ImGuiDrawer* imgui_drawer,
|
||||
description_(description),
|
||||
user_index_(user_index),
|
||||
position_(position_id),
|
||||
creation_time_(0) {}
|
||||
creation_time_(0) {
|
||||
notification_text_ = title_;
|
||||
if (!description_.empty()) {
|
||||
notification_text_.append("\n");
|
||||
notification_text_.append(description_);
|
||||
}
|
||||
}
|
||||
|
||||
ImGuiNotification::~ImGuiNotification() {
|
||||
imgui_drawer_->RemoveNotification(this);
|
||||
|
||||
@@ -77,22 +77,14 @@ class ImGuiNotification {
|
||||
return current_time - creation_time_ > time_to_close_;
|
||||
}
|
||||
|
||||
const std::string GetNotificationText() const {
|
||||
std::string text = title_;
|
||||
|
||||
if (!description_.empty()) {
|
||||
text.append("\n" + description_);
|
||||
}
|
||||
return text;
|
||||
}
|
||||
|
||||
void SetCreationTime(uint64_t new_creation_time) {
|
||||
creation_time_ = new_creation_time;
|
||||
}
|
||||
|
||||
const bool IsMarkedForDeletion() const { return marked_for_deletion_; }
|
||||
const std::string GetTitle() const { return title_; }
|
||||
const std::string GetDescription() const { return description_; }
|
||||
std::string_view GetTitle() const { return title_; }
|
||||
std::string_view GetDescription() const { return description_; }
|
||||
std::string_view GetNotificationText() const { return notification_text_; }
|
||||
|
||||
const uint8_t GetPositionId() const { return position_; }
|
||||
const uint8_t GetUserIndex() const { return user_index_; }
|
||||
@@ -123,6 +115,7 @@ class ImGuiNotification {
|
||||
|
||||
std::string title_;
|
||||
std::string description_;
|
||||
std::string notification_text_;
|
||||
|
||||
bool marked_for_deletion_ = false;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user