From cd94bfde6784e0be9e66cd447d31282694ff191c Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Thu, 10 Nov 2022 11:25:32 -0600 Subject: [PATCH] added AnylabelAttribute Signed-off-by: Matt Bruce --- VDS.xcodeproj/project.pbxproj | 4 +++ .../Label/Attributes/AnyLabelAttribute.swift | 36 +++++++++++++++++++ 2 files changed, 40 insertions(+) create mode 100644 VDS/Components/Label/Attributes/AnyLabelAttribute.swift diff --git a/VDS.xcodeproj/project.pbxproj b/VDS.xcodeproj/project.pbxproj index 03aa3d87..089a1176 100644 --- a/VDS.xcodeproj/project.pbxproj +++ b/VDS.xcodeproj/project.pbxproj @@ -44,6 +44,7 @@ EA89200628B526D6006B9984 /* CheckboxGroup.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA89200528B526D6006B9984 /* CheckboxGroup.swift */; }; EA89201328B568D8006B9984 /* RadioBox.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA89201228B568D8006B9984 /* RadioBox.swift */; }; EA89201528B56CF4006B9984 /* RadioBoxGroup.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA89201428B56CF4006B9984 /* RadioBoxGroup.swift */; }; + EA978EC5291D6AFE00ACC883 /* AnyLabelAttribute.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA978EC4291D6AFE00ACC883 /* AnyLabelAttribute.swift */; }; EAA5EEB528ECBFB4003B3210 /* ImageLabelAttribute.swift in Sources */ = {isa = PBXBuildFile; fileRef = EAA5EEB428ECBFB4003B3210 /* ImageLabelAttribute.swift */; }; EAA5EEB728ECC03A003B3210 /* ToolTipLabelAttribute.swift in Sources */ = {isa = PBXBuildFile; fileRef = EAA5EEB628ECC03A003B3210 /* ToolTipLabelAttribute.swift */; }; EAA5EEB928ECD24B003B3210 /* Icons.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = EAA5EEB828ECD24B003B3210 /* Icons.xcassets */; }; @@ -130,6 +131,7 @@ EA89200528B526D6006B9984 /* CheckboxGroup.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CheckboxGroup.swift; sourceTree = ""; }; EA89201228B568D8006B9984 /* RadioBox.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RadioBox.swift; sourceTree = ""; }; EA89201428B56CF4006B9984 /* RadioBoxGroup.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RadioBoxGroup.swift; sourceTree = ""; }; + EA978EC4291D6AFE00ACC883 /* AnyLabelAttribute.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AnyLabelAttribute.swift; sourceTree = ""; }; EAA5EEB428ECBFB4003B3210 /* ImageLabelAttribute.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ImageLabelAttribute.swift; sourceTree = ""; }; EAA5EEB628ECC03A003B3210 /* ToolTipLabelAttribute.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ToolTipLabelAttribute.swift; sourceTree = ""; }; EAA5EEB828ECD24B003B3210 /* Icons.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Icons.xcassets; sourceTree = ""; }; @@ -480,6 +482,7 @@ children = ( EAF7F0A3289B017C00B287F5 /* LabelAttributeModel.swift */, EAF7F0B2289B1ADC00B287F5 /* ActionLabelAttribute.swift */, + EA978EC4291D6AFE00ACC883 /* AnyLabelAttribute.swift */, EAF7F13228A2A16500B287F5 /* AttachmentLabelAttributeModel.swift */, EAF7F0B0289B177F00B287F5 /* ColorLabelAttribute.swift */, EAF7F0AA289B13FD00B287F5 /* FontLabelAttribute.swift */, @@ -631,6 +634,7 @@ EAF7F0AF289B144C00B287F5 /* UnderlineLabelAttribute.swift in Sources */, EAC925842911C63100091998 /* Colorable.swift in Sources */, EA3361C5289030FC0071C351 /* Accessable.swift in Sources */, + EA978EC5291D6AFE00ACC883 /* AnyLabelAttribute.swift in Sources */, EA33622C2891E73B0071C351 /* FontProtocol.swift in Sources */, EAF7F11728A1475A00B287F5 /* RadioButton.swift in Sources */, EAB1D2CD28ABE76100DAE764 /* Withable.swift in Sources */, diff --git a/VDS/Components/Label/Attributes/AnyLabelAttribute.swift b/VDS/Components/Label/Attributes/AnyLabelAttribute.swift new file mode 100644 index 00000000..b914c912 --- /dev/null +++ b/VDS/Components/Label/Attributes/AnyLabelAttribute.swift @@ -0,0 +1,36 @@ +// +// AnyAttribute.swift +// VDS +// +// Created by Matt Bruce on 11/10/22. +// + +import Foundation + +public struct AnyAttribute: LabelAttributeModel { + public var id = UUID() + public var location: Int + public var length: Int + public var key: NSAttributedString.Key + public var value: AnyHashable + + public init(location: Int, length: Int, key: NSAttributedString.Key, value: AnyHashable) { + self.location = location + self.length = length + self.key = key + self.value = value + } + + public func isEqual(_ equatable: AnyAttribute) -> Bool { + return id == equatable.id && range == equatable.range && key == equatable.key && value == equatable.value + } + + public static func == (lhs: AnyAttribute, rhs: AnyAttribute) -> Bool { + lhs.isEqual(rhs) + } + + public func setAttribute(on attributedString: NSMutableAttributedString) { + attributedString.removeAttribute(key, range: range) + attributedString.addAttribute(key, value: value, range: range) + } +}