Added Color struct and Layout.Props
This commit is contained in:
parent
a1b173a2a2
commit
8110931d84
|
@ -105,13 +105,13 @@ public final class StackView: BaseComponent<NoProps> {
|
|||
|
||||
public final class Label: BaseComponent<Label.Props> {
|
||||
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<Label.Props> {
|
|||
|
||||
public final class Button: BaseComponent<Button.Props> {
|
||||
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
|
||||
|
|
|
@ -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()
|
||||
}
|
|
@ -0,0 +1,125 @@
|
|||
//
|
||||
// Layout.swift
|
||||
// Gluon
|
||||
//
|
||||
// Created by Max Desiatov on 16/10/2018.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
public final class Constraint: BaseComponent<Constraint.Props> {
|
||||
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
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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<() -> ()>
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue