Skip to content

Commit d9eae08

Browse files
committed
Add colorize function
1 parent 401de0c commit d9eae08

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

Sources/GateEngine/UI/Button.swift

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,12 @@ open class Button: Control {
1717
self.backgroundColor = color
1818
}
1919
}
20+
public func setBackgroundColor(_ color: Color) {
21+
self.backgroundColor = color
22+
self.backgroundColors[.normal] = color
23+
self.backgroundColors[.highlighted] = color.interpolated(to: .lightGray, .linear(0.25))
24+
self.backgroundColors[.selected] = color.interpolated(to: .darkGray, .linear(0.25))
25+
}
2026

2127
private var textColors: [State: Color] = [
2228
.highlighted:.white,
@@ -141,10 +147,7 @@ open class Button: Control {
141147
public init(size: Size2? = nil, label: String? = nil, textColor: Color = .white, backgroundColor: Color = .blue, cornorRadius: Float? = nil, action: ((Button)->())? = nil) {
142148
super.init(size: size)
143149

144-
self.backgroundColor = backgroundColor
145-
self.backgroundColors[.normal] = backgroundColor
146-
self.backgroundColors[.highlighted] = backgroundColor
147-
self.backgroundColors[.selected] = backgroundColor.interpolated(to: .darkGray, .linear(0.25))
150+
self.setBackgroundColor(backgroundColor)
148151

149152
self.textColors[.normal] = textColor
150153
self.textColors[.highlighted] = textColor

0 commit comments

Comments
 (0)