Liquid Glass and Apple Music touches for the Spotify iOS app. A GPL-3.0 fork of spoti.pw 0.21.1.
C
fix: settings text grows with Dynamic Type and accent controls keep their contrast
My-Name-Is-Jeff4ec81a0069a8
diff --git a/harness/mod-settings/stubs.m b/harness/mod-settings/stubs.mindex 062c882f..0d0a4a3a 100644--- a/harness/mod-settings/stubs.m+++ b/harness/mod-settings/stubs.m@@ -21,7 +21,7 @@ UIViewController *SGRLyricsSettingsPage(NSString *title, NSString *intro, NSArra#define ROW(name) SGModRow *name(void) { return SGPageRow(@#name, ^UIViewController *{ return nil; }); }ROW(SGAppIconRow) ROW(SGGeminiKeyRow) ROW(SGGlassLyricsRow) ROW(SGLockScreenLyricsRow) ROW(SGLyricsMeaningsRow)-ROW(SGLyricsTranslationLanguageRow) ROW(SGLyricsWordTimingRow) ROW(SGRLyricsTextSizesRow) ROW(SGLyricsDelayRow) ROW(SGLyricsRomanisedRow)+ROW(SGLyricsTranslationLanguageRow) ROW(SGLyricsWordTimingRow) ROW(SGRLyricsTextSizesRow) ROW(SGLyricsDelayRow)NSArray<SGModRow *> *SGAppFontRows(void) { return @[]; }NSArray<SGModRow *> *SGNativeAppearanceRows(void) { return @[]; }NSArray<SGModRow *> *SGRAppearanceRows(void) { return @[]; }diff --git a/tweak/Sources/App/About/UpdatePage.m b/tweak/Sources/App/About/UpdatePage.mindex d4bd6e50..9f4e0ee7 100644--- a/tweak/Sources/App/About/UpdatePage.m+++ b/tweak/Sources/App/About/UpdatePage.m@@ -255,7 +255,7 @@ static NSArray<SGUpdateRelease *> *releasesToShow(void) {}- (CGFloat)tableView:(UITableView *)table heightForHeaderInSection:(NSInteger)section {- return _groups[(NSUInteger)section].title ? SGSectionHeaderHeight : SGSectionGap;+ return _groups[(NSUInteger)section].title ? SGSectionHeaderHeight() : SGSectionGap;}- (UIView *)tableView:(UITableView *)table viewForFooterInSection:(NSInteger)section {@@ -288,7 +288,7 @@ static NSArray<SGUpdateRelease *> *releasesToShow(void) {cell.accessoryView = toggle;} else if (row.value) {UILabel *label = [UILabel new];- label.font = SGTitleFont();+ label.font = SGCappedFont(SGTitleFont(), 18); // beside the title, which keeps its roomlabel.textColor = SGGrey();label.text = row.value();[label sizeToFit];diff --git a/tweak/Sources/App/Onboarding/Tour.m b/tweak/Sources/App/Onboarding/Tour.mindex 39285ab5..7963a152 100644--- a/tweak/Sources/App/Onboarding/Tour.m+++ b/tweak/Sources/App/Onboarding/Tour.m@@ -31,7 +31,7 @@ UIButton *SGOnboardingButton(NSString *title) {else config = [UIButtonConfiguration filledButtonConfiguration];config.cornerStyle = UIButtonConfigurationCornerStyleCapsule;config.baseBackgroundColor = SGGreen();- config.baseForegroundColor = UIColor.blackColor;+ config.baseForegroundColor = SGOnAccent();config.contentInsets = NSDirectionalEdgeInsetsMake(15, 20, 15, 20);config.attributedTitle = [[NSAttributedString alloc] initWithString:title attributes:@{NSFontAttributeName: [UIFont systemFontOfSize:17 weight:UIFontWeightSemibold]}];UIButton *button = [UIButton buttonWithConfiguration:config primaryAction:nil];diff --git a/tweak/Sources/Native/Navbar/NavbarSettings.m b/tweak/Sources/Native/Navbar/NavbarSettings.mindex 36e084e9..5acfa575 100644--- a/tweak/Sources/Native/Navbar/NavbarSettings.m+++ b/tweak/Sources/Native/Navbar/NavbarSettings.m@@ -102,7 +102,7 @@ static void appendTab(NSDictionary *tab) {}- (CGFloat)tableView:(UITableView *)table heightForHeaderInSection:(NSInteger)section {- return SGSectionHeaderHeight;+ return SGSectionHeaderHeight();}- (CGFloat)tableView:(UITableView *)table heightForFooterInSection:(NSInteger)section {@@ -211,7 +211,7 @@ typedef NS_ENUM(NSInteger, SGNavbarSection) {}- (CGFloat)tableView:(UITableView *)table heightForHeaderInSection:(NSInteger)section {- if ([self headerFor:section]) return SGSectionHeaderHeight;+ if ([self headerFor:section]) return SGSectionHeaderHeight();return [self tableView:table numberOfRowsInSection:section] ? SGSectionGap : CGFLOAT_MIN;}diff --git a/tweak/Sources/Redesigned/Lyrics/LyricsTextSettings.m b/tweak/Sources/Redesigned/Lyrics/LyricsTextSettings.mindex 2bfd43cb..a42e2ed0 100644--- a/tweak/Sources/Redesigned/Lyrics/LyricsTextSettings.m+++ b/tweak/Sources/Redesigned/Lyrics/LyricsTextSettings.m@@ -45,7 +45,7 @@}- (CGFloat)tableView:(UITableView *)table heightForHeaderInSection:(NSInteger)section {- return SGSectionHeaderHeight;+ return SGSectionHeaderHeight();}- (CGFloat)tableView:(UITableView *)table heightForFooterInSection:(NSInteger)section {diff --git a/tweak/Sources/Redesigned/Navbar/NavbarSettings.m b/tweak/Sources/Redesigned/Navbar/NavbarSettings.mindex 0f1a877d..1b0efa91 100644--- a/tweak/Sources/Redesigned/Navbar/NavbarSettings.m+++ b/tweak/Sources/Redesigned/Navbar/NavbarSettings.m@@ -106,7 +106,7 @@ static void appendTab(NSDictionary *tab) {}- (CGFloat)tableView:(UITableView *)table heightForHeaderInSection:(NSInteger)section {- return SGSectionHeaderHeight;+ return SGSectionHeaderHeight();}- (CGFloat)tableView:(UITableView *)table heightForFooterInSection:(NSInteger)section {@@ -334,13 +334,20 @@ static const CGFloat kPictureHeight = 76;_glyphs[i].frame = CGRectMake(x + (slot - 24) / 2, glyphTop, 24, 24);_bars[i].frame = CGRectMake(x + (slot - 20) / 2, glyphTop + 32, 20, 4);}- CGFloat titleHeight = ceil(_title.font.lineHeight);+ _title.font = SGSubtitleFont();+ _title.numberOfLines = [SGRLabelCard titleLines];+ CGFloat titleHeight = _title.numberOfLines * ceil(_title.font.lineHeight);_title.frame = CGRectMake(0, kPictureHeight + 8, width, titleHeight);_check.frame = CGRectMake((width - 44) / 2, CGRectGetMaxY(_title.frame) - 6, 44, 44);}+// The name takes a second line at the accessibility sizes, where half the row is too narrow for it.++ (NSInteger)titleLines {+ return SGAccessibilityTextSize() ? 2 : 1;+}++ (CGFloat)height {- return kPictureHeight + 8 + ceil(SGSubtitleFont().lineHeight) - 6 + 44;+ return kPictureHeight + 8 + [self titleLines] * ceil(SGSubtitleFont().lineHeight) - 6 + 44;}@end@@ -498,7 +505,7 @@ typedef NS_ENUM(NSInteger, SGRNavbarSection) {}- (CGFloat)tableView:(UITableView *)table heightForHeaderInSection:(NSInteger)section {- return [self headerFor:section] ? SGSectionHeaderHeight : SGSectionGap;+ return [self headerFor:section] ? SGSectionHeaderHeight() : SGSectionGap;}- (UIView *)tableView:(UITableView *)table viewForFooterInSection:(NSInteger)section {diff --git a/tweak/Sources/Redesigned/Player/PlayerSettings.m b/tweak/Sources/Redesigned/Player/PlayerSettings.mindex 9456f242..794e25bc 100644--- a/tweak/Sources/Redesigned/Player/PlayerSettings.m+++ b/tweak/Sources/Redesigned/Player/PlayerSettings.m@@ -273,6 +273,7 @@ static NSArray<NSString *> *backgroundNotes(void) {- (void)viewWillLayoutSubviews {[super viewWillLayoutSubviews];UITableView *table = self.tableView;+ _note.font = SGSubtitleFont();CGFloat width = table.bounds.size.width, inset = table.layoutMargins.left;CGFloat cardWidth = width - 2 * inset;CGFloat cardHeight = round(MIN(kCardMaxHeight, MAX(kCardMinHeight, cardWidth * kCardAspect)));diff --git a/tweak/Sources/Settings/SGModPage.m b/tweak/Sources/Settings/SGModPage.mindex 7cd27f29..70f21cb9 100644--- a/tweak/Sources/Settings/SGModPage.m+++ b/tweak/Sources/Settings/SGModPage.m@@ -304,6 +304,13 @@ SGModRow *SGWithTile(SGModRow *row, NSString *symbol, UIColor *color) {// A value never takes more than this much of the row, so a long one ends in "…" and leaves the title its room.static const CGFloat kValueMaxWidth = 170;+// At the accessibility sizes a row's value goes under its title (stackedValue), and the accessories that+// would carry it beside the title show none.+static NSString *stackedValue(SGModRow *row) {+ NSString *value = row.value() ?: @"";+ return row.subtitle.length ? [NSString stringWithFormat:@"%@\n%@", row.subtitle, value] : value;+}+static UIView *valueAndChevron(NSString *text) {UILabel *label = [UILabel new];label.font = SGTitleFont();@@ -412,7 +419,7 @@ static UIFont *tabular(UIFont *font) {// value over a slider in the accent colour, a subtitle between them when there is one, each step stored// as the thumb reaches it.@interface SGModSliderCell : UITableViewCell-+ (CGFloat)heightFor:(SGModRow *)row;++ (CGFloat)heightFor:(SGModRow *)row width:(CGFloat)width;- (void)showRow:(SGModRow *)row;// The number again, after something else on the page changed it (a Reset row); never under a finger.- (void)readNumber;@@ -428,12 +435,9 @@ static UIFont *tabular(UIFont *font) {static const CGFloat kSliderTop = 12, kSliderGap = 6, kSliderHeight = 28, kSliderBottom = 10;-// The lines are as tall as Dynamic Type makes the fonts.-static CGFloat titleLine(void) { return ceil(SGTitleFont().lineHeight); }-static CGFloat subtitleLine(void) { return ceil(SGSubtitleFont().lineHeight); }--+ (CGFloat)heightFor:(SGModRow *)row {- return kSliderTop + titleLine() + (row.subtitle ? subtitleLine() : 0) + kSliderGap + kSliderHeight + kSliderBottom;+// The text is as tall as Dynamic Type makes it at the cell's width, less its 16pt sides.++ (CGFloat)heightFor:(SGModRow *)row width:(CGFloat)width {+ return kSliderTop + SGSliderTextHeight(row.title, row.subtitle, width - 32) + kSliderGap + kSliderHeight + kSliderBottom;}- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)identifier {@@ -488,16 +492,8 @@ static CGFloat subtitleLine(void) { return ceil(SGSubtitleFont().lineHeight); }- (void)layoutSubviews {[super layoutSubviews];- CGFloat width = self.contentView.bounds.size.width, side = 16, y = kSliderTop;- [_value sizeToFit];- CGFloat valueWidth = MAX(_value.bounds.size.width, 44);- _value.frame = CGRectMake(width - side - valueWidth, y, valueWidth, titleLine());- _title.frame = CGRectMake(side, y, CGRectGetMinX(_value.frame) - side - 8, titleLine());- y += titleLine();- if (_row.subtitle) {- _subtitle.frame = CGRectMake(side, y, width - 2 * side, subtitleLine());- y += subtitleLine();- }+ CGFloat width = self.contentView.bounds.size.width, side = 16;+ CGFloat y = SGLayOutSliderText(_title, _value, _subtitle, side, kSliderTop, width - 2 * side);_slider.frame = CGRectMake(side, y + kSliderGap, width - 2 * side, kSliderHeight);}@@ -794,6 +790,13 @@ static void showWaiting(UITableViewCell *cell, BOOL waiting, NSString *switchTitfor (UITableViewCell *cell in self.tableView.visibleCells) {if (![self.tableView indexPathForCell:cell]) continue; // a row fading outSGModRow *row = [self rowAt:[self.tableView indexPathForCell:cell]];+ if (SGAccessibilityTextSize() && row.value && !row.number+ && [cell.contentConfiguration isKindOfClass:UIListContentConfiguration.class]) {+ UIListContentConfiguration *content = (UIListContentConfiguration *)cell.contentConfiguration;+ content.secondaryText = stackedValue(row);+ cell.contentConfiguration = content;+ continue;+ }if (row.page && row.value) {// valueAndChevron is sized to its text, so a new text gets a new one.NSString *text = row.value();@@ -830,7 +833,7 @@ static void showWaiting(UITableViewCell *cell, BOOL waiting, NSString *switchTit// A slider row is laid out by hand; every other row sizes itself.- (CGFloat)tableView:(UITableView *)table heightForRowAtIndexPath:(NSIndexPath *)path {SGModRow *row = [self rowAt:path];- return row.number ? [SGModSliderCell heightFor:row] : UITableViewAutomaticDimension;+ return row.number ? [SGModSliderCell heightFor:row width:table.bounds.size.width - table.layoutMargins.left - table.layoutMargins.right] : UITableViewAutomaticDimension;}// A section with no row showing has no heading, note or gap: they would sit over no card.@@ -845,7 +848,7 @@ static void showWaiting(UITableViewCell *cell, BOOL waiting, NSString *switchTit- (CGFloat)tableView:(UITableView *)table heightForHeaderInSection:(NSInteger)section {if ([self isEmpty:section]) return CGFLOAT_MIN;- return _sections[(NSUInteger)section].title ? SGSectionHeaderHeight : SGSectionGap;+ return _sections[(NSUInteger)section].title ? SGSectionHeaderHeight() : SGSectionGap;}- (UIView *)tableView:(UITableView *)table viewForFooterInSection:(NSInteger)section {@@ -870,6 +873,7 @@ static void showWaiting(UITableViewCell *cell, BOOL waiting, NSString *switchTitUITableViewCell *cell = SGDequeueCell(table, @"row");SGFillCell(cell, row.title, row.subtitle, row.color, row.symbol);UIListContentConfiguration *content = (UIListContentConfiguration *)cell.contentConfiguration;+ if (SGAccessibilityTextSize() && row.value) content.secondaryText = stackedValue(row);if (row.color) content.secondaryTextProperties.color = row.color;BOOL tile = row.symbol && !row.color && self.tiles;if (tile) content.image = row.tint ? SGTileImageTinted(row.symbol, row.tint) : SGTileImage(row.symbol);@@ -903,13 +907,13 @@ static void showWaiting(UITableViewCell *cell, BOOL waiting, NSString *switchTitcell.accessoryView = row.info ? [self infoButtonBeside:toggle] : toggle;cell.selectionStyle = locked ? UITableViewCellSelectionStyleDefault : UITableViewCellSelectionStyleNone;} else if (row.page) {- UIView *link = row.value ? valueAndChevron(row.value()) : SGChevronView();+ UIView *link = row.value && !SGAccessibilityTextSize() ? valueAndChevron(row.value()) : SGChevronView();cell.accessoryView = row.info ? [self infoButtonBeside:link] : link;cell.selectionStyle = UITableViewCellSelectionStyleDefault;} else if (row.menu) {cell.accessoryView = [self menuButtonFor:row];} else if (row.value) {- cell.accessoryView = valueView(row);+ cell.accessoryView = SGAccessibilityTextSize() ? nil : valueView(row);cell.selectionStyle = row.action ? UITableViewCellSelectionStyleDefault : UITableViewCellSelectionStyleNone;} else if (row.action) {cell.selectionStyle = UITableViewCellSelectionStyleDefault;@@ -955,7 +959,8 @@ static void showWaiting(UITableViewCell *cell, BOOL waiting, NSString *switchTit[items addObject:item];}];UIButtonConfiguration *look = [UIButtonConfiguration plainButtonConfiguration];- look.attributedTitle = [[NSAttributedString alloc] initWithString:current ?: @"" attributes:@{NSFontAttributeName: SGTitleFont()}];+ NSString *shown = SGAccessibilityTextSize() ? nil : current; // under the title instead+ look.attributedTitle = shown ? [[NSAttributedString alloc] initWithString:shown attributes:@{NSFontAttributeName: SGTitleFont()}] : nil;look.image = [UIImage systemImageNamed:@"chevron.up.chevron.down" withConfiguration:[UIImageSymbolConfiguration configurationWithPointSize:11 weight:UIImageSymbolWeightSemibold]];look.imagePlacement = NSDirectionalRectEdgeTrailing;look.imagePadding = 5;diff --git a/tweak/Sources/Settings/SGPage.m b/tweak/Sources/Settings/SGPage.mindex 90c6634c..a9315092 100644--- a/tweak/Sources/Settings/SGPage.m+++ b/tweak/Sources/Settings/SGPage.m@@ -23,6 +23,12 @@ static BOOL sg_pagesConform;self.tableView.sectionHeaderTopPadding = 0;}+- (void)traitCollectionDidChange:(UITraitCollection *)previous {+ [super traitCollectionDidChange:previous];+ if (![previous.preferredContentSizeCategory isEqualToString:self.traitCollection.preferredContentSizeCategory])+ [self.tableView reloadData];+}+- (NSString *)spt_pageIdentifier {return @"spotifyglass";}diff --git a/tweak/Sources/Settings/SGPageStyle.h b/tweak/Sources/Settings/SGPageStyle.hindex fbc47239..d008dfd8 100644--- a/tweak/Sources/Settings/SGPageStyle.h+++ b/tweak/Sources/Settings/SGPageStyle.h@@ -1,16 +1,27 @@// The look of every page of the mod's, in the dark appearance: cards of #1C1C1E on black, 13pt titles over 11pt// grey subtitles in Spotify's typeface, 11pt uppercase section headers and notes, a white symbol on a coloured// rounded square leading a row, white chevrons, switches in the look's accent colour. The text follows Dynamic-// Type up to the largest size before the accessibility ones, and the app font of Shared/Fonts.+// Type through the accessibility sizes, and the app font of Shared/Fonts.#import <UIKit/UIKit.h>UIColor *SGGrey(void); // the secondary label's greyUIColor *SGGreen(void);+UIColor *SGOnAccent(void); // black or white text on the accent+UIColor *SGAccentMark(void); // a visible accent mark on a dark cardUIColor *SGRed(void);UIColor *SGPageBackground(void);UIColor *SGCardBackground(void);UIFont *SGTitleFont(void); // a row's title and value, 13ptUIFont *SGSubtitleFont(void); // subtitles, section headers, footers and notes, 11pt+// Both grow through the accessibility sizes with no cap. A control beside a row's title, or text inside a+// drawing of fixed size, caps its copy so the title keeps its room.+UIFont *SGCappedFont(UIFont *font, CGFloat largest);+BOOL SGAccessibilityTextSize(void); // an accessibility size, where a row's value goes under its title+// A slider row's text, laid out by hand: the title with its value at the trailing edge, or at the accessibility+// sizes the title wrapped across the row with the value under it, then the subtitle when it has one. The+// layout returns the y under the text; the height is the same text measured at the same width.+CGFloat SGSliderTextHeight(NSString *title, NSString *subtitle, CGFloat width);+CGFloat SGLayOutSliderText(UILabel *title, UILabel *value, UILabel *subtitle, CGFloat x, CGFloat y, CGFloat width);// Takes the 13pt title font off Spotify's own settings list, once, for the Mod Settings row the mod adds to it// (App/ModSettings.x), which reads as one of Spotify's rows; SGSpotifyListFont hands it out.void SGAdoptFonts(UIView *list, UIView *exclude);@@ -30,7 +41,7 @@ void SGFitNote(UITableView *table, UIView *wrapper, CGFloat top, CGFloat bottom)// The now playing bar and the tab bar float over the content, so a page insets itself under them.void SGInsetForBars(UITableView *table);-extern const CGFloat SGSectionHeaderHeight;+CGFloat SGSectionHeaderHeight(void); // grows with the header's textextern const CGFloat SGSectionGap; // above a section with no header, so its card does not touch the one beforevoid SGFillCell(UITableViewCell *cell, NSString *title, NSString *subtitle, UIColor *color, NSString *symbolName);UIView *SGSectionHeader(UITableView *table, NSString *title);diff --git a/tweak/Sources/Settings/SGPageStyle.m b/tweak/Sources/Settings/SGPageStyle.mindex 762db5bf..4cf03c72 100644--- a/tweak/Sources/Settings/SGPageStyle.m+++ b/tweak/Sources/Settings/SGPageStyle.m@@ -7,15 +7,61 @@ static UIFont *sg_spotifyFont;UIColor *SGGrey(void) { return [UIColor colorWithRed:0xEB / 255.0 green:0xEB / 255.0 blue:0xF5 / 255.0 alpha:0.6]; }// Spotify's typeface at the sizes of its own lists, asked for by name so the app font of Shared/Fonts follows,-// and the system font before Spotify has registered it. Grown with Dynamic Type no further than xxxLarge:-// some rows are laid out by hand from these fonts, and the accessibility sizes would outgrow them.-static UIFont *scaled(UIFontTextStyle style, CGFloat size, CGFloat largest) {+// and the system font before Spotify has registered it. Grown with Dynamic Type through the accessibility+// sizes, with no cap: the rows laid out by hand measure their text from these fonts.+static UIFont *scaled(UIFontTextStyle style, CGFloat size) {UIFont *font = [UIFont fontWithName:@"SpotifyMixUI-Regular" size:size] ?: [UIFont systemFontOfSize:size];- return [[UIFontMetrics metricsForTextStyle:style] scaledFontForFont:font maximumPointSize:largest];+ return [[UIFontMetrics metricsForTextStyle:style] scaledFontForFont:font];+}++UIFont *SGTitleFont(void) { return scaled(UIFontTextStyleBody, 13); }+UIFont *SGSubtitleFont(void) { return scaled(UIFontTextStyleFootnote, 11); }+UIFont *SGCappedFont(UIFont *font, CGFloat largest) {+ return font.pointSize > largest ? [font fontWithSize:largest] : font;+}++BOOL SGAccessibilityTextSize(void) {+ return UIContentSizeCategoryIsAccessibilityCategory(UIApplication.sharedApplication.preferredContentSizeCategory);+}++static CGFloat textHeight(NSString *text, UIFont *font, CGFloat width) {+ if (!text.length) return 0;+ return ceil([text boundingRectWithSize:CGSizeMake(MAX(1, width), CGFLOAT_MAX) options:NSStringDrawingUsesLineFragmentOrigin+ attributes:@{NSFontAttributeName: font} context:nil].size.height);+}++CGFloat SGSliderTextHeight(NSString *title, NSString *subtitle, CGFloat width) {+ CGFloat line = ceil(SGTitleFont().lineHeight);+ CGFloat height = SGAccessibilityTextSize() ? textHeight(title, SGTitleFont(), width) + line : line;+ return height + textHeight(subtitle, SGSubtitleFont(), width);+}++CGFloat SGLayOutSliderText(UILabel *title, UILabel *value, UILabel *subtitle, CGFloat x, CGFloat y, CGFloat width) {+ CGFloat line = ceil(title.font.lineHeight);+ BOOL stacked = SGAccessibilityTextSize();+ title.numberOfLines = stacked ? 0 : 1;+ value.textAlignment = stacked ? NSTextAlignmentNatural : NSTextAlignmentRight;+ if (stacked) {+ CGFloat height = textHeight(title.text, title.font, width);+ title.frame = CGRectMake(x, y, width, height);+ y += height;+ value.frame = CGRectMake(x, y, width, line);+ } else {+ [value sizeToFit];+ CGFloat valueWidth = MIN(width, MAX(value.bounds.size.width, 44));+ value.frame = CGRectMake(x + width - valueWidth, y, valueWidth, line);+ title.frame = CGRectMake(x, y, MAX(1, CGRectGetMinX(value.frame) - x - 8), line);+ }+ y += line;+ if (subtitle && !subtitle.hidden && subtitle.text.length) {+ subtitle.numberOfLines = 0;+ CGFloat height = textHeight(subtitle.text, subtitle.font, width);+ subtitle.frame = CGRectMake(x, y, width, height);+ y += height;+ }+ return y;}-UIFont *SGTitleFont(void) { return scaled(UIFontTextStyleBody, 13, 18); }-UIFont *SGSubtitleFont(void) { return scaled(UIFontTextStyleFootnote, 11, 15); }UIFont *SGSpotifyListFont(void) { return sg_spotifyFont ?: [UIFont systemFontOfSize:13 weight:UIFontWeightBold]; }UIImageView *SGSymbolView(NSString *name, CGFloat size, UIImageSymbolWeight weight, CGFloat box) {@@ -32,6 +78,7 @@ UIView *SGNote(NSString *text) {UILabel *label = [UILabel new];label.text = text;label.font = SGSubtitleFont();+ label.adjustsFontForContentSizeCategory = YES;label.textColor = SGGrey();label.numberOfLines = 0;UIView *wrapper = [UIView new];@@ -44,6 +91,7 @@ UIView *SGNote(NSString *text) {// loop forever.void SGFitNote(UITableView *table, UIView *wrapper, CGFloat top, CGFloat bottom) {UILabel *label = wrapper.subviews.firstObject;+ label.font = SGSubtitleFont();CGFloat inset = table.layoutMargins.left;CGFloat width = table.bounds.size.width - 2 * inset;CGFloat height = ceil([label sizeThatFits:CGSizeMake(width, CGFLOAT_MAX)].height);@@ -90,6 +138,24 @@ static UIColor *lookAccent(void) {}UIColor *SGGreen(void) { return lookAccent() ?: [UIColor colorWithRed:0x1E / 255.0 green:0xD7 / 255.0 blue:0x60 / 255.0 alpha:1]; }+// Relative sRGB luminance, shared by filled controls and small marks on the dark cards.+static CGFloat luminance(UIColor *color) {+ CGFloat r = 0, g = 0, b = 0, a = 1;+ [color getRed:&r green:&g blue:&b alpha:&a];+ CGFloat (^linear)(CGFloat) = ^CGFloat(CGFloat c) { return c <= 0.04045 ? c / 12.92 : pow((c + 0.055) / 1.055, 2.4); };+ return 0.2126 * linear(r) + 0.7152 * linear(g) + 0.0722 * linear(b);+}++UIColor *SGOnAccent(void) {+ CGFloat light = luminance(SGGreen());+ return (light + 0.05) / 0.05 >= 1.05 / (light + 0.05) ? UIColor.blackColor : UIColor.whiteColor;+}++UIColor *SGAccentMark(void) {+ CGFloat contrast = (luminance(SGGreen()) + 0.05) / (luminance(SGCardBackground()) + 0.05);+ return contrast >= (UIAccessibilityDarkerSystemColorsEnabled() ? 4.5 : 3) ? SGGreen() : UIColor.whiteColor;+}+// The dark appearance's system red, and its grouped background and the cards on it, whichever look runs.UIColor *SGRed(void) { return [UIColor colorWithRed:0xFF / 255.0 green:0x45 / 255.0 blue:0x3A / 255.0 alpha:1]; }UIColor *SGPageBackground(void) { return UIColor.blackColor; }@@ -125,7 +191,7 @@ UIImageView *SGChevronView(void) {return SGSymbolView(@"chevron.right", 13, UIImageSymbolWeightBold, 16);}-const CGFloat SGSectionHeaderHeight = 38;+CGFloat SGSectionHeaderHeight(void) { return MAX(38, ceil(SGSubtitleFont().lineHeight) + 14); }const CGFloat SGSectionGap = 20;// Every page below draws the same row: a 13pt white title over an 11pt grey subtitle in Spotify's typeface,@@ -155,12 +221,13 @@ UIView *SGSectionHeader(UITableView *table, NSString *title) {UILabel *label = [UILabel new];label.text = title.uppercaseString;label.font = SGSubtitleFont();+ label.adjustsFontForContentSizeCategory = YES;label.textColor = SGGrey();// On the header's foot, 7pt over the card, however tall Dynamic Type makes the line.CGFloat height = ceil(label.font.lineHeight);- label.frame = CGRectMake(16, SGSectionHeaderHeight - 7 - height, table.bounds.size.width - 32, height);+ label.frame = CGRectMake(16, SGSectionHeaderHeight() - 7 - height, table.bounds.size.width - 32, height);label.autoresizingMask = UIViewAutoresizingFlexibleWidth;- UIView *header = [[UIView alloc] initWithFrame:CGRectMake(0, 0, table.bounds.size.width, SGSectionHeaderHeight)];+ UIView *header = [[UIView alloc] initWithFrame:CGRectMake(0, 0, table.bounds.size.width, SGSectionHeaderHeight())];[header addSubview:label];return header;}@@ -181,6 +248,7 @@ UIView *SGSectionFooter(UITableView *table, NSString *text) {UILabel *label = [UILabel new];label.text = text;label.font = SGSubtitleFont();+ label.adjustsFontForContentSizeCategory = YES;label.textColor = SGGrey();label.numberOfLines = 0;label.frame = CGRectMake(16, kFooterTop, table.bounds.size.width - 32, footerTextHeight(table, text));diff --git a/tweak/Sources/Settings/SGSourcesPage.m b/tweak/Sources/Settings/SGSourcesPage.mindex 331176eb..27a78b4e 100644--- a/tweak/Sources/Settings/SGSourcesPage.m+++ b/tweak/Sources/Settings/SGSourcesPage.m@@ -87,7 +87,7 @@ typedef NS_ENUM(NSInteger, SGSourcesSection) {}- (CGFloat)tableView:(UITableView *)table heightForHeaderInSection:(NSInteger)section {- return section == SGSourcesSectionOn || _off.count ? SGSectionHeaderHeight : CGFLOAT_MIN;+ return section == SGSourcesSectionOn || _off.count ? SGSectionHeaderHeight() : CGFLOAT_MIN;}- (CGFloat)tableView:(UITableView *)table heightForFooterInSection:(NSInteger)section {diff --git a/tweak/Sources/Shared/ArtistBlock/ArtistBlockSettings.m b/tweak/Sources/Shared/ArtistBlock/ArtistBlockSettings.mindex e19f580c..e3efc6ad 100644--- a/tweak/Sources/Shared/ArtistBlock/ArtistBlockSettings.m+++ b/tweak/Sources/Shared/ArtistBlock/ArtistBlockSettings.m@@ -55,7 +55,7 @@ typedef NS_ENUM(NSInteger, SGArtistSection) {}- (CGFloat)tableView:(UITableView *)table heightForHeaderInSection:(NSInteger)section {- return section == SGArtistSectionMode || section == SGArtistSectionList ? SGSectionHeaderHeight : SGSectionGap;+ return section == SGArtistSectionMode || section == SGArtistSectionList ? SGSectionHeaderHeight() : SGSectionGap;}- (CGFloat)tableView:(UITableView *)table heightForFooterInSection:(NSInteger)section {diff --git a/tweak/Sources/Shared/AudioEffects/AudioEffectsPage.m b/tweak/Sources/Shared/AudioEffects/AudioEffectsPage.mindex 5a0e2573..c9e5b511 100644--- a/tweak/Sources/Shared/AudioEffects/AudioEffectsPage.m+++ b/tweak/Sources/Shared/AudioEffects/AudioEffectsPage.m@@ -279,12 +279,8 @@ static UIFont *tabular(UIFont *font) {- (void)layoutSubviews {[super layoutSubviews];CGFloat width = self.contentView.bounds.size.width, side = 16;- [_value sizeToFit];- CGFloat valueWidth = MAX(_value.bounds.size.width, 44);- CGFloat line = ceil(_title.font.lineHeight); // as tall as Dynamic Type makes the title- _value.frame = CGRectMake(width - side - valueWidth, 12, valueWidth, line);- _title.frame = CGRectMake(side, 12, CGRectGetMinX(_value.frame) - side - 8, line);- _slider.frame = CGRectMake(side, 12 + line + 6, width - 2 * side, 28);+ CGFloat y = SGLayOutSliderText(_title, _value, nil, side, 12, width - 2 * side);+ _slider.frame = CGRectMake(side, y + 6, width - 2 * side, 28);}- (void)moved {@@ -534,7 +530,9 @@ static UIFont *tabular(UIFont *font) {// The heads, the values and the errors size themselves; a nil row would read as a slider.SGDSPRow *row = [self rowAt:path];if (!row) return UITableViewAutomaticDimension;- if (row.kind == SGDSPRowSlider) return 12 + ceil(SGTitleFont().lineHeight) + 6 + 28 + 10;+ // As SGDSPSliderCell lays it out: its text at the cell's width, which the table's margins inset, less 16pt sides.+ CGFloat text = table.bounds.size.width - table.layoutMargins.left - table.layoutMargins.right - 32;+ if (row.kind == SGDSPRowSlider) return 12 + SGSliderTextHeight(row.title, nil, text) + 6 + 28 + 10;if (row.kind == SGDSPRowCurve) return [SGDSPCurveView heightForKey:row.key];return UITableViewAutomaticDimension;}diff --git a/tweak/Sources/Shared/AudioEffects/AudioEffectsPresetsPage.m b/tweak/Sources/Shared/AudioEffects/AudioEffectsPresetsPage.mindex 3c99a54b..a1a7a418 100644--- a/tweak/Sources/Shared/AudioEffects/AudioEffectsPresetsPage.m+++ b/tweak/Sources/Shared/AudioEffects/AudioEffectsPresetsPage.m@@ -15,7 +15,7 @@ static void showAlert(UIViewController *owner, NSString *title, NSString *messagstatic void tick(UITableViewCell *cell, BOOL on) {if (on) {UIImageView *tick = SGSymbolView(@"checkmark", 13, UIImageSymbolWeightSemibold, 16);- tick.tintColor = SGGreen();+ tick.tintColor = SGAccentMark();cell.accessoryView = tick;}cell.accessibilityTraits = on ? UIAccessibilityTraitButton | UIAccessibilityTraitSelected : UIAccessibilityTraitButton;@@ -95,7 +95,7 @@ static NSArray<NSString *> *userPresetNames(void) {}- (CGFloat)tableView:(UITableView *)table heightForHeaderInSection:(NSInteger)section {- return section == 2 ? SGSectionGap : SGSectionHeaderHeight;+ return section == 2 ? SGSectionGap : SGSectionHeaderHeight();}- (UIView *)tableView:(UITableView *)table viewForFooterInSection:(NSInteger)section {@@ -364,7 +364,7 @@ static BOOL headphoneInUse(void) {- (CGFloat)tableView:(UITableView *)table heightForHeaderInSection:(NSInteger)section {if (section == SGDSPHeadphoneSearch) return kSearchTop + 44 + 4;if ([self tableView:table numberOfRowsInSection:section] == 0) return CGFLOAT_MIN;- return section == SGDSPHeadphoneRemembered ? SGSectionHeaderHeight : SGSectionGap;+ return section == SGDSPHeadphoneRemembered ? SGSectionHeaderHeight() : SGSectionGap;}- (NSString *)outputFooter {diff --git a/tweak/Sources/Shared/AudioEffects/SGDSPCurveView.m b/tweak/Sources/Shared/AudioEffects/SGDSPCurveView.mindex 88729ea4..68e9085b 100644--- a/tweak/Sources/Shared/AudioEffects/SGDSPCurveView.m+++ b/tweak/Sources/Shared/AudioEffects/SGDSPCurveView.m@@ -4,9 +4,10 @@#import "AudioEffects.h"enum { kPoints = 128 }; // along the curve, log spaced from 20 Hz to 20 kHz-static const CGFloat kBarHeight = 36; // the presets and Reset, over the plotstatic const CGFloat kInset = 9; // above the top line and under the bottom one, where a handle at the limit sitsstatic const CGFloat kLabelsHeight = 26; // the bands' frequencies under the plot+// The presets and Reset, over the plot: 36pt, or as tall as Dynamic Type makes their text.+static CGFloat barHeight(void) { return MAX(36, ceil(SGTitleFont().lineHeight) + 12); }static const CGFloat kSide = 16; // the row's margins, the same as the text rows'static const CGFloat kGutter = 22; // the scale's numbers, right of the plotstatic const CGFloat kGrab = 28; // how far above or below a handle a finger still takes it@@ -86,7 +87,7 @@ static NSString *signedNumber(double value, int decimals) {+ (CGFloat)heightForKey:(NSString *)key {CGFloat plot = [key isEqualToString:SGKeyDSPCompanderGains] ? 112 : 144;- return kBarHeight + kInset + plot + kInset + kLabelsHeight;+ return barHeight() + kInset + plot + kInset + kLabelsHeight;}- (instancetype)initWithKey:(NSString *)key {@@ -239,7 +240,7 @@ static NSString *signedNumber(double value, int decimals) {// Where the grid's top and bottom lines run: the limits.- (CGRect)plotRect {CGSize size = self.bounds.size;- CGFloat top = kBarHeight + kInset, bottom = size.height - kLabelsHeight - kInset;+ CGFloat top = barHeight() + kInset, bottom = size.height - kLabelsHeight - kInset;return CGRectMake(kSide, top, MAX(size.width - kSide - kGutter - kSide, 1), MAX(bottom - top, 1));}@@ -271,16 +272,16 @@ static NSString *signedNumber(double value, int decimals) {CGFloat width = self.bounds.size.width;[_reset sizeToFit];- _reset.frame = CGRectMake(width - kSide - _reset.bounds.size.width, 0, _reset.bounds.size.width, kBarHeight);+ _reset.frame = CGRectMake(width - kSide - _reset.bounds.size.width, 0, _reset.bounds.size.width, barHeight());// Measured here: a button's configuration catches up with a new title only on its next pass, so// sizeToFit would still be fitting the old name.if (_presets) {NSString *title = _presets.configuration.title ?: @"";CGFloat needed = ceil([title sizeWithAttributes:@{NSFontAttributeName: SGTitleFont()}].width) + 5 + 12;- _presets.frame = CGRectMake(kSide, 0, MIN(needed, width / 2), kBarHeight);+ _presets.frame = CGRectMake(kSide, 0, MIN(needed, width / 2), barHeight());}_name.font = SGTitleFont();- _name.frame = CGRectMake(kSide, 0, width / 2, kBarHeight);+ _name.frame = CGRectMake(kSide, 0, width / 2, barHeight());[CATransaction begin];[CATransaction setDisableActions:YES];diff --git a/tweak/Sources/Shared/Flags/FlagsPage.m b/tweak/Sources/Shared/Flags/FlagsPage.mindex 9cdd2e20..c055da25 100644--- a/tweak/Sources/Shared/Flags/FlagsPage.m+++ b/tweak/Sources/Shared/Flags/FlagsPage.m@@ -109,7 +109,10 @@ static NSString *flagState(const SGFlagDef *flag, id value) {UISegmentedControl *control = [[UISegmentedControl alloc] initWithItems:@[@"Auto", @"Off", @"On"]];control.selectedSegmentIndex = value ? ([value boolValue] ? 2 : 1) : 0;control.selectedSegmentTintColor = SGGreen();- [control setTitleTextAttributes:@{NSForegroundColorAttributeName: UIColor.whiteColor, NSFontAttributeName: SGSubtitleFont()} forState:UIControlStateNormal];+ // Capped, so the segments leave the flag's name its room at the accessibility sizes.+ UIFont *font = SGCappedFont(SGSubtitleFont(), 15);+ [control setTitleTextAttributes:@{NSForegroundColorAttributeName: UIColor.whiteColor, NSFontAttributeName: font} forState:UIControlStateNormal];+ [control setTitleTextAttributes:@{NSForegroundColorAttributeName: SGOnAccent(), NSFontAttributeName: font} forState:UIControlStateSelected];control.tag = path.row;[control addTarget:self action:@selector(segmentChanged:) forControlEvents:UIControlEventValueChanged];[control sizeToFit];diff --git a/tweak/Sources/Shared/Fonts/FontImport.m b/tweak/Sources/Shared/Fonts/FontImport.mindex 0f3a5ef1..e506b9dc 100644--- a/tweak/Sources/Shared/Fonts/FontImport.m+++ b/tweak/Sources/Shared/Fonts/FontImport.m@@ -278,7 +278,7 @@ typedef NS_ENUM(NSInteger, SGFontSection) { SGFontBuiltIn, SGFontMore, SGFontYou}- (CGFloat)tableView:(UITableView *)table heightForHeaderInSection:(NSInteger)section {- return section == SGFontBuiltIn ? SGSectionGap : SGSectionHeaderHeight;+ return section == SGFontBuiltIn ? SGSectionGap : SGSectionHeaderHeight();}- (UITableViewCell *)tableView:(UITableView *)table cellForRowAtIndexPath:(NSIndexPath *)path {diff --git a/tweak/Sources/Shared/Gestures/GesturesSettings.m b/tweak/Sources/Shared/Gestures/GesturesSettings.mindex 44429d90..9e10f6d9 100644--- a/tweak/Sources/Shared/Gestures/GesturesSettings.m+++ b/tweak/Sources/Shared/Gestures/GesturesSettings.m@@ -54,7 +54,7 @@ static NSString *cellLabel(SGGestureAction action) {}while (_labels.count < zones.count) {UILabel *label = [UILabel new];- label.font = SGSubtitleFont();+ label.font = SGCappedFont(SGSubtitleFont(), 15); // inside a drawing of the screen, of fixed sizelabel.textColor = UIColor.whiteColor;label.textAlignment = NSTextAlignmentCenter;label.numberOfLines = 2;@@ -178,7 +178,7 @@ static NSString *cellLabel(SGGestureAction action) {}- (CGFloat)tableView:(UITableView *)table heightForHeaderInSection:(NSInteger)section {- return section == 1 || section == 2 ? SGSectionHeaderHeight : SGSectionGap;+ return section == 1 || section == 2 ? SGSectionHeaderHeight() : SGSectionGap;}- (CGFloat)tableView:(UITableView *)table heightForFooterInSection:(NSInteger)section {diff --git a/tweak/Sources/Shared/HeadGestures/HeadGesturesTeach.m b/tweak/Sources/Shared/HeadGestures/HeadGesturesTeach.mindex cce7577f..10d93570 100644--- a/tweak/Sources/Shared/HeadGestures/HeadGesturesTeach.m+++ b/tweak/Sources/Shared/HeadGestures/HeadGesturesTeach.m@@ -128,7 +128,7 @@ static BOOL headOffset(double *pitch, double *yaw) {NSMutableArray<CAShapeLayer *> *ticks = [NSMutableArray array];for (NSInteger i = 0; i < kTicks; i++) {CAShapeLayer *tick = [CAShapeLayer layer];- tick.strokeColor = SGGreen().CGColor;+ tick.strokeColor = SGAccentMark().CGColor;tick.lineWidth = kTickWidth;tick.lineCap = kCALineCapRound;tick.opacity = 0;@@ -146,7 +146,7 @@ static BOOL headOffset(double *pitch, double *yaw) {[self.layer addSublayer:_dot];_check = SGSymbolView(@"checkmark", 34, UIImageSymbolWeightSemibold, 44);- _check.tintColor = SGGreen();+ _check.tintColor = SGAccentMark();_check.hidden = YES;[self addSubview:_check];@@ -287,7 +287,7 @@ static BOOL headOffset(double *pitch, double *yaw) {config.cornerStyle = UIButtonConfigurationCornerStyleCapsule;if (prominent) {config.baseBackgroundColor = SGGreen();- config.baseForegroundColor = UIColor.blackColor;+ config.baseForegroundColor = SGOnAccent();} else {config.baseForegroundColor = UIColor.whiteColor;}diff --git a/tweak/Sources/Shared/LocalFiles/LocalLyricsPage.m b/tweak/Sources/Shared/LocalFiles/LocalLyricsPage.mindex 3d308102..4d00d812 100644--- a/tweak/Sources/Shared/LocalFiles/LocalLyricsPage.m+++ b/tweak/Sources/Shared/LocalFiles/LocalLyricsPage.m@@ -80,7 +80,7 @@ static NSString *playingLocalFile(void) {}- (CGFloat)tableView:(UITableView *)table heightForHeaderInSection:(NSInteger)section {- return section == 0 ? SGSectionHeaderHeight : SGSectionGap;+ return section == 0 ? SGSectionHeaderHeight() : SGSectionGap;}- (UIView *)tableView:(UITableView *)table viewForFooterInSection:(NSInteger)section {diff --git a/tweak/Sources/Shared/Navigation/AddTabSheet.m b/tweak/Sources/Shared/Navigation/AddTabSheet.mindex d0edb324..06093f8e 100644--- a/tweak/Sources/Shared/Navigation/AddTabSheet.m+++ b/tweak/Sources/Shared/Navigation/AddTabSheet.m@@ -100,7 +100,7 @@ static void showProblem(UIViewController *page, NSString *title, NSString *messa}- (CGFloat)tableView:(UITableView *)table heightForHeaderInSection:(NSInteger)section {- return SGSectionHeaderHeight;+ return SGSectionHeaderHeight();}- (UIView *)tableView:(UITableView *)table viewForFooterInSection:(NSInteger)section {@@ -310,7 +310,7 @@ static void showProblem(UIViewController *page, NSString *title, NSString *messa- (CGFloat)tableView:(UITableView *)table heightForHeaderInSection:(NSInteger)section {NSString *title = _headers[(NSUInteger)section];- return title.length && _sections[(NSUInteger)section].count ? SGSectionHeaderHeight : SGSectionGap;+ return title.length && _sections[(NSUInteger)section].count ? SGSectionHeaderHeight() : SGSectionGap;}- (BOOL)isLast:(NSInteger)section {@@ -466,7 +466,7 @@ typedef NS_ENUM(NSInteger, SGAddTabSection) {}- (CGFloat)tableView:(UITableView *)table heightForHeaderInSection:(NSInteger)section {- return section == SGAddTabSectionRemove ? SGSectionGap : SGSectionHeaderHeight;+ return section == SGAddTabSectionRemove ? SGSectionGap : SGSectionHeaderHeight();}- (CGFloat)tableView:(UITableView *)table heightForFooterInSection:(NSInteger)section {