ScriptControllerIconView: Update to reflect policy type
This commit is contained in:
@@ -13,17 +13,16 @@ class ScriptControllerIconView: ReliefButton
|
||||
didSet { setNeedsLayout() }
|
||||
}
|
||||
|
||||
public var someScriptsAllowed: Bool = false {
|
||||
didSet { setNeedsLayout() }
|
||||
}
|
||||
@Invalidating(.layout)
|
||||
public var currentPolicy: ScriptPolicy = ScriptPolicy(securityOrigin: "", policyType: .alpha)
|
||||
|
||||
private let labelView = UILabel(frame: .zero)
|
||||
private let policyImageView = UIImageView(frame: .zero)
|
||||
|
||||
private let shieldsDownImage = UIImage(systemName: "shield.slash")
|
||||
private let shieldsUpImage = UIImage(systemName: "shield")
|
||||
private let shieldsPartiallyUpImage = UIImage(systemName: "shield.lefthalf.fill")
|
||||
|
||||
|
||||
override init() {
|
||||
super.init()
|
||||
|
||||
@@ -37,6 +36,8 @@ class ScriptControllerIconView: ReliefButton
|
||||
labelView.font = .boldSystemFont(ofSize: 8)
|
||||
labelView.textColor = .white
|
||||
|
||||
policyImageView.contentMode = .scaleAspectFit
|
||||
|
||||
setBlockedScriptsNumber(0)
|
||||
}
|
||||
|
||||
@@ -62,13 +63,34 @@ class ScriptControllerIconView: ReliefButton
|
||||
labelView.center = CGPoint(x: bounds.center.x + 10, y: bounds.center.y + 10)
|
||||
labelView.bounds = labelView.bounds.insetBy(dx: -3.0, dy: -2.0)
|
||||
|
||||
let policyImageWidth = round(bounds.width / 3)
|
||||
let policyImageSize = CGSize(
|
||||
// Make multiple of 2 to ensure proper centering
|
||||
width: policyImageWidth - policyImageWidth.truncatingRemainder(dividingBy: 2),
|
||||
height: policyImageWidth - policyImageWidth.truncatingRemainder(dividingBy: 2)
|
||||
)
|
||||
|
||||
if let imageView = imageView {
|
||||
imageView.addSubview(policyImageView)
|
||||
policyImageView.frame = CGRect(origin: .zero, size: policyImageSize)
|
||||
.centered(inRect: imageView.bounds)
|
||||
.offsetBy(dx: 0.0, dy: -1.0)
|
||||
}
|
||||
|
||||
if shieldsDown {
|
||||
setImage(shieldsDownImage, for: .normal)
|
||||
} else {
|
||||
if someScriptsAllowed {
|
||||
setImage(shieldsPartiallyUpImage, for: .normal)
|
||||
setImage(shieldsUpImage, for: .normal)
|
||||
|
||||
if isEnabled {
|
||||
policyImageView.isHidden = false
|
||||
policyImageView.image = ScriptPolicy.iconRepresentation(forPolicyType: currentPolicy.policyType, configuration: ScriptPolicy.IconConfiguration(
|
||||
size: policyImageSize,
|
||||
foregroundColor: .label,
|
||||
backgroundColor: .clear
|
||||
))
|
||||
} else {
|
||||
setImage(shieldsUpImage, for: .normal)
|
||||
policyImageView.isHidden = true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user