enchanted_quill 0.1.1 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5730b8d566d7ed7b273cddb1747f52854e5268da
4
- data.tar.gz: 3393cc15dfcdab0aa9f6db26f507c0fa71601058
3
+ metadata.gz: 1c61fbd123463496f0e1221ea675c6e2e1f7e86e
4
+ data.tar.gz: 70c0a1fee81c53ee6301d4ccdebf5ec788c68422
5
5
  SHA512:
6
- metadata.gz: cdcb55744c301335f38893f1fa0d69b397c2f4e5c0039c442ff7e3c209103c57d96e2ae824f5959e4f94e397e91bd3c965dd39d4bd94c32989f00126c44551ce
7
- data.tar.gz: 014b262a9ac5814addab76c5101f967c551a2efe5ef8933edbdedbcc9045c52dcc79c3e36050de720f3a1063210d4618ff0f69088b10ff33a7cce95feafb5b48
6
+ metadata.gz: 393fc448959a64b60a25a5efe3b63770949e31df6a683d158ebd8193ef2eedbba2fbc30bc5b2cbafd1930700594f07b66f758f243ab65647fa1313c07818139c
7
+ data.tar.gz: bf7013c7100229c1b7837fbe9cbbe837c4e05967687f04d0bfad69aa762cc194c4a94c459ee9918b829d62a50d87f2e64d04b647e1d01d3b4aa9f5d905730a05
data/README.md CHANGED
@@ -37,6 +37,12 @@ label.category_selected_color = UIColor.brownColor.colorWithAlphaComponent(0.5)
37
37
  label.url_color = UIColor.colorWithRed(85.0/255, green: 238.0/255, blue: 151.0/255, alpha: 1)
38
38
  label.url_selected_color = UIColor.colorWithRed(85.0/255, green: 238.0/255, blue: 151.0/255, alpha: 1).colorWithAlphaComponent(0.5)
39
39
 
40
+ # Handle Paragraph Styling
41
+ label.line_spacing = 5
42
+ label.line_height_multiple = 1.5
43
+ label.minimum_line_height = 20
44
+ label.maximum_line_height = 30
45
+
40
46
  label.handle_mention_tap do |mention|
41
47
  p "Mention #{mention}"
42
48
  end
@@ -53,7 +59,7 @@ label.handle_hashtag_tap do |hashtag|
53
59
  p "Hashtag #{hashtag}"
54
60
  end
55
61
  ```
56
- ## Better Performance
62
+ ## Better Performance
57
63
  For better performance use the `customize` block, this basically groups all customizations on the label
58
64
  and refreshes the textContainer once instead of refreshing each time an attribute is set.
59
65
  ```ruby
@@ -102,4 +108,3 @@ Bug reports and pull requests are welcome on GitHub at https://github.com/paddin
102
108
  ## License
103
109
 
104
110
  The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
105
-
@@ -4,7 +4,8 @@ module EnchantedQuill
4
4
  :category_tap_handler, :mention_color, :mention_selected_color,
5
5
  :hashtag_color, :hashtag_selected_color, :category_color,
6
6
  :category_selected_color, :url_color, :url_selected_color,
7
- :line_spacing
7
+ :line_spacing, :line_height_multiple, :minimum_line_height,
8
+ :maximum_line_height
8
9
 
9
10
  def init
10
11
  super.tap do |label|
@@ -175,6 +176,21 @@ module EnchantedQuill
175
176
  update_text_storage(false)
176
177
  end
177
178
 
179
+ def line_height_multiple=(multiple)
180
+ @line_height_multiple = multiple
181
+ update_text_storage(false)
182
+ end
183
+
184
+ def maximum_line_height=(height)
185
+ @maximum_line_height = height
186
+ update_text_storage(false)
187
+ end
188
+
189
+ def minimum_line_height=(height)
190
+ @minimum_line_height = height
191
+ update_text_storage(false)
192
+ end
193
+
178
194
  def touchesBegan(touches, withEvent: event)
179
195
  touches = touches && touches.allObjects
180
196
  touch = touches.first
@@ -199,28 +215,32 @@ module EnchantedQuill
199
215
  super
200
216
  end
201
217
 
