Fixed some label initialization issues.
This commit is contained in:
@@ -873,17 +873,6 @@ class MTAccentDisplay : MTDisplay {
|
|||||||
get { super.textColor }
|
get { super.textColor }
|
||||||
}
|
}
|
||||||
|
|
||||||
// func setTextColor(_ textColor:MTColor) {
|
|
||||||
// super.textColor = textColor
|
|
||||||
// accentee?.textColor = textColor
|
|
||||||
// accent?.textColor = textColor
|
|
||||||
// }
|
|
||||||
|
|
||||||
// func setPosition(_ position:CGPoint) {
|
|
||||||
// super.position = position
|
|
||||||
// self.updateAccenteePosition()
|
|
||||||
// }
|
|
||||||
|
|
||||||
override var position: CGPoint {
|
override var position: CGPoint {
|
||||||
set {
|
set {
|
||||||
super.position = newValue
|
super.position = newValue
|
||||||
|
|||||||
@@ -22,8 +22,7 @@ public enum MTMathUILabelMode {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@typedef MTTextAlignment
|
Horizontal text alignment for `MTMathUILabel`.
|
||||||
@brief Horizontal text alignment for `MTMathUILabel`.
|
|
||||||
*/
|
*/
|
||||||
public enum MTTextAlignment : UInt {
|
public enum MTTextAlignment : UInt {
|
||||||
/// Align left.
|
/// Align left.
|
||||||
@@ -47,7 +46,7 @@ public enum MTTextAlignment : UInt {
|
|||||||
When created it uses `[MTFontManager defaultFont]` as its font. This can be changed using
|
When created it uses `[MTFontManager defaultFont]` as its font. This can be changed using
|
||||||
the `font` parameter.
|
the `font` parameter.
|
||||||
*/
|
*/
|
||||||
//@IBDesignable
|
@IBDesignable
|
||||||
public class MTMathUILabel : MTView {
|
public class MTMathUILabel : MTView {
|
||||||
|
|
||||||
/** The `MTMathList` to render. Setting this will remove any
|
/** The `MTMathList` to render. Setting this will remove any
|
||||||
@@ -58,8 +57,9 @@ public class MTMathUILabel : MTView {
|
|||||||
*/
|
*/
|
||||||
var mathList:MTMathList? {
|
var mathList:MTMathList? {
|
||||||
didSet {
|
didSet {
|
||||||
self.error = nil
|
mathList = nil
|
||||||
self.latex = MTMathListBuilder.mathListToString(mathList)
|
error = nil
|
||||||
|
latex = MTMathListBuilder.mathListToString(mathList)
|
||||||
self.invalidateIntrinsicContentSize()
|
self.invalidateIntrinsicContentSize()
|
||||||
self.setNeedsLayout()
|
self.setNeedsLayout()
|
||||||
}
|
}
|
||||||
@@ -69,12 +69,12 @@ public class MTMathUILabel : MTView {
|
|||||||
has been set. If latex has not been set, this will return the latex output for the
|
has been set. If latex has not been set, this will return the latex output for the
|
||||||
`mathList` that is set.
|
`mathList` that is set.
|
||||||
@see error */
|
@see error */
|
||||||
// @IBInspectable
|
@IBInspectable
|
||||||
public var latex = "" {
|
public var latex = "" {
|
||||||
didSet {
|
didSet {
|
||||||
self.error = nil
|
self.error = nil
|
||||||
var error : NSError? = nil
|
var error : NSError? = nil
|
||||||
self.mathList = MTMathListBuilder.build(fromString: latex, error: &error)
|
mathList = MTMathListBuilder.build(fromString: latex, error: &error)
|
||||||
if error != nil {
|
if error != nil {
|
||||||
self.mathList = nil
|
self.mathList = nil
|
||||||
self.error = error
|
self.error = error
|
||||||
@@ -104,7 +104,7 @@ public class MTMathUILabel : MTView {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** Convenience method to just set the size of the font without changing the fontface. */
|
/** Convenience method to just set the size of the font without changing the fontface. */
|
||||||
// @IBInspectable
|
@IBInspectable
|
||||||
public var fontSize = MTFontManager.fontManager.kDefaultFontSize {
|
public var fontSize = MTFontManager.fontManager.kDefaultFontSize {
|
||||||
didSet {
|
didSet {
|
||||||
self.font = font?.copy(withSize: fontSize)
|
self.font = font?.copy(withSize: fontSize)
|
||||||
@@ -112,7 +112,7 @@ public class MTMathUILabel : MTView {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** This sets the text color of the rendered math formula. The default color is black. */
|
/** This sets the text color of the rendered math formula. The default color is black. */
|
||||||
// @IBInspectable
|
@IBInspectable
|
||||||
public var textColor:MTColor? = MTColor.black {
|
public var textColor:MTColor? = MTColor.black {
|
||||||
didSet {
|
didSet {
|
||||||
self.displayList?.textColor = textColor
|
self.displayList?.textColor = textColor
|
||||||
@@ -124,7 +124,7 @@ public class MTMathUILabel : MTView {
|
|||||||
`UIEdgeInsetsZero` by default. This is useful if you need some padding between the math and
|
`UIEdgeInsetsZero` by default. This is useful if you need some padding between the math and
|
||||||
the border/background color. sizeThatFits: will have its returned size increased by these insets.
|
the border/background color. sizeThatFits: will have its returned size increased by these insets.
|
||||||
*/
|
*/
|
||||||
// @IBInspectable
|
@IBInspectable
|
||||||
public var contentInsets = MTEdgeInsetsZero {
|
public var contentInsets = MTEdgeInsetsZero {
|
||||||
didSet {
|
didSet {
|
||||||
self.invalidateIntrinsicContentSize()
|
self.invalidateIntrinsicContentSize()
|
||||||
@@ -171,15 +171,28 @@ public class MTMathUILabel : MTView {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func initCommon() {
|
func initCommon() {
|
||||||
errorLabel = MTLabel()
|
#if os(macOS)
|
||||||
#if os(macOS)
|
|
||||||
self.layer?.isGeometryFlipped = true
|
self.layer?.isGeometryFlipped = true
|
||||||
errorLabel?.layer?.isGeometryFlipped = true
|
#else
|
||||||
#else
|
|
||||||
self.layer.isGeometryFlipped = true
|
self.layer.isGeometryFlipped = true
|
||||||
errorLabel?.layer.isGeometryFlipped = true
|
#endif
|
||||||
#endif
|
fontSize = 20
|
||||||
|
contentInsets = MTEdgeInsetsZero
|
||||||
|
labelMode = .display
|
||||||
|
let font = MTFontManager.fontManager.defaultFont
|
||||||
|
self.font = font
|
||||||
|
textAlignment = .left
|
||||||
|
displayList = nil
|
||||||
|
displayErrorInline = true
|
||||||
self.backgroundColor = MTColor.clear
|
self.backgroundColor = MTColor.clear
|
||||||
|
|
||||||
|
textColor = MTColor.black
|
||||||
|
errorLabel = MTLabel()
|
||||||
|
#if os(macOS)
|
||||||
|
errorLabel?.layer?.isGeometryFlipped = true
|
||||||
|
#else
|
||||||
|
errorLabel?.layer.isGeometryFlipped = true
|
||||||
|
#endif
|
||||||
errorLabel?.isHidden = true
|
errorLabel?.isHidden = true
|
||||||
errorLabel?.textColor = MTColor.red
|
errorLabel?.textColor = MTColor.red
|
||||||
self.addSubview(errorLabel!)
|
self.addSubview(errorLabel!)
|
||||||
@@ -196,7 +209,7 @@ public class MTMathUILabel : MTView {
|
|||||||
context.restoreGState()
|
context.restoreGState()
|
||||||
}
|
}
|
||||||
|
|
||||||
func _layoutSubviews() {
|
override public func layoutSubviews() {
|
||||||
if mathList != nil {
|
if mathList != nil {
|
||||||
displayList = MTTypesetter.createLineForMathList(mathList, font: font, style: currentStyle)
|
displayList = MTTypesetter.createLineForMathList(mathList, font: font, style: currentStyle)
|
||||||
displayList?.textColor = textColor
|
displayList?.textColor = textColor
|
||||||
@@ -240,16 +253,26 @@ public class MTMathUILabel : MTView {
|
|||||||
override public var intrinsicContentSize: CGSize { _sizeThatFits(CGSizeZero) }
|
override public var intrinsicContentSize: CGSize { _sizeThatFits(CGSizeZero) }
|
||||||
|
|
||||||
#if os(macOS)
|
#if os(macOS)
|
||||||
override public var isFlipped: Bool { false }
|
|
||||||
func setNeedsDisplay() { self.needsDisplay = true }
|
func setNeedsDisplay() { self.needsDisplay = true }
|
||||||
func setNeedsLayout() { self.needsLayout = true }
|
func setNeedsLayout() { self.needsLayout = true }
|
||||||
|
override public var isFlipped: Bool { false }
|
||||||
override public func layout() {
|
override public func layout() {
|
||||||
self._layoutSubviews()
|
self.layoutSubviews()
|
||||||
super.layout()
|
super.layout()
|
||||||
}
|
}
|
||||||
#else
|
|
||||||
override public func layoutSubviews() { self._layoutSubviews() }
|
|
||||||
override public func sizeThatFits(_ size: CGSize) -> CGSize { self._sizeThatFits(size) }
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
// #if os(macOS)
|
||||||
|
// override public var isFlipped: Bool { false }
|
||||||
|
// func setNeedsDisplay() { self.needsDisplay = true }
|
||||||
|
// func setNeedsLayout() { self.needsLayout = true }
|
||||||
|
// override public func layout() {
|
||||||
|
// self._layoutSubviews()
|
||||||
|
// super.layout()
|
||||||
|
// }
|
||||||
|
// #else
|
||||||
|
// override public func layoutSubviews() { self._layoutSubviews() }
|
||||||
|
// override public func sizeThatFits(_ size: CGSize) -> CGSize { self._sizeThatFits(size) }
|
||||||
|
// #endif
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user