mirror of
https://github.com/anomalyco/hex.git
synced 2026-11-28 13:02:21 +01:00
What: the accent callout now looks and behaves like the system keyboard's (iOS 27.2 simulators, every English letter, digit and symbol key held and screenshotted): - Arrangement: options sit where Apple puts them, the key's own selected over the key (e: ë é [e] è ê ě ẽ ē ė ę; $: ₽ ¥ € [$] ¢ £ ₩; " « » „ “ ” ["]). "a" gets two rows (æ ã å ā ă ą over a à á â ä ǎ). The characters stay #2140's observed lists (KeyboardLanguage.letterHolds, symbolHolds, the 123/#+= list). AccentCatalog.arrangement only places them, and only while its table lists exactly the same options, so a list change can't drop or invent one. Languages without a checked arrangement open from the key toward the middle, as before. - Geometry: cells are the held key's width + 4 pt (36.3 on a 390 pt iPhone's letters, 51.7 on the wide . , ? ! ' keys, 67 in landscape). Rows are 47 pt with 10.5/10.35 pt padding and 20.8 pt corners, 3 pt above the key, kept 6.67 pt from the sides. Sliding picks by row, then by nearest cell. - Look: the selection is a grey rounded square (227/227/230, dark 87 grey, 6.3 pt corners) behind 21.5 pt regular options, on the pop-up's bubble with no border. The dark callout lightens toward its bottom. - Letting go more than 57.5 pt below the key's middle closes the callout with nothing typed (Apple: 55 pt types, 60 cancels). - Hold delay 0.36 s: the callout replaces the pop-up about 380 ms in (Apple 382, Hex was 420). The emoji panel's skin-tone picker passes its own cell width and keeps its layout and drawing unchanged (AccentMenu.buildFixed, drawFixed). Removed: the blue selected cell with white medium text, the 1 px border, the 44 pt cells and 4 pt padding, and opening every list sideways from the key with the base at the thumb end. Why: press-and-hold visuals should match the system keyboard one to one. Verified: 17e simulator screenshots of Apple vs Hex holds (e with slide and drag-off cancel, a, n, u, k, $, 0, ", ', .), light and dark, and landscape (i). The drag-off typed nothing on both. Updated testLongPressAccentPicker... for Apple's arrangement. Full HEXMobileTests pass apart from #2142's emoji bar band test, fixed with the key-plane geometry it depends on. Rebased on #2164 and #2172: the arrangement is looked up for the layout's language and letters, as the options are (the bilingual English & Spanish keyboard holds English's; Spanish on plain QWERTY, whose n also holds ñ, opens its own list). testEnglishOnQWERTZTypesOnItsOwnKeys checks the selected option is the key's own instead of the first, since Apple's y reads ÿ ŷ ý [y].
139 lines
7.1 KiB
Swift
139 lines
7.1 KiB
Swift
import UIKit
|
|
|
|
/// The full keyboard's colours, light and dark, calibrated against Apple's iOS 26
|
|
/// Liquid Glass system keyboard. Dark follows the keyboard's trait collection, which iOS
|
|
/// sets from the field's `keyboardAppearance` and the host's current style, as it does
|
|
/// the system platter behind the keys. The document proxy's `keyboardAppearance` can't
|
|
/// decide it: the host resolves a default field to light or dark when it sends its traits
|
|
/// and doesn't send them again when only its style changes, so after switching apps it
|
|
/// could still say light in dark mode (TestFlight build 29).
|
|
struct FullKeyboardPalette: Equatable {
|
|
let isDark: Bool
|
|
|
|
static func isDark(traits: UITraitCollection) -> Bool {
|
|
traits.userInterfaceStyle == .dark
|
|
}
|
|
|
|
private static func rgb(_ hex: UInt32, alpha: CGFloat = 1) -> UIColor {
|
|
UIColor(
|
|
red: CGFloat((hex >> 16) & 0xFF) / 255,
|
|
green: CGFloat((hex >> 8) & 0xFF) / 255,
|
|
blue: CGFloat(hex & 0xFF) / 255,
|
|
alpha: alpha
|
|
)
|
|
}
|
|
|
|
/// Stand-in for the system Liquid Glass platter, used only in standalone snapshot scenes.
|
|
var backdrop: UIColor { isDark ? Self.rgb(0x17181A) : Self.rgb(0xDFE1E6) }
|
|
|
|
var textBase: UIColor { isDark ? .white : .black }
|
|
var textMuted: UIColor { isDark ? UIColor(white: 1, alpha: 0.56) : Self.rgb(0x525763) }
|
|
|
|
/// Unified iOS 26 Liquid Glass keycap fill across letters and modifiers:
|
|
/// `white @ 0.16` composites to `(61,61,63)` on dark `(23,24,26)` and `(94,94,96)` on dark-field `(64,64,66)`.
|
|
var keyFill: UIColor { isDark ? UIColor(white: 1, alpha: 0.16) : .white }
|
|
var keyPressedFill: UIColor { isDark ? UIColor(white: 1, alpha: 0.28) : Self.rgb(0xD8DCE4) }
|
|
/// A held key on the key plane, under its pop-up: Apple's grey (222 on white keys; 105 on
|
|
/// dark ones, iOS 27.2).
|
|
var keyHeldFill: UIColor { isDark ? UIColor(white: 1, alpha: 0.32) : Self.rgb(0xDEDEDE) }
|
|
/// A held shift, delete, globe, emoji or return key: Apple's darker grey (197, 197, 201;
|
|
/// 131 on dark keys).
|
|
var functionHeldFill: UIColor { isDark ? UIColor(white: 1, alpha: 0.44) : Self.rgb(0xC5C5C9) }
|
|
/// A held space bar: only a shade darker (242, 242, 247; 56 on dark keys).
|
|
var spaceHeldFill: UIColor { isDark ? UIColor(white: 1, alpha: 0.1) : Self.rgb(0xF2F2F7) }
|
|
/// Secondary fill for non-key chips and the recording panel's cancel pill.
|
|
var functionFill: UIColor { isDark ? UIColor(white: 1, alpha: 0.09) : UIColor(white: 0, alpha: 0.065) }
|
|
var keyShadow: UIColor { .clear }
|
|
|
|
/// Opaque so balloons and menus float cleanly over the strip and neighbouring keys.
|
|
var popupFill: UIColor { isDark ? Self.rgb(0x4E5056) : .white }
|
|
/// The key pop-up's and the accent callout's bubble: white, or in dark Apple's neutral grey
|
|
/// (63 at its top, lightening downward).
|
|
var bubbleFill: UIColor { isDark ? Self.rgb(0x3F3F41) : .white }
|
|
var bubbleShadow: UIColor { UIColor(white: 0, alpha: isDark ? 0.3 : 0.1) }
|
|
/// The accent callout's selected option: a grey square behind it (227, 227, 230; 87 in dark).
|
|
var accentSelectFill: UIColor { isDark ? Self.rgb(0x57575A) : Self.rgb(0xE3E3E6) }
|
|
var popupBorder: UIColor { isDark ? UIColor(white: 1, alpha: 0.14) : UIColor(white: 0, alpha: 0.08) }
|
|
var popupShadow: UIColor { UIColor(white: 0, alpha: isDark ? 0.42 : 0.18) }
|
|
|
|
var chipFill: UIColor { isDark ? UIColor(white: 1, alpha: 0.11) : UIColor(white: 0, alpha: 0.065) }
|
|
var wellFill: UIColor { isDark ? UIColor(white: 1, alpha: 0.055) : UIColor(white: 0, alpha: 0.045) }
|
|
var separator: UIColor { isDark ? UIColor(white: 1, alpha: 0.12) : UIColor(white: 0, alpha: 0.10) }
|
|
var selectFill: UIColor { isDark ? UIColor(white: 1, alpha: 0.18) : UIColor(white: 0, alpha: 0.075) }
|
|
var selectText: UIColor { textBase }
|
|
|
|
/// Apple's predictive bar, measured on its platter (dark (34,34,35), light (226,227,232),
|
|
/// iOS 27.2): words (163,163,164) / (74,74,76), dividers (50,50,53) / (211,212,217), and the
|
|
/// pending autocorrection's and a pressed word's capsule (115,115,115) under white words /
|
|
/// (235,237,240) under (44,46,49).
|
|
var stripText: UIColor { isDark ? UIColor(white: 1, alpha: 0.58) : UIColor(white: 0, alpha: 0.67) }
|
|
var stripDivider: UIColor { isDark ? UIColor(white: 1, alpha: 0.075) : UIColor(white: 0, alpha: 0.066) }
|
|
var stripPillFill: UIColor { isDark ? UIColor(white: 1, alpha: 0.37) : UIColor(white: 1, alpha: 0.33) }
|
|
/// A pressed word gets the same capsule (measured the same on Apple's bar).
|
|
var stripPillPressedFill: UIColor { stripPillFill }
|
|
var stripPillText: UIColor { isDark ? .white : UIColor(white: 0, alpha: 0.81) }
|
|
|
|
/// Apple system keyboard action blue (`#007AFF`).
|
|
var actionFill: UIColor { Self.rgb(0x007AFF) }
|
|
var actionPressedFill: UIColor { Self.rgb(0x0062CC) }
|
|
var warmCore: UIColor { Self.rgb(0xFF9500) }
|
|
|
|
static let cornerRadius: CGFloat = 8.5
|
|
}
|
|
|
|
/// The Hex mark (two hexagon outlines and a filled core) as UIKit paths.
|
|
enum HexMarkPath {
|
|
private static let outer: [CGPoint] = [
|
|
CGPoint(x: 32, y: 4), CGPoint(x: 57, y: 18.5), CGPoint(x: 57, y: 45.5),
|
|
CGPoint(x: 32, y: 60), CGPoint(x: 7, y: 45.5), CGPoint(x: 7, y: 18.5),
|
|
]
|
|
private static let middle: [CGPoint] = [
|
|
CGPoint(x: 32, y: 15), CGPoint(x: 48, y: 24.25), CGPoint(x: 48, y: 39.75),
|
|
CGPoint(x: 32, y: 49), CGPoint(x: 16, y: 39.75), CGPoint(x: 16, y: 24.25),
|
|
]
|
|
private static let core: [CGPoint] = [
|
|
CGPoint(x: 32, y: 24), CGPoint(x: 39.5, y: 28.25), CGPoint(x: 39.5, y: 36.75),
|
|
CGPoint(x: 32, y: 41), CGPoint(x: 24.5, y: 36.75), CGPoint(x: 24.5, y: 28.25),
|
|
]
|
|
|
|
static func draw(in context: CGContext, rect: CGRect, color: UIColor, coreColor: UIColor?) {
|
|
let side = min(rect.width, rect.height)
|
|
let s = side / 64
|
|
let origin = CGPoint(x: rect.midX - side / 2, y: rect.midY - side / 2)
|
|
|
|
func path(_ points: [CGPoint]) -> CGPath {
|
|
let p = CGMutablePath()
|
|
p.addLines(between: points.map { CGPoint(x: origin.x + $0.x * s, y: origin.y + $0.y * s) })
|
|
p.closeSubpath()
|
|
return p
|
|
}
|
|
|
|
context.saveGState()
|
|
context.setLineWidth(max(1.15, 4.5 * s))
|
|
context.setLineCap(.round)
|
|
context.setLineJoin(.round)
|
|
context.setStrokeColor(color.cgColor)
|
|
context.addPath(path(outer))
|
|
context.addPath(path(middle))
|
|
context.strokePath()
|
|
context.setFillColor((coreColor ?? color).cgColor)
|
|
context.addPath(path(core))
|
|
context.fillPath()
|
|
context.restoreGState()
|
|
}
|
|
}
|
|
|
|
extension CGContext {
|
|
/// Draws a continuous-corner iOS 26 Liquid Glass keycap with no legacy under-shadow.
|
|
func fillKeycap(_ rect: CGRect, fill: UIColor, shadow: UIColor = .clear, radius: CGFloat = FullKeyboardPalette.cornerRadius) {
|
|
let path = UIBezierPath(roundedRect: rect, cornerRadius: radius).cgPath
|
|
saveGState()
|
|
if shadow != .clear {
|
|
setShadow(offset: CGSize(width: 0, height: 1), blur: 0.5, color: shadow.cgColor)
|
|
}
|
|
addPath(path)
|
|
setFillColor(fill.cgColor)
|
|
fillPath()
|
|
restoreGState()
|
|
}
|
|
}
|