-
-
Notifications
You must be signed in to change notification settings - Fork 121
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add font size picker config environment support
- Loading branch information
1 parent
ee3134b
commit 009be5d
Showing
17 changed files
with
141 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
Sources/RichTextKit/Fonts/RichTextFont+SizePickerConfig.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
// | ||
// RichTextFont+SizePickerConfig.swift | ||
// RichTextKit | ||
// | ||
// Created by Daniel Saidi on 2024-03-04. | ||
// Copyright © 2024 Daniel Saidi. All rights reserved. | ||
// | ||
|
||
import SwiftUI | ||
|
||
public extension RichTextFont { | ||
|
||
/// This type can configure a ``RichTextFont/SizePicker``. | ||
struct SizePickerConfig { | ||
|
||
/// Create a custom font size picker config. | ||
/// | ||
/// - Parameters: | ||
/// - values: The values to display in the list, by default a standard list. | ||
public init( | ||
values: [CGFloat] = [10, 12, 14, 18, 20, 22, 24, 28, 36, 48, 64, 72, 96, 144] | ||
) { | ||
self.values = values | ||
} | ||
|
||
/// The values to display in the list. | ||
public var values: [CGFloat] | ||
} | ||
} | ||
|
||
public extension RichTextFont.SizePickerConfig { | ||
|
||
/// The standard font size picker configuration. | ||
/// | ||
/// You can set a new value to change the global default. | ||
static var standard = Self() | ||
} | ||
|
||
public extension View { | ||
|
||
/// Apply a ``RichTextFont`` size picker configuration. | ||
func richTextFontSizePickerConfig( | ||
_ config: RichTextFont.SizePickerConfig | ||
) -> some View { | ||
self.environment(\.richTextFontSizePickerConfig, config) | ||
} | ||
} | ||
|
||
private extension RichTextFont.SizePickerConfig { | ||
|
||
struct Key: EnvironmentKey { | ||
|
||
public static var defaultValue: RichTextFont.SizePickerConfig = .standard | ||
} | ||
} | ||
|
||
public extension EnvironmentValues { | ||
|
||
/// This value can bind to a font size picker config. | ||
var richTextFontSizePickerConfig: RichTextFont.SizePickerConfig { | ||
get { self [RichTextFont.SizePickerConfig.Key.self] } | ||
set { self [RichTextFont.SizePickerConfig.Key.self] = newValue } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.