Is there a way to constrain the AttributedTextFormattingDefinition of a TextEditor to only bold/italic/underline/strikethrough, without showing the full Font UI?
struct CustomFormattingDefinition: AttributedTextFormattingDefinition {
struct Scope: AttributeScope {
let font: AttributeScopes.SwiftUIAttributes.FontAttribute
let underlineStyle: AttributeScopes.SwiftUIAttributes.UnderlineStyleAttribute
let strikethroughStyle: AttributeScopes.SwiftUIAttributes.StrikethroughStyleAttribute
}
var body: some AttributedTextFormattingDefinition<Scope> {
ValueConstraint(for: \.font,
values: [MyStyle.defaultFont, MyStyle.boldFont, MyStyle.italicFont, MyStyle.boldItalicFont],
default: MyStyle.defaultFont)
ValueConstraint(for: \.underlineStyle,
values: [nil, .single],
default: .single)
ValueConstraint(for: \.strikethroughStyle,
values: [nil, .single],
default: .single)
}
}
If I remove the Font attribute from the scope, the Bold and Italic buttons disappear. And if the Font attribute is defined, even if it's restricted to one typeface in 4 different styles, the full typography UI is displayed.