[refactor] update notification window rendering for high-DPI scaling support

This commit is contained in:
dijunkun
2025-12-04 19:00:37 +08:00
parent 436dfafc2a
commit ed5ddb96fd
2 changed files with 32 additions and 31 deletions

View File

@@ -933,7 +933,7 @@ int Render::DrawMainWindow() {
MainWindow(); MainWindow();
// UpdateNotificationWindow(); UpdateNotificationWindow();
#ifdef __APPLE__ #ifdef __APPLE__
if (show_request_permission_window_) { if (show_request_permission_window_) {

View File

@@ -55,8 +55,8 @@ int Render::UpdateNotificationWindow() {
if (show_update_notification_window_ && update_available_) { if (show_update_notification_window_ && update_available_) {
const ImGuiViewport* viewport = ImGui::GetMainViewport(); const ImGuiViewport* viewport = ImGui::GetMainViewport();
float window_width = update_notification_window_width_; float update_notification_window_width = title_bar_button_width_ * 10.0f;
float window_height = update_notification_window_height_; float update_notification_window_height = title_bar_button_width_ * 8.0f;
// #ifdef __APPLE__ // #ifdef __APPLE__
// float font_scale = 0.3f; // float font_scale = 0.3f;
@@ -64,16 +64,16 @@ int Render::UpdateNotificationWindow() {
// float font_scale = 0.5f; // float font_scale = 0.5f;
// #endif // #endif
float button_width = 35.0f * dpi_scale_; ImGui::SetNextWindowPos(ImVec2((viewport->WorkSize.x - viewport->WorkPos.x -
float button_height = 25.0f * dpi_scale_; update_notification_window_width) /
2,
(viewport->WorkSize.y - viewport->WorkPos.y -
update_notification_window_height) /
2),
ImGuiCond_FirstUseEver);
ImGui::SetNextWindowPos( ImGui::SetNextWindowSize(ImVec2(update_notification_window_width,
ImVec2( update_notification_window_height));
(viewport->WorkSize.x - viewport->WorkPos.x - window_width) / 2,
(viewport->WorkSize.y - viewport->WorkPos.y - window_height) / 2),
ImGuiCond_FirstUseEver);
ImGui::SetNextWindowSize(ImVec2(window_width, window_height));
ImGui::PushStyleColor(ImGuiCol_WindowBg, ImVec4(1.0f, 1.0f, 1.0f, 1.0f)); ImGui::PushStyleColor(ImGuiCol_WindowBg, ImVec4(1.0f, 1.0f, 1.0f, 1.0f));
ImGui::PushStyleVar(ImGuiStyleVar_WindowBorderSize, 1.0f); ImGui::PushStyleVar(ImGuiStyleVar_WindowBorderSize, 1.0f);
@@ -85,11 +85,12 @@ int Render::UpdateNotificationWindow() {
ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoCollapse |
ImGuiWindowFlags_NoSavedSettings | ImGuiWindowFlags_NoTitleBar); ImGuiWindowFlags_NoSavedSettings | ImGuiWindowFlags_NoTitleBar);
ImGui::SetCursorPosY(ImGui::GetCursorPosY() + window_height * 0.05f); ImGui::SetCursorPosY(ImGui::GetCursorPosY() +
update_notification_window_height * 0.05f);
// title: new version available // title: new version available
ImGui::SetCursorPosX(window_width * 0.1f); ImGui::SetCursorPosX(update_notification_window_width * 0.1f);
ImGui::SetWindowFontScale(0.6f); ImGui::SetWindowFontScale(0.55f);
std::string title = std::string title =
localization::new_version_available[localization_language_index_] + localization::new_version_available[localization_language_index_] +
": v" + latest_version_; ": v" + latest_version_;
@@ -103,23 +104,25 @@ int Render::UpdateNotificationWindow() {
localization::access_website[localization_language_index_] + localization::access_website[localization_language_index_] +
"https://crossdesk.cn"; "https://crossdesk.cn";
ImGui::SetWindowFontScale(0.5f); ImGui::SetWindowFontScale(0.5f);
Hyperlink(download_text, "https://crossdesk.cn", window_width); Hyperlink(download_text, "https://crossdesk.cn",
update_notification_window_width);
ImGui::SetWindowFontScale(1.0f); ImGui::SetWindowFontScale(1.0f);
ImGui::Spacing(); ImGui::Spacing();
float scrollable_height = float scrollable_height =
window_height - UPDATE_NOTIFICATION_RESERVED_HEIGHT; update_notification_window_height - UPDATE_NOTIFICATION_RESERVED_HEIGHT;
if (main_windows_system_chinese_font_ != nullptr) { if (main_windows_system_chinese_font_ != nullptr) {
ImGui::PushFont(main_windows_system_chinese_font_); ImGui::PushFont(main_windows_system_chinese_font_);
} }
// scrollable content area // scrollable content area
ImGui::SetCursorPosX(window_width * 0.05f); ImGui::SetCursorPosX(update_notification_window_width * 0.05f);
ImGui::BeginChild("ScrollableContent", ImGui::BeginChild(
ImVec2(window_width * 0.9f, scrollable_height), "ScrollableContent",
ImGuiChildFlags_Border, ImGuiWindowFlags_None); ImVec2(update_notification_window_width * 0.9f, scrollable_height),
ImGui::SetWindowFontScale(0.6f); ImGuiChildFlags_Border, ImGuiWindowFlags_None);
ImGui::SetWindowFontScale(0.5f);
// set text wrap position to current available width (accounts for // set text wrap position to current available width (accounts for
// scrollbar) // scrollbar)
float wrap_pos = ImGui::GetContentRegionAvail().x; float wrap_pos = ImGui::GetContentRegionAvail().x;
@@ -129,7 +132,7 @@ int Render::UpdateNotificationWindow() {
if (latest_version_info_.contains("releaseName") && if (latest_version_info_.contains("releaseName") &&
latest_version_info_["releaseName"].is_string() && latest_version_info_["releaseName"].is_string() &&
!latest_version_info_["releaseName"].empty()) { !latest_version_info_["releaseName"].empty()) {
ImGui::SetCursorPosX(window_width * 0.05f); ImGui::SetCursorPosX(update_notification_window_width * 0.05f);
std::string release_name = std::string release_name =
latest_version_info_["releaseName"].get<std::string>(); latest_version_info_["releaseName"].get<std::string>();
ImGui::TextWrapped("%s", release_name.c_str()); ImGui::TextWrapped("%s", release_name.c_str());
@@ -138,7 +141,7 @@ int Render::UpdateNotificationWindow() {
// release notes // release notes
if (!release_notes_.empty()) { if (!release_notes_.empty()) {
ImGui::SetCursorPosX(window_width * 0.05f); ImGui::SetCursorPosX(update_notification_window_width * 0.05f);
std::string cleaned_notes = CleanMarkdown(release_notes_); std::string cleaned_notes = CleanMarkdown(release_notes_);
ImGui::TextWrapped("%s", cleaned_notes.c_str()); ImGui::TextWrapped("%s", cleaned_notes.c_str());
ImGui::Spacing(); ImGui::Spacing();
@@ -148,7 +151,7 @@ int Render::UpdateNotificationWindow() {
if (latest_version_info_.contains("releaseDate") && if (latest_version_info_.contains("releaseDate") &&
latest_version_info_["releaseDate"].is_string() && latest_version_info_["releaseDate"].is_string() &&
!latest_version_info_["releaseDate"].empty()) { !latest_version_info_["releaseDate"].empty()) {
ImGui::SetCursorPosX(window_width * 0.05f); ImGui::SetCursorPosX(update_notification_window_width * 0.05f);
std::string date_label = std::string date_label =
localization::release_date[localization_language_index_]; localization::release_date[localization_language_index_];
std::string release_date = latest_version_info_["releaseDate"]; std::string release_date = latest_version_info_["releaseDate"];
@@ -170,16 +173,15 @@ int Render::UpdateNotificationWindow() {
ImGui::Spacing(); ImGui::Spacing();
if (ConfigCenter::LANGUAGE::CHINESE == localization_language_) { if (ConfigCenter::LANGUAGE::CHINESE == localization_language_) {
ImGui::SetCursorPosX(UPDATE_NOTIFICATION_OK_BUTTON_PADDING_CN); ImGui::SetCursorPosX(update_notification_window_width * 0.407f);
} else { } else {
ImGui::SetCursorPosX(UPDATE_NOTIFICATION_OK_BUTTON_PADDING_EN); ImGui::SetCursorPosX(update_notification_window_width * 0.367f);
} }
ImGui::SetWindowFontScale(0.5f); ImGui::SetWindowFontScale(0.5f);
// update button // update button
if (ImGui::Button( if (ImGui::Button(
localization::update[localization_language_index_].c_str(), localization::update[localization_language_index_].c_str())) {
ImVec2(button_width, button_height))) {
// open download page // open download page
std::string url = "https://crossdesk.cn"; std::string url = "https://crossdesk.cn";
#if defined(_WIN32) #if defined(_WIN32)
@@ -196,8 +198,7 @@ int Render::UpdateNotificationWindow() {
ImGui::SameLine(); ImGui::SameLine();
if (ImGui::Button( if (ImGui::Button(
localization::cancel[localization_language_index_].c_str(), localization::cancel[localization_language_index_].c_str())) {
ImVec2(button_width, button_height))) {
show_update_notification_window_ = false; show_update_notification_window_ = false;
} }