@@ -28,7 +28,7 @@ class DebugLabelViewController: ViewController<DebugLabelView> {
2828 super. viewDidLoad ( )
2929
3030 setup ( )
31- update ( )
31+ updateText ( )
3232 }
3333
3434 private func setup( ) {
@@ -41,24 +41,75 @@ class DebugLabelViewController: ViewController<DebugLabelView> {
4141 }
4242
4343 private func set( info: Debug . Label ) {
44+
45+ func update( _ style: AttributedString . Attribute . ParagraphStyle ) {
46+ paragraphs. removeAll ( where: { $0 ~= style } )
47+ paragraphs. append ( style)
48+ }
49+
50+ func remove( _ style: AttributedString . Attribute . ParagraphStyle ) {
51+ paragraphs. removeAll ( where: { $0 ~= style } )
52+ }
53+
4454 if let value = info. lineSpacing {
45- paragraphs. removeAll ( where: { $0 == . lineSpacing( 0 ) } )
46- paragraphs. append ( . lineSpacing( value) )
55+ update ( . lineSpacing( value) )
4756
4857 } else {
49- paragraphs . removeAll ( where : { $0 == . lineSpacing( 0 ) } )
58+ remove ( . lineSpacing( 0 ) )
5059 }
5160 if let value = info. lineHeightMultiple {
52- paragraphs. removeAll ( where: { $0 == . lineHeightMultiple( 0 ) } )
53- paragraphs. append ( . lineHeightMultiple( value) )
61+ update ( . lineHeightMultiple( value) )
62+
63+ } else {
64+ remove ( . lineHeightMultiple( 0 ) )
65+ }
66+ if let value = info. minimumLineHeight {
67+ update ( . minimumLineHeight( value) )
68+
69+ } else {
70+ remove ( . minimumLineHeight( 0 ) )
71+ }
72+ if let value = info. maximumLineHeight {
73+ update ( . maximumLineHeight( value) )
74+
75+ } else {
76+ remove ( . maximumLineHeight( 0 ) )
77+ }
78+ if let value = info. paragraphSpacing {
79+ update ( . paragraphSpacing( value) )
80+
81+ } else {
82+ remove ( . paragraphSpacing( 0 ) )
83+ }
84+ if let value = info. paragraphSpacingBefore {
85+ update ( . paragraphSpacingBefore( value) )
86+
87+ } else {
88+ remove ( . paragraphSpacingBefore( 0 ) )
89+ }
90+ if let value = info. firstLineHeadIndent {
91+ update ( . firstLineHeadIndent( value) )
92+
93+ } else {
94+ remove ( . firstLineHeadIndent( 0 ) )
95+ }
96+ if let value = info. headIndent {
97+ update ( . headIndent( value) )
98+
99+ } else {
100+ remove ( . headIndent( 0 ) )
101+ }
102+ if let value = info. tailIndent {
103+ update ( . tailIndent( value) )
54104
55105 } else {
56- paragraphs . removeAll ( where : { $0 == . lineHeightMultiple ( 0 ) } )
106+ remove ( . tailIndent ( 0 ) )
57107 }
58108 container. set ( info: info)
109+ updateText ( )
59110 }
60111
61- private func update ( ) {
112+ private func updateText ( ) {
62113 container. set ( text: . init(
63114 attributedString,
64115 with: attributes + [ . paragraph( paragraphs) ]
@@ -121,37 +172,32 @@ class DebugLabelViewController: ViewController<DebugLabelView> {
121172 }
122173
123174 @IBAction func lineSpacingSliderAction( _ sender: UISlider ) {
124- paragraphs. removeAll ( where: { $0 == . lineSpacing( 0 ) } )
125- paragraphs. append ( . lineSpacing( . init( sender. value) ) )
126175 info. lineSpacing = . init( sender. value)
127- update ( )
128176 }
129177 @IBAction func lineHeightMultipleSliderAction( _ sender: UISlider ) {
130- paragraphs. removeAll ( where: { $0 == . lineHeightMultiple( 0 ) } )
131- paragraphs. append ( . lineHeightMultiple( . init( sender. value) ) )
132178 info. lineHeightMultiple = . init( sender. value)
133- update ( )
134179 }
135-
136180 @IBAction func minimumLineHeightSliderAction( _ sender: UISlider ) {
181+ info. minimumLineHeight = . init( sender. value)
137182 }
138183 @IBAction func maximumLineHeightSliderAction( _ sender: UISlider ) {
184+ info. maximumLineHeight = . init( sender. value)
139185 }
140-
141186 @IBAction func paragraphSpacingSliderAction( _ sender: UISlider ) {
187+ info. paragraphSpacing = . init( sender. value)
142188 }
143189 @IBAction func paragraphSpacingBeforeSliderAction( _ sender: UISlider ) {
190+ info. paragraphSpacingBefore = . init( sender. value)
144191 }
145-
146192 @IBAction func firstLineHeadIndentSliderAction( _ sender: UISlider ) {
193+ info. firstLineHeadIndent = . init( sender. value)
147194 }
148-
149195 @IBAction func headIndentSliderAction( _ sender: UISlider ) {
196+ info. headIndent = . init( sender. value)
150197 }
151-
152198 @IBAction func tailIndentSliderAction( _ sender: UISlider ) {
199+ info. tailIndent = . init( sender. value)
153200 }
154-
155201}
156202
157203extension DebugLabelViewController : UIScrollViewDelegate {
0 commit comments