Skip to content

Introduce dynamic text styles and various font modifiers #186

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jun 23, 2025

Conversation

stackotter
Copy link
Owner

This PR introduces dynamic text styles with a similar API to SwiftUI. It also expands the existing set of font-related view modifiers, and introduces a set of APIs for constructing new fonts from existing fonts.

The set of text styles supported by SwiftUI differs by platform. I've standardised SwiftCrossUI's text styles on the set of styles supported by SwiftUI on macOS. I've extrapolated values for any text styles that SwiftUI doesn't support on certain platforms.

I've based the font size and weight of each text style off Apple's typography guidelines. By default, the text styles are resolved by SwiftCrossUI and only depend on the backend's reported device class (e.g. desktop, tablet, etc). However, backends can override the text style resolution process if needed.

Example usage of new features

Text("Your Recipes")
    .font(.title.fontWeight(.bold))

Text("Recently Cooked")
    .font(.title2)

ForEach(recentlyCooked) { recipe in
    HStack {
        Text(recipe.name)
            .emphasized()
        Text(recipe.author)
            .fontWeight(.light)
    }

    Text("\(recipe.stars)/5")
        .fontDesign(.monospaced)

    // Alternative approach
    Text("\(recipe.stars)/5")
        .font(.body.monospaced())
}

@stackotter stackotter added the feature A feature request label Jun 17, 2025
@stackotter stackotter force-pushed the dynamic_fonts branch 2 times, most recently from 6937f55 to 5174849 Compare June 23, 2025 12:13
@stackotter stackotter merged commit fa6d364 into main Jun 23, 2025
20 checks passed
@stackotter stackotter deleted the dynamic_fonts branch June 23, 2025 13:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature A feature request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant