WIP. Issues from language paradigms. Further work to resolve.

This commit is contained in:
Christiano, Kevin 2019-03-31 21:08:11 -04:00
parent c791d78671
commit 27127aacfb

View File

@ -45,10 +45,29 @@ public typealias CoreObjectActionLoadPresentDelegate = MVMCoreActionDelegateProt
} }
// By default, it will follow most of the font standard in zepplin, and should need to be changed // By default, it will follow most of the font standard in zepplin, and should need to be changed
public var normalTextFont: UIFont? = MFStyler.fontB2() public var normalTextFont: UIFont? = MFStyler.fontB2() {
public var actionTextFont: UIFont? = MFStyler.fontB2() didSet(newNormalFont) {
public var normalTextColor: UIColor = .black setAlternateNormalTextAttributes([NSAttributedString.Key.font: newNormalFont as Any])
public var actionTextColor: UIColor = .black }
}
public var actionTextFont: UIFont? = MFStyler.fontB2() {
didSet(newActionFont) {
setAlternateActionTextAttributes([NSAttributedString.Key.font: newActionFont as Any])
}
}
public var normalTextColor: UIColor = .black {
didSet(newNormalColor) {
setAlternateNormalTextAttributes([NSAttributedString.Key.foregroundColor: newNormalColor as Any])
}
}
public var actionTextColor: UIColor = .black {
didSet(newActionColor) {
setAlternateActionTextAttributes([NSAttributedString.Key.foregroundColor: newActionColor as Any])
}
}
public var makeWholeViewClickable = false public var makeWholeViewClickable = false
@ -333,7 +352,7 @@ public typealias CoreObjectActionLoadPresentDelegate = MVMCoreActionDelegateProt
// MARK: - Helper // MARK: - Helper
//------------------------------------------------------ //------------------------------------------------------
private func getTextFromStringComponents() -> String? { private func getTextFromStringComponents() -> String {
if let frontTxt = frontText, !frontTxt.isEmpty { if let frontTxt = frontText, !frontTxt.isEmpty {
frontText?.append(" ") frontText?.append(" ")
@ -392,32 +411,27 @@ public typealias CoreObjectActionLoadPresentDelegate = MVMCoreActionDelegateProt
private func setText(_ text: String?, startTag: String?, endTag: String?) { private func setText(_ text: String?, startTag: String?, endTag: String?) {
guard let actionRange: ActionIndiciesTuple = rangeOfText(text, startTag: startTag, endTag: endTag) else { return } let actionRange: ActionIndiciesTuple = rangeOfText(text, startTag: startTag, endTag: endTag)
frontText = actionRange.revisedText
if let revisedText = actionRange.revisedText, let startBraceIndex = actionRange.startIndex, let endBraceIndex = actionRange.endIndex { if let revisedText = actionRange.revisedText, let startBraceIndex = actionRange.startIndex, let endBraceIndex = actionRange.endIndex {
// TODO: Put some of this into a String Extension in MVMCore
frontText = String(revisedText[revisedText.startIndex..<startBraceIndex]).trimmingCharacters(in: .whitespaces) frontText = String(revisedText[revisedText.startIndex..<startBraceIndex]).trimmingCharacters(in: .whitespaces)
actionText = String(revisedText[startBraceIndex..<endBraceIndex]).trimmingCharacters(in: .whitespaces) actionText = String(revisedText[startBraceIndex..<endBraceIndex]).trimmingCharacters(in: .whitespaces)
backText = String(revisedText[endBraceIndex...]).trimmingCharacters(in: .whitespaces) backText = String(revisedText[endBraceIndex...]).trimmingCharacters(in: .whitespaces)
self.text = getTextFromStringComponents()
} }
self.text = getTextFromStringComponents()
setup() setup()
} }
private func rangeOfText(_ text: String?, startTag: String?, endTag: String?) -> ActionIndiciesTuple? { private func rangeOfText(_ text: String?, startTag: String?, endTag: String?) -> ActionIndiciesTuple {
var fullText = text ?? "" var fullText = text ?? ""
guard let start = startTag, let end = endTag else { return nil }
if !fullText.contains(Character(start)) && !fullText.contains(Character(end)) {
return nil
}
var actionRange: ActionIndiciesTuple var actionRange: ActionIndiciesTuple
if let leftBrace = startTag, let rightBrace = endTag { if let leftBrace = startTag, let rightBrace = endTag, fullText.contains(Character(leftBrace)) && fullText.contains(Character(rightBrace)) {
actionRange.startIndex = fullText.firstIndex(of: Character(leftBrace)) actionRange.startIndex = fullText.firstIndex(of: Character(leftBrace))
fullText = fullText.replacingOccurrences(of: leftBrace, with: "") fullText = fullText.replacingOccurrences(of: leftBrace, with: "")
@ -427,6 +441,7 @@ public typealias CoreObjectActionLoadPresentDelegate = MVMCoreActionDelegateProt
self.text = fullText self.text = fullText
actionRange.revisedText = fullText actionRange.revisedText = fullText
return actionRange return actionRange
} }