diff --git a/Gluon/Classes/Classes.swift b/Gluon/Classes/Classes.swift index 6682bfaf..cf96ad28 100644 --- a/Gluon/Classes/Classes.swift +++ b/Gluon/Classes/Classes.swift @@ -105,13 +105,13 @@ public final class StackView: BaseComponent { public final class Label: BaseComponent { public struct Props: Equatable, Default { - let fontColor: UIColor + let fontColor: Color public init() { fontColor = .black } - public init(fontColor: UIColor) { + public init(fontColor: Color) { self.fontColor = fontColor } } @@ -119,11 +119,11 @@ public final class Label: BaseComponent { public final class Button: BaseComponent { public struct Props: Equatable { - let backgroundColor: UIColor - let fontColor: UIColor + let backgroundColor: Color + let fontColor: Color let onPress: Unique<() -> ()> - public init(backgroundColor: UIColor = .white, fontColor: UIColor = .black, + public init(backgroundColor: Color = .white, fontColor: Color = .black, onPress: Unique<() -> ()>) { self.backgroundColor = backgroundColor self.fontColor = fontColor diff --git a/Gluon/Classes/Color.swift b/Gluon/Classes/Color.swift new file mode 100644 index 00000000..b34f629b --- /dev/null +++ b/Gluon/Classes/Color.swift @@ -0,0 +1,13 @@ +// +// Color.swift +// Gluon +// +// Created by Max Desiatov on 16/10/2018. +// + +import Foundation + +public struct Color: Equatable { + public static var white = Color() + public static var black = Color() +} diff --git a/Gluon/Classes/Layout.swift b/Gluon/Classes/Layout.swift new file mode 100644 index 00000000..7be3e8a5 --- /dev/null +++ b/Gluon/Classes/Layout.swift @@ -0,0 +1,125 @@ +// +// Layout.swift +// Gluon +// +// Created by Max Desiatov on 16/10/2018. +// + +import Foundation + +public final class Constraint: BaseComponent { + enum Target { + case next + case container + case own + } + + struct HorizontalLocation: Equatable { + enum Attribute { + case left + case right + } + + let target: Target + let attribute: Attribute? + let offset: Double + + static func equal(to target: Target, + _ attribute: Attribute? = nil, + offset: Double = 0) -> HorizontalLocation { + return HorizontalLocation(target: target, + attribute: attribute, + offset: offset) + } + } + + struct VerticalLocation: Equatable { + enum Attribute { + case top + case bottom + case baseline + } + + let target: Target + let attribute: Attribute? + let offset: Double + + static func equal(to target: Target, + _ attribute: Attribute? = nil, + offset: Double = 0) -> VerticalLocation { + return VerticalLocation(target: target, + attribute: attribute, + offset: offset) + } + } + + enum CenterTarget { + case next + case container + } + + struct Center: Equatable { + let target: CenterTarget + + static func equal(to target: CenterTarget) -> Center { + return Center(target: target) + } + } + + struct Size: Equatable { + enum Attribute { + case width + case height + } + + let target: Target + let attibute: Attribute? + let offset: Double + let multiplier: Double + + static func equal(to target: Target, + _ attribute: Attribute? = nil, + offset: Double = 0, + multiplier: Double = 1) -> Size { + return Size(target: target, + attibute: attribute, + offset: offset, + multiplier: multiplier) + } + } + + struct Props: Equatable { + let baseline: VerticalLocation? + let bottom: VerticalLocation? + let center: Center? + let centerX: HorizontalLocation? + let centerY: VerticalLocation? + let height: Size? + let left: HorizontalLocation? + let right: HorizontalLocation? + let top: VerticalLocation? + let width: Size? + + init(baseline: VerticalLocation? = nil, + bottom: VerticalLocation? = nil, + center: Center? = nil, + centerX: HorizontalLocation? = nil, + centerY: VerticalLocation? = nil, + height: Size? = nil, + left: HorizontalLocation? = nil, + right: HorizontalLocation? = nil, + top: VerticalLocation? = nil, + width: Size? = nil) { + self.width = width + self.height = height + self.centerX = centerX + self.centerY = centerY + self.center = center + self.baseline = baseline + self.top = top + self.bottom = bottom + self.left = left + self.right = right + } + } +} diff --git a/Gluon/Classes/Structs.swift b/Gluon/Classes/Structs.swift index 0a6fb3ad..cd23b552 100644 --- a/Gluon/Classes/Structs.swift +++ b/Gluon/Classes/Structs.swift @@ -82,8 +82,8 @@ private struct Button: ComponentType { var children: [Node] struct Props: Equatable { - let backgroundColor = UIColor.white - let fontColor = UIColor.black + let backgroundColor = Color.white + let fontColor = Color.black let onPress: Unique<() -> ()> } }