202
- # def intrinsicContentSize
203
- # label_height = sizeThatFits(CGSizeMake(CGRectGetWidth(self.frame), Float::MAX)).height
204
- # return CGSizeMake(self.frame.size.width, label_height + self.layoutMargins.top + self.layoutMargins.bottom)
205
- # end
218
+ def intrinsicContentSize
219
+ label_height = sizeThatFits(CGSizeMake(CGRectGetWidth(self.frame), Float::MAX)).height
220
+ return CGSizeMake(self.frame.size.width, label_height + self.layoutMargins.top + self.layoutMargins.bottom)
221
+ end
206
222
 
207
223
  def setup_label
208
- @customizing = false
209
- @active_elements = {}
210
- self.textColor = UIColor.blackColor
211
- self.mention_color = UIColor.blueColor
212
- self.mention_selected_color = UIColor.blueColor.colorWithAlphaComponent(0.5)
213
- self.hashtag_color = UIColor.blueColor
214
- self.hashtag_selected_color = UIColor.blueColor.colorWithAlphaComponent(0.5)
215
- self.category_color = UIColor.brownColor
216
- self.category_selected_color = UIColor.brownColor.colorWithAlphaComponent(0.5)
217
- self.url_color = UIColor.blueColor
218
- self.url_selected_color = UIColor.blueColor.colorWithAlphaComponent(0.5)
219
-
220
- text_storage.addLayoutManager(layout_manager)
221
- layout_manager.addTextContainer(text_container)
222
- text_container.lineFragmentPadding = 0
223
- self.userInteractionEnabled = true
224
+ @setup_label ||= begin
225
+ @customizing = false
226
+ @active_elements = {}
227
+ @height_correction = 0
228
+ self.line_height_multiple = 1
229
+ self.textColor = UIColor.blackColor
230
+ self.mention_color = UIColor.blueColor
231
+ self.mention_selected_color = UIColor.blueColor.colorWithAlphaComponent(0.5)
232
+ self.hashtag_color = UIColor.blueColor
233
+ self.hashtag_selected_color = UIColor.blueColor.colorWithAlphaComponent(0.5)
234
+ self.category_color = UIColor.brownColor
235
+ self.category_selected_color = UIColor.brownColor.colorWithAlphaComponent(0.5)
236
+ self.url_color = UIColor.blueColor
237
+ self.url_selected_color = UIColor.blueColor.colorWithAlphaComponent(0.5)
238
+
239
+ text_storage.addLayoutManager(layout_manager)
240
+ layout_manager.addTextContainer(text_container)
241
+ text_container.lineFragmentPadding = 0
242
+ self.userInteractionEnabled = true
243
+ end
224
244
  end
225
245
 
226
246
  private
@@ -329,12 +349,22 @@ module EnchantedQuill
329
349
 
330
350
  current_paragraph_style = attributes[NSParagraphStyleAttributeName] && attributes[NSParagraphStyleAttributeName].mutableCopy
331
351
  paragraph_style = current_paragraph_style || NSMutableParagraphStyle.alloc.init
332
- paragraph_style.lineBreakMode = NSLineBreakByWordWrapping
333
- paragraph_style.alignment = textAlignment
334
-
335
- if line_spacing
336
- paragraph_style.lineSpacing = line_spacing
337
- end
352
+ paragraph_style.lineBreakMode = NSLineBreakByWordWrapping
353
+ paragraph_style.alignment = textAlignment
354
+ paragraph_style.lineSpacing = line_spacing if line_spacing
355
+ paragraph_style.lineHeightMultiple = line_height_multiple
356
+
357
+ paragraph_style.minimumLineHeight = if minimum_line_height && minimum_line_height > 0
358
+ minimum_line_height
359
+ else
360
+ font.lineHeight * line_height_multiple
361
+ end
362
+
363
+ paragraph_style.maximumLineHeight = if maximum_line_height and maximum_line_height > 0
364
+ maximum_line_height
365
+ else
366
+ font.lineHeight * line_height_multiple
367
+ end
338
368
 
339
369
  attributes[NSParagraphStyleAttributeName] = paragraph_style
340
370
  mut_attr_string.setAttributes(attributes, range: range_pointer[0])
@@ -1,3 +1,3 @@
1
1
  module EnchantedQuill
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: enchanted_quill
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Elom Gomez