[ui] hide privacy screen hints when local unlock is disabled

This commit is contained in:
dijunkun
2026-10-28 09:39:42 +08:00
parent 25fb6ee051
commit 37cc6954a2
2 changed files with 12 additions and 11 deletions
@@ -69,16 +69,9 @@ CGFloat TextHeight(NSAttributedString* text, CGFloat width) {
const CGFloat margin = 32 * scale, text_width = 398 * scale; const CGFloat margin = 32 * scale, text_width = 398 * scale;
NSColor* foreground = [NSColor colorWithSRGBRed:245.0 / 255 green:247.0 / 255 NSColor* foreground = [NSColor colorWithSRGBRed:245.0 / 255 green:247.0 / 255
blue:250.0 / 255 alpha:1]; blue:250.0 / 255 alpha:1];
NSColor* muted = [NSColor colorWithSRGBRed:181.0 / 255 green:190.0 / 255
blue:204.0 / 255 alpha:1];
NSAttributedString* brand = Text(@"CrossDesk", 14 * scale, NSFontWeightSemibold, foreground); NSAttributedString* brand = Text(@"CrossDesk", 14 * scale, NSFontWeightSemibold, foreground);
NSAttributedString* hint = Text(self.unlockHint, 16 * scale, NSFontWeightRegular, muted);
NSAttributedString* shortcut = Text(@"Control + Option + Shift + Esc", 24 * scale,
NSFontWeightSemibold, foreground);
const CGFloat logo_size = std::ceil(brand.size.width); const CGFloat logo_size = std::ceil(brand.size.width);
const CGFloat brand_height = TextHeight(brand, logo_size); const CGFloat brand_height = TextHeight(brand, logo_size);
const CGFloat hint_height = TextHeight(hint, text_width);
const CGFloat shortcut_height = self.allowLocalUnlock ? TextHeight(shortcut, text_width) : 0;
const CGFloat bottom = height - margin; const CGFloat bottom = height - margin;
const CGFloat logo_top = bottom - brand_height - 6 * scale - logo_size; const CGFloat logo_top = bottom - brand_height - 6 * scale - logo_size;
[self.logo drawInRect:NSMakeRect(margin, logo_top, logo_size, logo_size) [self.logo drawInRect:NSMakeRect(margin, logo_top, logo_size, logo_size)
@@ -86,10 +79,18 @@ CGFloat TextHeight(NSAttributedString* text, CGFloat width) {
fraction:1 respectFlipped:YES hints:@{NSImageHintInterpolation: @(NSImageInterpolationHigh)}]; fraction:1 respectFlipped:YES hints:@{NSImageHintInterpolation: @(NSImageInterpolationHigh)}];
[brand drawWithRect:NSMakeRect(margin, bottom - brand_height, logo_size, brand_height) [brand drawWithRect:NSMakeRect(margin, bottom - brand_height, logo_size, brand_height)
options:kTextOptions]; options:kTextOptions];
if (!self.allowLocalUnlock) return;
NSColor* muted = [NSColor colorWithSRGBRed:181.0 / 255 green:190.0 / 255
blue:204.0 / 255 alpha:1];
NSAttributedString* hint = Text(self.unlockHint, 16 * scale, NSFontWeightRegular, muted);
NSAttributedString* shortcut = Text(@"Control + Option + Shift + Esc", 24 * scale,
NSFontWeightSemibold, foreground);
const CGFloat hint_height = TextHeight(hint, text_width);
const CGFloat shortcut_height = TextHeight(shortcut, text_width);
const CGFloat text_left = margin + logo_size + 24 * scale; const CGFloat text_left = margin + logo_size + 24 * scale;
[hint drawWithRect:NSMakeRect(text_left, bottom - shortcut_height - (self.allowLocalUnlock ? 12 * scale : 0) - hint_height, [hint drawWithRect:NSMakeRect(text_left, bottom - shortcut_height - 12 * scale - hint_height,
text_width, hint_height) options:kTextOptions]; text_width, hint_height) options:kTextOptions];
if (self.allowLocalUnlock) [shortcut drawWithRect:NSMakeRect(text_left, bottom - shortcut_height, [shortcut drawWithRect:NSMakeRect(text_left, bottom - shortcut_height,
text_width, shortcut_height) options:kTextOptions]; text_width, shortcut_height) options:kTextOptions];
} }
@end @end
@@ -68,7 +68,7 @@ bool DrawPrivacyCover(HDC dc, const RECT& rect, UINT dpi, HINSTANCE module,
}}; }};
constexpr UINT flags = DT_LEFT | DT_WORDBREAK | DT_NOPREFIX; constexpr UINT flags = DT_LEFT | DT_WORDBREAK | DT_NOPREFIX;
for (size_t i = 0; i < lines.size(); ++i) { for (size_t i = 0; i < lines.size(); ++i) {
if (i == 1 && !allow_local_unlock) continue; if (i < kInstructionLines && !allow_local_unlock) continue;
auto& line = lines[i]; auto& line = lines[i];
resources.fonts[i] = resources.fonts[i] =
CreateFontW(-px(line.size), 0, 0, 0, line.weight, FALSE, FALSE, FALSE, CreateFontW(-px(line.size), 0, 0, 0, line.weight, FALSE, FALSE, FALSE,
@@ -110,8 +110,8 @@ bool DrawPrivacyCover(HDC dc, const RECT& rect, UINT dpi, HINSTANCE module,
if (!DrawTextW(dc, lines[kBrandLine].text, -1, &brand_bounds, if (!DrawTextW(dc, lines[kBrandLine].text, -1, &brand_bounds,
DT_CENTER | DT_SINGLELINE | DT_NOPREFIX)) DT_CENTER | DT_SINGLELINE | DT_NOPREFIX))
return false; return false;
if (!allow_local_unlock) return true;
for (size_t i = 0; i < kInstructionLines; ++i) { for (size_t i = 0; i < kInstructionLines; ++i) {
if (i == 1 && !allow_local_unlock) continue;
const auto& line = lines[i]; const auto& line = lines[i];
if (!Select(dc, resources.fonts[i])) return false; if (!Select(dc, resources.fonts[i])) return false;
RECT bounds{left, top, left + text_width, top + line.bounds.bottom}; RECT bounds{left, top, left + text_width, top + line.bounds.bottom};