Fix titlebar shortcut hint clipping (#1259)
* Add regression test for titlebar shortcut hint clipping * Fix titlebar shortcut hint clipping
This commit is contained in:
parent
64b37fc121
commit
459a0289c1
2 changed files with 25 additions and 4 deletions
|
|
@ -193,6 +193,14 @@ struct ShortcutHintHorizontalPlanner {
|
|||
}
|
||||
}
|
||||
|
||||
func titlebarShortcutHintHeight(for config: TitlebarControlsStyleConfig) -> CGFloat {
|
||||
max(14, config.iconSize + 1)
|
||||
}
|
||||
|
||||
func titlebarShortcutHintVerticalOffset(for config: TitlebarControlsStyleConfig) -> CGFloat {
|
||||
max(0, floor(config.buttonSize - titlebarShortcutHintHeight(for: config)))
|
||||
}
|
||||
|
||||
struct TitlebarControlButton<Content: View>: View {
|
||||
let config: TitlebarControlsStyleConfig
|
||||
let action: () -> Void
|
||||
|
|
@ -240,7 +248,6 @@ struct TitlebarControlsView: View {
|
|||
@StateObject private var modifierKeyMonitor = TitlebarShortcutHintModifierMonitor()
|
||||
private let titlebarHintRightSafetyShift: CGFloat = 10
|
||||
private let titlebarHintBaseXShift: CGFloat = -10
|
||||
private let titlebarHintBaseYShift: CGFloat = 1
|
||||
|
||||
private enum HintSlot: Int, CaseIterable {
|
||||
case toggleSidebar
|
||||
|
|
@ -304,7 +311,7 @@ struct TitlebarControlsView: View {
|
|||
}
|
||||
|
||||
private func titlebarHintVerticalBaseOffset(for config: TitlebarControlsStyleConfig) -> CGFloat {
|
||||
max(8, config.buttonSize * 0.4)
|
||||
titlebarShortcutHintVerticalOffset(for: config)
|
||||
}
|
||||
|
||||
@ViewBuilder
|
||||
|
|
@ -452,7 +459,6 @@ struct TitlebarControlsView: View {
|
|||
) -> some View {
|
||||
let yOffset = config.groupPadding.top
|
||||
+ titlebarHintVerticalBaseOffset(for: config)
|
||||
+ titlebarHintBaseYShift
|
||||
+ ShortcutHintDebugSettings.clamped(titlebarShortcutHintYOffset)
|
||||
|
||||
ZStack(alignment: .topLeading) {
|
||||
|
|
@ -480,7 +486,7 @@ struct TitlebarControlsView: View {
|
|||
.foregroundColor(.primary)
|
||||
.padding(.horizontal, 6)
|
||||
.padding(.vertical, 2)
|
||||
.frame(minHeight: max(14, config.iconSize + 1))
|
||||
.frame(minHeight: titlebarShortcutHintHeight(for: config))
|
||||
.background(ShortcutHintPillBackground())
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -166,6 +166,21 @@ final class TitlebarControlsSizingPolicyTests: XCTestCase {
|
|||
)
|
||||
XCTAssertTrue(titlebarControlsShouldApplyLayout(previous: baseline, next: changed))
|
||||
}
|
||||
|
||||
func testShortcutHintVerticalOffsetKeepsPillInsideButtonLane() {
|
||||
for style in TitlebarControlsStyle.allCases {
|
||||
let config = style.config
|
||||
let hintHeight = titlebarShortcutHintHeight(for: config)
|
||||
let verticalOffset = titlebarShortcutHintVerticalOffset(for: config)
|
||||
|
||||
XCTAssertGreaterThanOrEqual(verticalOffset, 0, "Expected non-negative hint offset for style \(style)")
|
||||
XCTAssertLessThanOrEqual(
|
||||
verticalOffset + hintHeight,
|
||||
config.buttonSize,
|
||||
"Expected hint pill to fit within the titlebar button lane for style \(style)"
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
final class TitlebarControlsHoverPolicyTests: XCTestCase {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue