diff --git a/src/ui.cpp b/src/ui.cpp index c91dca4..b55b2f6 100644 --- a/src/ui.cpp +++ b/src/ui.cpp @@ -1759,7 +1759,7 @@ int fitSettingsColumns(WindowLayout &layout, size_t first, size_t end, int width } int fitLanSettings(HWND panel, int width); int fitSyncSettings(HWND panel, int width); -int fitDriveSettings(HWND panel, int width); +int fitDriveSettings(HWND panel, int width, int height); void reflowSettingsPage(HWND pane, WindowLayout &layout, int width, int height) { const auto &v = *reinterpret_cast(GetWindowLongPtrW(GetParent(pane), GWLP_USERDATA)); @@ -1771,8 +1771,10 @@ void reflowSettingsPage(HWND pane, WindowLayout &layout, int width, int height) if (v.selectedPage == ManageComputersPage || v.selectedPage == OpenBaoPage || v.selectedPage == GoogleDrivePage) { const int panelWidth = std::max(1, available - 16); + const int panelAreaHeight = std::max(1, height * 96 / static_cast(dpi) - 15); const int panelHeight = v.selectedPage == ManageComputersPage ? fitLanSettings(v.lan, panelWidth) : - v.selectedPage == OpenBaoPage ? fitSyncSettings(v.sync, panelWidth) : fitDriveSettings(v.drive, panelWidth); + v.selectedPage == OpenBaoPage ? fitSyncSettings(v.sync, panelWidth) : + fitDriveSettings(v.drive, panelWidth, panelAreaHeight); layout.controls[page.first].second = {8, 7, 8 + panelWidth, 7 + panelHeight}; layout.height = panelHeight + 15; return; diff --git a/src/ui_google_drive.inl b/src/ui_google_drive.inl index 25ae6b8..23596c5 100644 --- a/src/ui_google_drive.inl +++ b/src/ui_google_drive.inl @@ -2,6 +2,10 @@ constexpr int DriveConnect = 620, DriveBackup = 621, DriveRestore = 622, DriveDi constexpr int DriveSyncNow = 626, DriveSyncUpload = 627, DriveSyncDownload = 628, DriveSyncConflicts = 629, DriveSyncStatus = 630; constexpr int DriveSettingsWidth = 660, DriveSettingsHeight = 390; +constexpr int DriveMargin = 16, DriveButtonWidth = 276, DriveButtonGap = 16; +constexpr int DriveLeftButton = (DriveSettingsWidth - 2 * DriveButtonWidth - DriveButtonGap) / 2; +constexpr int DriveRightButton = DriveLeftButton + DriveButtonWidth + DriveButtonGap; +constexpr int DriveBackupActionsTop = 124; constexpr int DriveSyncTop = 193; enum class DriveAction { Status, Connect, Backup, Restore, Disconnect }; struct DriveResult @@ -342,21 +346,21 @@ HWND createDriveSettings(HWND pane, SettingsView &settings) SetPropW(w, L"Font", GetPropW(pane, L"Font")); auto *layout = new WindowLayout{DriveSettingsWidth, DriveSettingsHeight, 0, 0, true, true}; SetPropW(w, L"WindowLayout", layout); - constexpr int left = 16, width = DriveSettingsWidth - 2 * left; + constexpr int left = DriveMargin, width = DriveSettingsWidth - 2 * left; settingsGroupLabel(w, L"Backup and restore", left, 14, width); label(w, L"Apply or Save your edits before backing them up.", left, 40, width); edit(w, DriveStatus, left, 63, width, 54, ES_MULTILINE | ES_READONLY | WS_VSCROLL); - button(w, L"&Connect", DriveConnect, left, 124, 210); - button(w, L"Back &up saved settings", DriveBackup, left, 155, 210); - button(w, L"&Restore latest backup", DriveRestore, 338, 124, 210); - button(w, L"&Disconnect", DriveDisconnect, 338, 155, 210); + button(w, L"&Connect", DriveConnect, DriveLeftButton, DriveBackupActionsTop, DriveButtonWidth); + button(w, L"Back &up saved settings", DriveBackup, DriveLeftButton, DriveBackupActionsTop + 31, DriveButtonWidth); + button(w, L"&Restore latest backup", DriveRestore, DriveRightButton, DriveBackupActionsTop, DriveButtonWidth); + button(w, L"&Disconnect", DriveDisconnect, DriveRightButton, DriveBackupActionsTop + 31, DriveButtonWidth); settingsGroupLabel(w, L"Automatic synchronization", left, DriveSyncTop, width); checkbox(w, L"&Use Google Drive for automatic synchronization", DriveAutomatic, left, DriveSyncTop + 27, width); edit(w, DriveSyncStatus, left, DriveSyncTop + 54, width, 52, ES_MULTILINE | ES_READONLY | WS_VSCROLL); - button(w, L"S&ync now", DriveSyncNow, left, DriveSyncTop + 113, SyncColumnWidth); - button(w, L"D&ownload sync profile", DriveSyncDownload, 338, DriveSyncTop + 113, SyncColumnWidth); - button(w, L"U&pload local settings to sync profile", DriveSyncUpload, left, DriveSyncTop + 144, SyncColumnWidth); - button(w, L"Resolve individual con&flicts…", DriveSyncConflicts, 338, DriveSyncTop + 144, SyncColumnWidth); + button(w, L"S&ync now", DriveSyncNow, DriveLeftButton, DriveSyncTop + 113, DriveButtonWidth); + button(w, L"D&ownload sync profile", DriveSyncDownload, DriveRightButton, DriveSyncTop + 113, DriveButtonWidth); + button(w, L"U&pload local settings to sync profile", DriveSyncUpload, DriveLeftButton, DriveSyncTop + 144, DriveButtonWidth); + button(w, L"Resolve individual con&flicts…", DriveSyncConflicts, DriveRightButton, DriveSyncTop + 144, DriveButtonWidth); for (int id : {DriveAutomatic, DriveSyncNow, DriveSyncUpload, DriveSyncDownload, DriveSyncConflicts}) EnableWindow(GetDlgItem(w, id), FALSE); captureSettingsGeometry(*layout, 0, w); @@ -365,11 +369,29 @@ HWND createDriveSettings(HWND pane, SettingsView &settings) return w; } -int fitDriveSettings(HWND panel, int width) +int fitDriveSettings(HWND panel, int width, int height) { auto &layout = *windowLayoutState(panel); layout.width = 1; - layout.height = fitSettingsColumns(layout, 0, layout.controls.size(), width, - {16, DriveSettingsWidth - 16, 338, 322, DriveSyncTop, 535, 0, 124}); + const int minimumHeight = fitSettingsColumns(layout, 0, layout.controls.size(), width, + {DriveMargin, DriveSettingsWidth - DriveMargin}); + const int extra = std::max(0, height - minimumHeight); + const int buttonWidth = std::clamp((width - 2 * DriveMargin - DriveButtonGap) / 2, 1, DriveButtonWidth); + const int firstButton = (width - 2 * buttonWidth - DriveButtonGap) / 2; + for (size_t i = 0; i < layout.controls.size(); ++i) + { + auto &[child, bounds] = layout.controls[i]; + const auto &original = layout.originalControls[i].bounds; + const int id = GetDlgCtrlID(child); + if (original.top >= DriveBackupActionsTop) OffsetRect(&bounds, 0, extra); + if (id == DriveStatus) bounds.bottom += extra; + if (id == DriveStatus || id == DriveSyncStatus) bounds.right = width - DriveMargin; + if ((id >= DriveConnect && id <= DriveDisconnect) || (id >= DriveSyncNow && id <= DriveSyncConflicts)) + { + bounds.left = firstButton + (original.left == DriveRightButton ? buttonWidth + DriveButtonGap : 0); + bounds.right = bounds.left + buttonWidth; + } + } + layout.height = minimumHeight + extra; return layout.height; } diff --git a/tests/chat_profiles.cpp b/tests/chat_profiles.cpp index 97e6282..dff37bb 100644 --- a/tests/chat_profiles.cpp +++ b/tests/chat_profiles.cpp @@ -62,6 +62,49 @@ void googleDriveWindowChecks(const std::filesystem::path &root) for (int id : {620, 621, 622, 623}) require(!IsWindowEnabled(GetDlgItem(drive, id)), "unconfigured OAuth actions are disabled"); } + const auto dips = [dpi = GetDpiForWindow(settings)](int value) { return MulDiv(value, dpi, 96); }; + const auto resize = [&](int width, int height) + { + SetWindowPos(settings, nullptr, 0, 0, dips(width), dips(height), SWP_NOMOVE | SWP_NOACTIVATE | SWP_NOZORDER); + }; + const auto boundsOf = [](HWND window) + { + RECT bounds{}; + GetWindowRect(window, &bounds); + return bounds; + }; + const auto backupStatus = GetDlgItem(drive, 624); + const auto syncStatus = GetDlgItem(drive, 630); + const auto lastButton = GetDlgItem(drive, 629); + resize(980, 650); + const auto originalStatus = boundsOf(backupStatus); + const auto originalSyncStatus = boundsOf(syncStatus); + resize(1100, 750); + const auto expandedStatus = boundsOf(backupStatus); + const auto expandedSyncStatus = boundsOf(syncStatus); + require((expandedStatus.bottom - expandedStatus.top) - (originalStatus.bottom - originalStatus.top) >= dips(80) && + expandedSyncStatus.bottom - expandedSyncStatus.top == originalSyncStatus.bottom - originalSyncStatus.top, + "raising the window grows the top status without stretching the lower status"); + const auto expandedPanel = boundsOf(drive); + const auto bottom = boundsOf(lastButton).bottom; + require(expandedPanel.bottom - bottom >= dips(18) && expandedPanel.bottom - bottom <= dips(22) && + boundsOf(pane).bottom - bottom <= dips(35), "the action block stays against the viewport bottom"); + for (const auto &status : {expandedStatus, expandedSyncStatus}) + require(std::abs((expandedPanel.right - status.right) - (status.left - expandedPanel.left)) <= dips(2), + "both status fields stretch to the right margin"); + for (const auto &[first, second] : {std::pair{620, 622}, {621, 623}, {626, 628}, {627, 629}}) + { + const auto left = boundsOf(GetDlgItem(drive, first)), right = boundsOf(GetDlgItem(drive, second)); + require(std::abs((left.left + right.right) - (expandedPanel.left + expandedPanel.right)) <= dips(2) && + left.right < right.left, "each action row is horizontally centered"); + } + resize(640, 460); + const auto compactStatus = boundsOf(backupStatus); + require(compactStatus.bottom - compactStatus.top >= dips(53) && + (GetWindowLongPtrW(pane, GWL_STYLE) & WS_VSCROLL), "short windows keep a usable status field and scroll"); + SendMessageW(pane, WM_VSCROLL, SB_BOTTOM, 0); + require(boundsOf(lastButton).bottom <= boundsOf(pane).bottom, "bottom actions remain reachable by scrolling"); + resize(1100, 750); RedrawWindow(settings, nullptr, nullptr, RDW_INVALIDATE | RDW_UPDATENOW | RDW_ALLCHILDREN); RECT area{}; GetClientRect(settings, &area);