Commit 367592c3 by Daniel Dahan

added MaterialShape

parent 4e64b67f
......@@ -30,6 +30,7 @@
65BDD1671BB7111E006F7F2B /* MaterialButton.swift in Headers */ = {isa = PBXBuildFile; fileRef = 65BDD1561BB6FC82006F7F2B /* MaterialButton.swift */; settings = {ATTRIBUTES = (Public, ); }; };
65BDD1681BB7111E006F7F2B /* FlatButton.swift in Headers */ = {isa = PBXBuildFile; fileRef = 65BDD1581BB6FE3E006F7F2B /* FlatButton.swift */; settings = {ATTRIBUTES = (Public, ); }; };
65BDD16A1BB7146B006F7F2B /* MaterialBorder.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65BDD1691BB7146B006F7F2B /* MaterialBorder.swift */; settings = {ASSET_TAGS = (); }; };
65BDD16C1BB88D1A006F7F2B /* MaterialShape.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65BDD16B1BB88D1A006F7F2B /* MaterialShape.swift */; settings = {ASSET_TAGS = (); }; };
65DBE4201B9A9244000C804F /* Roboto-Bold.ttf in Resources */ = {isa = PBXBuildFile; fileRef = 65DBE41E1B9A9244000C804F /* Roboto-Bold.ttf */; };
65DBE4211B9A9244000C804F /* Roboto-Thin.ttf in Resources */ = {isa = PBXBuildFile; fileRef = 65DBE41F1B9A9244000C804F /* Roboto-Thin.ttf */; };
962F3E531BACA68C0004B8AD /* NavigationBarView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 962F3E521BACA68C0004B8AD /* NavigationBarView.swift */; };
......@@ -65,6 +66,7 @@
65BDD15A1BB7095E006F7F2B /* MaterialRadius.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MaterialRadius.swift; sourceTree = "<group>"; };
65BDD15C1BB70D60006F7F2B /* MaterialInsets.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MaterialInsets.swift; sourceTree = "<group>"; };
65BDD1691BB7146B006F7F2B /* MaterialBorder.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MaterialBorder.swift; sourceTree = "<group>"; };
65BDD16B1BB88D1A006F7F2B /* MaterialShape.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MaterialShape.swift; sourceTree = "<group>"; };
65DBE41E1B9A9244000C804F /* Roboto-Bold.ttf */ = {isa = PBXFileReference; lastKnownFileType = file; path = "Roboto-Bold.ttf"; sourceTree = "<group>"; };
65DBE41F1B9A9244000C804F /* Roboto-Thin.ttf */ = {isa = PBXFileReference; lastKnownFileType = file; path = "Roboto-Thin.ttf"; sourceTree = "<group>"; };
962F3E521BACA68C0004B8AD /* NavigationBarView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NavigationBarView.swift; sourceTree = "<group>"; };
......@@ -195,6 +197,7 @@
65BDD15A1BB7095E006F7F2B /* MaterialRadius.swift */,
65BDD15C1BB70D60006F7F2B /* MaterialInsets.swift */,
65BDD1691BB7146B006F7F2B /* MaterialBorder.swift */,
65BDD16B1BB88D1A006F7F2B /* MaterialShape.swift */,
);
name = Theme;
sourceTree = "<group>";
......@@ -336,6 +339,7 @@
files = (
65BDD15D1BB70D60006F7F2B /* MaterialInsets.swift in Sources */,
65BDD1471BB5B916006F7F2B /* MaterialView.swift in Sources */,
65BDD16C1BB88D1A006F7F2B /* MaterialShape.swift in Sources */,
65BDD1521BB6EE7C006F7F2B /* RobotoFont.swift in Sources */,
65BDD1591BB6FE3E006F7F2B /* FlatButton.swift in Sources */,
962F3E531BACA68C0004B8AD /* NavigationBarView.swift in Sources */,
......
......@@ -26,11 +26,6 @@ public class FlatButton : MaterialButton {
super.prepareView()
setTitleColor(MaterialTheme.button.flat.titleLabelColorForNormalState, forState: .Normal)
titleLabel!.font = MaterialTheme.button.flat.titleLabelFont
backgroundColor = MaterialColor.red.base //MaterialTheme.button.flat.backgroudColor
cornerRadius = MaterialTheme.button.flat.cornerRadius
contentInsets = MaterialTheme.button.flat.contentInsets
borderWidth = MaterialTheme.button.flat.borderWidth
borderColor = MaterialTheme.button.flat.bordercolor
}
//
......@@ -42,5 +37,11 @@ public class FlatButton : MaterialButton {
shadowColor = MaterialTheme.button.flat.shadowColor
zPosition = MaterialTheme.button.flat.zPosition
masksToBounds = MaterialTheme.button.flat.masksToBounds
shape = MaterialTheme.button.flat.shape
cornerRadius = MaterialTheme.button.flat.cornerRadius
borderWidth = MaterialTheme.button.flat.borderWidth
borderColor = MaterialTheme.button.flat.bordercolor
contentInsets = MaterialTheme.button.flat.contentInsets
backgroundColor = MaterialTheme.button.flat.backgroudColor
}
}
\ No newline at end of file
......@@ -35,8 +35,11 @@ public class MaterialButton : UIButton {
:name: x
*/
public var x: CGFloat! {
didSet {
layer.bounds.origin.x = x
get {
return layer.bounds.origin.x
}
set(value) {
layer.bounds.origin.x = value
}
}
......@@ -44,8 +47,11 @@ public class MaterialButton : UIButton {
:name: y
*/
public var y: CGFloat! {
didSet {
layer.bounds.origin.y = y
get {
return layer.bounds.origin.y
}
set(value) {
layer.bounds.origin.y = value
}
}
......@@ -53,8 +59,11 @@ public class MaterialButton : UIButton {
:name: width
*/
public var width: CGFloat! {
didSet {
layer.bounds.size.width = width
get {
return layer.bounds.size.width
}
set(value) {
layer.bounds.size.width = value
}
}
......@@ -62,8 +71,11 @@ public class MaterialButton : UIButton {
:name: height
*/
public var height: CGFloat! {
didSet {
layer.bounds.size.height = height
get {
return layer.bounds.size.height
}
set(value) {
layer.bounds.size.height = value
}
}
......@@ -117,11 +129,20 @@ public class MaterialButton : UIButton {
*/
public var cornerRadius: MaterialRadius! {
didSet {
switch cornerRadius! {
case .Square, .Light, .Regular, .Medium, .Heavy:
layer.cornerRadius = MaterialRadiusToValue(cornerRadius!)
case .Round:
layer.cornerRadius = bounds.width / 2
layer.cornerRadius = MaterialRadiusToValue(cornerRadius!)
}
}
/**
:name: shape
*/
public var shape: MaterialShape! {
didSet {
switch shape! {
case .Square:
layer.cornerRadius = 0
case .Circle:
layer.cornerRadius = width / 2
}
}
}
......@@ -194,11 +215,10 @@ public class MaterialButton : UIButton {
super.init(frame: frame)
prepareView()
prepareLayer()
prepareBounds()
}
public convenience init() {
self.init(frame: CGRectMake(0, 0, 100, 100))
self.init(frame: CGRectZero)
}
/**
......@@ -230,16 +250,6 @@ public class MaterialButton : UIButton {
}
//
// :name: prepareBounds
//
internal func prepareBounds() {
x = frame.origin.x
y = frame.origin.y
width = frame.size.width
height = frame.size.height
}
//
// :name: prepareLayer
//
internal func prepareLayer() {
......
......@@ -21,12 +21,11 @@ import UIKit
public typealias MaterialRadiusType = CGFloat
public enum MaterialRadius {
case Square
case None
case Light
case Regular
case Medium
case Heavy
case Round
}
/**
......@@ -34,7 +33,7 @@ public enum MaterialRadius {
*/
public func MaterialRadiusToValue(radius: MaterialRadius) -> MaterialRadiusType {
switch radius {
case .Square, .Round:
case .None:
return 0
case .Light:
return 4
......
//
// Copyright (C) 2015 GraphKit, Inc. <http://graphkit.io> and other GraphKit contributors.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published
// by the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program located at the root of the software package
// in a file called LICENSE. If not, see <http://www.gnu.org/licenses/>.
//
public enum MaterialShape {
case Square
case Circle
}
......@@ -42,7 +42,8 @@ public extension MaterialTheme.view {
// shape
public static let masksToBounds: Bool = false
public static let cornerRadius: MaterialRadius = .Square
public static let cornerRadius: MaterialRadius = .None
public static let shape: MaterialShape = .Square
// border
public static let borderWidth: MaterialBorder = .None
......@@ -79,6 +80,7 @@ public extension MaterialTheme.navigation {
// shape
public static let masksToBounds: Bool = MaterialTheme.view.masksToBounds
public static let cornerRadius: MaterialRadius = MaterialTheme.view.cornerRadius
public static let shape: MaterialShape = MaterialTheme.view.shape
// border
public static let borderWidth: MaterialBorder = MaterialTheme.view.borderWidth
......@@ -110,6 +112,7 @@ public extension MaterialTheme.button {
// shape
public static let masksToBounds: Bool = MaterialTheme.view.masksToBounds
public static let cornerRadius: MaterialRadius = .Light
public static let shape: MaterialShape = MaterialTheme.view.shape
public static let contentInsets: MaterialInsets = .Inset2
// border
......@@ -139,6 +142,7 @@ public extension MaterialTheme.button.flat {
// shape
public static let masksToBounds: Bool = MaterialTheme.button.masksToBounds
public static let cornerRadius: MaterialRadius = MaterialTheme.button.cornerRadius
public static let shape: MaterialShape = MaterialTheme.button.shape
public static let contentInsets: MaterialInsets = MaterialTheme.button.contentInsets
// border
......
......@@ -80,8 +80,11 @@ public class MaterialView: UIView {
:name: x
*/
public var x: CGFloat! {
didSet {
layer.bounds.origin.x = x
get {
return layer.bounds.origin.x
}
set(value) {
layer.bounds.origin.x = value
}
}
......@@ -89,8 +92,11 @@ public class MaterialView: UIView {
:name: y
*/
public var y: CGFloat! {
didSet {
layer.bounds.origin.y = y
get {
return layer.bounds.origin.y
}
set(value) {
layer.bounds.origin.y = value
}
}
......@@ -98,8 +104,11 @@ public class MaterialView: UIView {
:name: width
*/
public var width: CGFloat! {
didSet {
layer.bounds.size.width = width
get {
return layer.bounds.size.width
}
set(value) {
layer.bounds.size.width = value
}
}
......@@ -107,8 +116,11 @@ public class MaterialView: UIView {
:name: height
*/
public var height: CGFloat! {
didSet {
layer.bounds.size.height = height
get {
return layer.bounds.size.height
}
set(value) {
layer.bounds.size.height = value
}
}
......@@ -162,11 +174,20 @@ public class MaterialView: UIView {
*/
public var cornerRadius: MaterialRadius! {
didSet {
switch cornerRadius! {
case .Square, .Light, .Regular, .Medium, .Heavy:
layer.cornerRadius = MaterialRadiusToValue(cornerRadius!)
case .Round:
layer.cornerRadius = bounds.width / 2
layer.cornerRadius = MaterialRadiusToValue(cornerRadius!)
}
}
/**
:name: shape
*/
public var shape: MaterialShape! {
didSet {
switch shape! {
case .Square:
layer.cornerRadius = 0
case .Circle:
layer.cornerRadius = width / 2
}
}
}
......@@ -176,7 +197,7 @@ public class MaterialView: UIView {
*/
public var borderWidth: MaterialBorder! {
didSet {
layer.borderWidth = MaterialBorderToValue(borderWidth)
layer.borderWidth = MaterialBorderToValue(borderWidth!)
}
}
......@@ -194,7 +215,7 @@ public class MaterialView: UIView {
*/
public var shadowDepth: MaterialShadow! {
didSet {
let value: MaterialShadowType = MaterialShadowToValue(shadowDepth)
let value: MaterialShadowType = MaterialShadowToValue(shadowDepth!)
shadowOffset = value.offset
shadowOpacity = value.opacity
shadowRadius = value.radius
......@@ -224,7 +245,6 @@ public class MaterialView: UIView {
super.init(frame: frame)
prepareView()
prepareLayer()
prepareBounds()
}
/**
......@@ -243,16 +263,6 @@ public class MaterialView: UIView {
}
//
// :name: prepareBounds
//
internal func prepareBounds() {
x = frame.origin.x
y = frame.origin.y
width = frame.size.width
height = frame.size.height
}
//
// :name: prepareLayer
//
internal func prepareLayer() {
......@@ -264,8 +274,9 @@ public class MaterialView: UIView {
shadowColor = MaterialTheme.view.shadowColor
zPosition = MaterialTheme.view.zPosition
masksToBounds = MaterialTheme.view.masksToBounds
shape = MaterialTheme.view.shape
cornerRadius = MaterialTheme.view.cornerRadius
borderWidth = .None
borderWidth = MaterialTheme.view.borderWidth
borderColor = MaterialTheme.view.bordercolor
}
}
......
......@@ -58,8 +58,9 @@ public class NavigationBarView: MaterialView {
shadowColor = MaterialTheme.navigation.shadowColor
zPosition = MaterialTheme.navigation.zPosition
masksToBounds = MaterialTheme.navigation.masksToBounds
shape = MaterialTheme.navigation.shape
cornerRadius = MaterialTheme.navigation.cornerRadius
borderWidth = .None
borderColor = MaterialTheme.view.bordercolor
borderWidth = MaterialTheme.navigation.borderWidth
borderColor = MaterialTheme.navigation.bordercolor
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment