1
1
mirror of https://github.com/exyte/Macaw.git synced 2024-11-09 20:03:05 +03:00
This commit is contained in:
Igor Zapletnev 2016-05-11 12:10:17 +06:00
parent fc18868215
commit c1702b6b54
50 changed files with 197 additions and 223 deletions

View File

@ -210,7 +210,7 @@ class PathExampleView: MacawView {
let cloud = cloudExample()
let velocity = Point(x: -700 + Double(rand() % 1400),
y: -700 + Double(rand() % 1400))
let flying = PathAnimation(observableValue: cloud.posProperty, function: { t in
let flying = PathAnimation(observableValue: cloud.posVar, function: { t in
let x = velocity.x * t
let y = velocity.y * t + g * t * t;
return Transform.move(100.0 + x, my: 100 + y).scale(0.05, sy: 0.05)

View File

@ -26,7 +26,6 @@
66AE19D21CC8C6B300B78B5E /* SVGParser.swift in Sources */ = {isa = PBXBuildFile; fileRef = 66AE19D11CC8C6B300B78B5E /* SVGParser.swift */; };
AD9EDEE3709C1668BED1B1BF /* Pods_Macaw.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = BA114AD1025D7DA0B0DC35A8 /* Pods_Macaw.framework */; };
B0086C561C789758008A4F69 /* GroupRenderer.swift in Sources */ = {isa = PBXBuildFile; fileRef = B0086C551C789758008A4F69 /* GroupRenderer.swift */; };
B0097E081C706CAB00350E43 /* ObservableValue.swift in Sources */ = {isa = PBXBuildFile; fileRef = B0097E071C706CAB00350E43 /* ObservableValue.swift */; };
B03275E51C78772F000BDD33 /* Align.swift in Sources */ = {isa = PBXBuildFile; fileRef = B03275B21C78772F000BDD33 /* Align.swift */; };
B03275E61C78772F000BDD33 /* AspectRatio.swift in Sources */ = {isa = PBXBuildFile; fileRef = B03275B31C78772F000BDD33 /* AspectRatio.swift */; };
B03275E71C78772F000BDD33 /* Baseline.swift in Sources */ = {isa = PBXBuildFile; fileRef = B03275B41C78772F000BDD33 /* Baseline.swift */; };
@ -81,7 +80,6 @@
B03276231C78882A000BDD33 /* ImageRenderer.swift in Sources */ = {isa = PBXBuildFile; fileRef = B03276221C78882A000BDD33 /* ImageRenderer.swift */; };
B03276271C789217000BDD33 /* RenderContext.swift in Sources */ = {isa = PBXBuildFile; fileRef = B03276261C789217000BDD33 /* RenderContext.swift */; };
B03F88BE1C1C6A9E00F24FFC /* Signal.swift in Sources */ = {isa = PBXBuildFile; fileRef = B03F88BD1C1C6A9E00F24FFC /* Signal.swift */; };
B07B544B1CA3F92B0056CA74 /* Disposable.swift in Sources */ = {isa = PBXBuildFile; fileRef = B07B544A1CA3F92B0056CA74 /* Disposable.swift */; };
/* End PBXBuildFile section */
/* Begin PBXFileReference section */
@ -105,7 +103,6 @@
66AE19D11CC8C6B300B78B5E /* SVGParser.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = SVGParser.swift; path = svg/SVGParser.swift; sourceTree = "<group>"; };
8A680FA7BCDE96402C10D8D2 /* Pods-Macaw.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Macaw.release.xcconfig"; path = "Pods/Target Support Files/Pods-Macaw/Pods-Macaw.release.xcconfig"; sourceTree = "<group>"; };
B0086C551C789758008A4F69 /* GroupRenderer.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = GroupRenderer.swift; sourceTree = "<group>"; };
B0097E071C706CAB00350E43 /* ObservableValue.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ObservableValue.swift; sourceTree = "<group>"; };
B02E75D61C160F8D00D1971D /* Macaw.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Macaw.framework; sourceTree = BUILT_PRODUCTS_DIR; };
B02E76131C1612A900D1971D /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
B03275B21C78772F000BDD33 /* Align.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Align.swift; sourceTree = "<group>"; };
@ -162,7 +159,6 @@
B03276221C78882A000BDD33 /* ImageRenderer.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ImageRenderer.swift; sourceTree = "<group>"; };
B03276261C789217000BDD33 /* RenderContext.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RenderContext.swift; sourceTree = "<group>"; };
B03F88BD1C1C6A9E00F24FFC /* Signal.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Signal.swift; sourceTree = "<group>"; };
B07B544A1CA3F92B0056CA74 /* Disposable.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Disposable.swift; sourceTree = "<group>"; };
BA114AD1025D7DA0B0DC35A8 /* Pods_Macaw.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_Macaw.framework; sourceTree = BUILT_PRODUCTS_DIR; };
/* End PBXFileReference section */
@ -241,15 +237,6 @@
name = svg;
sourceTree = "<group>";
};
B0097E061C706CA500350E43 /* bindings */ = {
isa = PBXGroup;
children = (
B0097E071C706CAB00350E43 /* ObservableValue.swift */,
B07B544A1CA3F92B0056CA74 /* Disposable.swift */,
);
path = bindings;
sourceTree = "<group>";
};
B02E75CC1C160F8D00D1971D = {
isa = PBXGroup;
children = (
@ -276,7 +263,6 @@
B03275B01C78772F000BDD33 /* model */,
585C04461C27CFB100335FF2 /* views */,
B03F88BC1C1C6A9300F24FFC /* events */,
B0097E061C706CA500350E43 /* bindings */,
B03276151C787996000BDD33 /* render */,
B02E76131C1612A900D1971D /* Info.plist */,
);
@ -537,7 +523,6 @@
573AA6A41CAE402C00F30607 /* RevertedAnimation.swift in Sources */,
573AA6A61CAE41D400F30607 /* LoopedAnimation.swift in Sources */,
B03275F71C78772F000BDD33 /* Ellipse.swift in Sources */,
B0097E081C706CAB00350E43 /* ObservableValue.swift in Sources */,
B032760F1C78772F000BDD33 /* Group.swift in Sources */,
B03275E61C78772F000BDD33 /* AspectRatio.swift in Sources */,
B03276071C78772F000BDD33 /* SCubic.swift in Sources */,
@ -565,7 +550,6 @@
B03276001C78772F000BDD33 /* PLine.swift in Sources */,
B03275F91C78772F000BDD33 /* HLine.swift in Sources */,
B03275FA1C78772F000BDD33 /* Insets.swift in Sources */,
B07B544B1CA3F92B0056CA74 /* Disposable.swift in Sources */,
B03276101C78772F000BDD33 /* Image.swift in Sources */,
B03275EE1C78772F000BDD33 /* LinearGradient.swift in Sources */,
B03275E71C78772F000BDD33 /* Baseline.swift in Sources */,

View File

@ -3,5 +3,6 @@ use_frameworks!
target 'Macaw' do
pod 'SWXMLHash', '~> 2.3.0'
pod 'RxSwift', '~> 2.4'
end

View File

@ -1,10 +1,13 @@
PODS:
- RxSwift (2.4)
- SWXMLHash (2.3.1)
DEPENDENCIES:
- RxSwift (~> 2.4)
- SWXMLHash (~> 2.3.0)
SPEC CHECKSUMS:
RxSwift: 67b9ef4e8b34fb394e200e754c6a09cc16559f94
SWXMLHash: 795c66e74f4cc9473ad6465c6653c5a6f59f417e
COCOAPODS: 0.39.0

View File

@ -1,4 +1,5 @@
import Foundation
import RxSwift
public extension SequenceType where Generator.Element: Animatable {
func playAnimations() {
@ -33,7 +34,7 @@ public class Animatable {
var shouldUpdateSubscription = false
public let currentProgress = ObservableValue<Double>(value: 0)
public let currentProgress = Variable<Double>(0)
func animate(progress: Double) { }
func getDuration() -> Double { return 0 }
@ -47,33 +48,33 @@ public class Animatable {
public func moveToPosition(position: Double) {
shouldUpdateSubscription = true
currentProgress.set(position)
currentProgress.value = position
}
}
public class Animation<T: Interpolable>: Animatable {
let value: ObservableValue<T>
let value: Variable<T>
let start: T
let final: T
let duration: Double
public required init(observableValue: ObservableValue<T>, startValue: T, finalValue: T, animationDuration: Double) {
public required init(observableValue: Variable<T>, startValue: T, finalValue: T, animationDuration: Double) {
value = observableValue
start = startValue
final = finalValue
duration = animationDuration
}
public convenience init(observableValue: ObservableValue<T>, finalValue: T, animationDuration: Double) {
self.init(observableValue: observableValue, startValue: observableValue.get(), finalValue: finalValue, animationDuration: animationDuration)
public convenience init(observableValue: Variable<T>, finalValue: T, animationDuration: Double) {
self.init(observableValue: observableValue, startValue: observableValue.value, finalValue: finalValue, animationDuration: animationDuration)
}
public override func animate(progress: Double) {
value.set(start.interpolate(final, progress: progress))
currentProgress.set(progress)
value.value = start.interpolate(final, progress: progress)
currentProgress.value = progress
}
public override func getDuration() -> Double {

View File

@ -35,7 +35,7 @@ class AnimationLoop {
if animation.shouldUpdateSubscription {
animation.shouldUpdateSubscription = false
subscription.startTime = timestamp - animation.getDuration() * animation.currentProgress.get()
subscription.startTime = timestamp - animation.getDuration() * animation.currentProgress.value
}
// Calculating current position
@ -54,7 +54,7 @@ class AnimationLoop {
toRemove.append(subscription)
}
animation.currentProgress.set(position)
animation.currentProgress.value = position
subscription.moveToTimeFrame(position)
}
@ -78,13 +78,13 @@ class AnimationLoop {
return
}
animation.currentProgress.addListener { (oldValue, newValue) in
if !subscription.anim.paused {
return
}
subscription.moveToTimeFrame(newValue)
self.rendererCall?()
}
let _ = animation.currentProgress.asObservable().subscribeNext { newValue in
if !subscription.anim.paused {
return
}
subscription.moveToTimeFrame(newValue)
self.rendererCall?()
}
}
}

View File

@ -1,4 +1,5 @@
import Foundation
import RxSwift
public struct AnimationPathFrame<T: Interpolable> {
@ -21,13 +22,13 @@ public struct AnimationPathSegment<T: Interpolable> {
public class PathAnimation<T: Interpolable>: Animatable {
let value: ObservableValue<T>
let value: Variable<T>
let pathSegments: [AnimationPathSegment<T>]
let duration: Double
var cachedSegment: AnimationPathSegment<T>?
public required init(observableValue: ObservableValue<T>, path: [AnimationPathFrame<T>], animationDuration: Double) {
public required init(observableValue: Variable<T>, path: [AnimationPathFrame<T>], animationDuration: Double) {
value = observableValue
duration = animationDuration
@ -45,7 +46,7 @@ public class PathAnimation<T: Interpolable>: Animatable {
pathSegments = segments
}
public convenience init(observableValue: ObservableValue<T>, function: (Double) -> T, animationDuration: Double) {
public convenience init(observableValue: Variable<T>, function: (Double) -> T, animationDuration: Double) {
var path = [AnimationPathFrame<T>]()
// 60 fps
@ -66,8 +67,8 @@ public class PathAnimation<T: Interpolable>: Animatable {
// Cache
if let cachedSegment = cachedSegment {
if cachedSegment.contains(progress) {
value.set(iterpolate(cachedSegment, position: progress))
currentProgress.set(progress)
value.value = iterpolate(cachedSegment, position: progress)
currentProgress.value = progress
return
}
}
@ -76,8 +77,8 @@ public class PathAnimation<T: Interpolable>: Animatable {
for segment in pathSegments {
if segment.contains(progress) {
cachedSegment = segment
value.set(iterpolate(segment, position: progress))
currentProgress.set(progress)
value.value = iterpolate(segment, position: progress)
currentProgress.value = progress
return
}
}

View File

@ -1,13 +0,0 @@
import Foundation
public class Disposable {
private let disposeAction: () -> ()
init(disposeAction: () -> ()) {
self.disposeAction = disposeAction
}
public func dispose() {
disposeAction()
}
}

View File

@ -1,44 +0,0 @@
public class ObservableValue<T> {
private var listeners: [ObservableValueListener<T>] = []
private var value: T
init(value: T) {
self.value = value
}
func get() -> T {
return value
}
func set(newValue: T) {
let oldValue = value
value = newValue
valueChanged(oldValue, newValue: value)
}
public func addListener(listener: (oldValue: T, newValue: T) -> ()) -> Disposable {
let observableListener = ObservableValueListener<T>(onChange: listener)
listeners.append(observableListener)
return Disposable {
let index = self.listeners.indexOf { $0 === observableListener }
if let indexVal = index {
self.listeners.removeAtIndex(indexVal)
}
}
}
func valueChanged(oldValue: T, newValue: T) {
for listener in listeners {
listener.onChange(oldValue: oldValue, newValue: newValue)
}
}
}
class ObservableValueListener<T> {
let onChange: (oldValue: T, newValue: T) -> ()
init(onChange: (oldValue: T, newValue: T) -> ()) {
self.onChange = onChange
}
}

View File

@ -1,4 +1,5 @@
import Foundation
import RxSwift
public class Color: Fill {

View File

@ -1,4 +1,5 @@
import Foundation
import RxSwift
public class Drawable {

View File

@ -1,4 +1,5 @@
import Foundation
import RxSwift
public class Fill {

View File

@ -1,4 +1,5 @@
import Foundation
import RxSwift
public class Font {

View File

@ -1,4 +1,5 @@
import Foundation
import RxSwift
public class LinearGradient: Fill {

View File

@ -1,4 +1,5 @@
import Foundation
import RxSwift
public class Stop {

View File

@ -1,4 +1,5 @@
import Foundation
import RxSwift
public class Stroke {

View File

@ -1,4 +1,5 @@
import Foundation
import RxSwift
public class Arc: Locus {

View File

@ -1,4 +1,5 @@
import Foundation
import RxSwift
public class Circle: Locus {

View File

@ -1,4 +1,5 @@
import Foundation
import RxSwift
public class Close: PathSegment {

View File

@ -1,4 +1,5 @@
import Foundation
import RxSwift
public class Cubic: PathSegment {

View File

@ -1,4 +1,5 @@
import Foundation
import RxSwift
public class Ellipse: Locus {

View File

@ -1,4 +1,5 @@
import Foundation
import RxSwift
public class Elliptical: PathSegment {

View File

@ -1,4 +1,5 @@
import Foundation
import RxSwift
public class HLine: PathSegment {

View File

@ -1,4 +1,5 @@
import Foundation
import RxSwift
public class Insets {

View File

@ -1,4 +1,5 @@
import Foundation
import RxSwift
public class Line: Locus {

View File

@ -1,4 +1,5 @@
import Foundation
import RxSwift
public class Locus {

View File

@ -1,4 +1,5 @@
import Foundation
import RxSwift
public class Move: PathSegment {

View File

@ -1,4 +1,5 @@
import Foundation
import RxSwift
public class PLine: PathSegment {

View File

@ -1,4 +1,5 @@
import Foundation
import RxSwift
public class Path: Locus {

View File

@ -1,4 +1,5 @@
import Foundation
import RxSwift
public class PathSegment {

View File

@ -1,4 +1,5 @@
import Foundation
import RxSwift
public class Point: Locus {

View File

@ -1,4 +1,5 @@
import Foundation
import RxSwift
public class Polygon: Locus {

View File

@ -1,4 +1,5 @@
import Foundation
import RxSwift
public class Polyline: Locus {

View File

@ -1,4 +1,5 @@
import Foundation
import RxSwift
public class Quadratic: PathSegment {

View File

@ -1,4 +1,5 @@
import Foundation
import RxSwift
public class Rect: Locus {

View File

@ -1,4 +1,5 @@
import Foundation
import RxSwift
public class RoundRect: Locus {

View File

@ -1,4 +1,5 @@
import Foundation
import RxSwift
public class SCubic: PathSegment {

View File

@ -1,4 +1,5 @@
import Foundation
import RxSwift
public class SQuadratic: PathSegment {

View File

@ -1,4 +1,5 @@
import Foundation
import RxSwift
public class Size {

View File

@ -1,4 +1,5 @@
import Foundation
import RxSwift
public final class Transform {

View File

@ -1,4 +1,5 @@
import Foundation
import RxSwift
public class VLine: PathSegment {

View File

@ -1,43 +1,44 @@
import Foundation
import RxSwift
public class Mouse {
public let hoverProperty: ObservableValue<Bool>
public let hoverVar: Variable<Bool>
public var hover: Bool {
get { return hoverProperty.get() }
set(val) { hoverProperty.set(val) }
get { return hoverVar.value }
set(val) { hoverVar.value = val }
}
public let posProperty: ObservableValue<Point>
public let posVar: Variable<Point>
public var pos: Point {
get { return posProperty.get() }
set(val) { posProperty.set(val) }
get { return posVar.value }
set(val) { posVar.value = val }
}
public let onEnterProperty: ObservableValue<Signal>
public let onEnterVar: Variable<Signal>
public var onEnter: Signal {
get { return onEnterProperty.get() }
set(val) { onEnterProperty.set(val) }
get { return onEnterVar.value }
set(val) { onEnterVar.value = val }
}
public let onExitProperty: ObservableValue<Signal>
public let onExitVar: Variable<Signal>
public var onExit: Signal {
get { return onExitProperty.get() }
set(val) { onExitProperty.set(val) }
get { return onExitVar.value }
set(val) { onExitVar.value = val }
}
public let onWheelProperty: ObservableValue<Signal>
public let onWheelVar: Variable<Signal>
public var onWheel: Signal {
get { return onWheelProperty.get() }
set(val) { onWheelProperty.set(val) }
get { return onWheelVar.value }
set(val) { onWheelVar.value = val }
}
public init(hover: Bool = false, pos: Point, onEnter: Signal, onExit: Signal, onWheel: Signal) {
self.hoverProperty = ObservableValue<Bool>(value: hover)
self.posProperty = ObservableValue<Point>(value: pos)
self.onEnterProperty = ObservableValue<Signal>(value: onEnter)
self.onExitProperty = ObservableValue<Signal>(value: onExit)
self.onWheelProperty = ObservableValue<Signal>(value: onWheel)
self.hoverVar = Variable<Bool>(hover)
self.posVar = Variable<Point>(pos)
self.onEnterVar = Variable<Signal>(onEnter)
self.onExitVar = Variable<Signal>(onExit)
self.onWheelVar = Variable<Signal>(onWheel)
}
// GENERATED NOT

View File

@ -1,43 +1,44 @@
import Foundation
import RxSwift
public class MouseButton {
public let pressedProperty: ObservableValue<Bool>
public let pressedVar: Variable<Bool>
public var pressed: Bool {
get { return pressedProperty.get() }
set(val) { pressedProperty.set(val) }
get { return pressedVar.value }
set(val) { pressedVar.value = val }
}
public let onPressProperty: ObservableValue<Signal>
public let onPressVar: Variable<Signal>
public var onPress: Signal {
get { return onPressProperty.get() }
set(val) { onPressProperty.set(val) }
get { return onPressVar.value }
set(val) { onPressVar.value = val }
}
public let onReleaseProperty: ObservableValue<Signal>
public let onReleaseVar: Variable<Signal>
public var onRelease: Signal {
get { return onReleaseProperty.get() }
set(val) { onReleaseProperty.set(val) }
get { return onReleaseVar.value }
set(val) { onReleaseVar.value = val }
}
public let onClickProperty: ObservableValue<Signal>
public let onClickVar: Variable<Signal>
public var onClick: Signal {
get { return onClickProperty.get() }
set(val) { onClickProperty.set(val) }
get { return onClickVar.value }
set(val) { onClickVar.value = val }
}
public let onDoubleClickProperty: ObservableValue<Signal>
public let onDoubleClickVar: Variable<Signal>
public var onDoubleClick: Signal {
get { return onDoubleClickProperty.get() }
set(val) { onDoubleClickProperty.set(val) }
get { return onDoubleClickVar.value }
set(val) { onDoubleClickVar.value = val }
}
public init(pressed: Bool = false, onPress: Signal, onRelease: Signal, onClick: Signal, onDoubleClick: Signal) {
self.pressedProperty = ObservableValue<Bool>(value: pressed)
self.onPressProperty = ObservableValue<Signal>(value: onPress)
self.onReleaseProperty = ObservableValue<Signal>(value: onRelease)
self.onClickProperty = ObservableValue<Signal>(value: onClick)
self.onDoubleClickProperty = ObservableValue<Signal>(value: onDoubleClick)
self.pressedVar = Variable<Bool>(pressed)
self.onPressVar = Variable<Signal>(onPress)
self.onReleaseVar = Variable<Signal>(onRelease)
self.onClickVar = Variable<Signal>(onClick)
self.onDoubleClickVar = Variable<Signal>(onDoubleClick)
}
}

View File

@ -1,15 +1,16 @@
import Foundation
import RxSwift
public class Group: Node {
public let contentsProperty: ObservableValue<[Node]>
public let contentsVar: Variable<[Node]>
public var contents: [Node] {
get { return contentsProperty.get() }
set(val) { contentsProperty.set(val) }
get { return contentsVar.value }
set(val) { contentsVar.value = val }
}
public init(contents: [Node] = [], pos: Transform = Transform(), opaque: NSObject = true, visible: NSObject = true, clip: Locus? = nil, tag: [String] = []) {
self.contentsProperty = ObservableValue<[Node]>(value: contents)
self.contentsVar = Variable<[Node]>(contents)
super.init(
pos: pos,
opaque: opaque,

View File

@ -1,50 +1,51 @@
import Foundation
import RxSwift
public class Image: Node {
public let srcProperty: ObservableValue<String>
public let srcVar: Variable<String>
public var src: String {
get { return srcProperty.get() }
set(val) { srcProperty.set(val) }
get { return srcVar.value }
set(val) { srcVar.value = val }
}
public let xAlignProperty: ObservableValue<Align>
public let xAlignVar: Variable<Align>
public var xAlign: Align {
get { return xAlignProperty.get() }
set(val) { xAlignProperty.set(val) }
get { return xAlignVar.value }
set(val) { xAlignVar.value = val }
}
public let yAlignProperty: ObservableValue<Align>
public let yAlignVar: Variable<Align>
public var yAlign: Align {
get { return yAlignProperty.get() }
set(val) { yAlignProperty.set(val) }
get { return yAlignVar.value }
set(val) { yAlignVar.value = val }
}
public let aspectRatioProperty: ObservableValue<AspectRatio>
public let aspectRatioVar: Variable<AspectRatio>
public var aspectRatio: AspectRatio {
get { return aspectRatioProperty.get() }
set(val) { aspectRatioProperty.set(val) }
get { return aspectRatioVar.value }
set(val) { aspectRatioVar.value = val }
}
public let wProperty: ObservableValue<Int>
public let wVar: Variable<Int>
public var w: Int {
get { return wProperty.get() }
set(val) { wProperty.set(val) }
get { return wVar.value }
set(val) { wVar.value = val }
}
public let hProperty: ObservableValue<Int>
public let hVar: Variable<Int>
public var h: Int {
get { return hProperty.get() }
set(val) { hProperty.set(val) }
get { return hVar.value }
set(val) { hVar.value = val }
}
public init(src: String, xAlign: Align = .min, yAlign: Align = .min, aspectRatio: AspectRatio = .none, w: Int = 0, h: Int = 0, pos: Transform = Transform(), opaque: NSObject = true, visible: NSObject = true, clip: Locus? = nil, tag: [String] = []) {
self.srcProperty = ObservableValue<String>(value: src)
self.xAlignProperty = ObservableValue<Align>(value: xAlign)
self.yAlignProperty = ObservableValue<Align>(value: yAlign)
self.aspectRatioProperty = ObservableValue<AspectRatio>(value: aspectRatio)
self.wProperty = ObservableValue<Int>(value: w)
self.hProperty = ObservableValue<Int>(value: h)
self.srcVar = Variable<String>(src)
self.xAlignVar = Variable<Align>(xAlign)
self.yAlignVar = Variable<Align>(yAlign)
self.aspectRatioVar = Variable<AspectRatio>(aspectRatio)
self.wVar = Variable<Int>(w)
self.hVar = Variable<Int>(h)
super.init(
pos: pos,
opaque: opaque,

View File

@ -1,43 +1,40 @@
import Foundation
import RxSwift
public class Node: Drawable {
public let posProperty: ObservableValue<Transform>
public let posVar: Variable<Transform>
public var pos: Transform {
get { return posProperty.get() }
set(val) { posProperty.set(val) }
get { return posVar.value }
set(val) { posVar.value = val }
}
public let opaqueProperty: ObservableValue<NSObject>
public let opaqueVar: Variable<NSObject>
public var opaque: NSObject {
get { return opaqueProperty.get() }
set(val) { opaqueProperty.set(val) }
get { return opaqueVar.value }
set(val) { opaqueVar.value = val }
}
public let visibleProperty: ObservableValue<NSObject>
public let visibleVar: Variable<NSObject>
public var visible: NSObject {
get { return visibleProperty.get() }
set(val) { visibleProperty.set(val) }
get { return visibleVar.value }
set(val) { visibleVar.value = val }
}
public let clipProperty: ObservableValue<Locus?>
public let clipVar: Variable<Locus?>
public var clip: Locus? {
get { return clipProperty.get() }
set(val) { clipProperty.set(val) }
get { return clipVar.value }
set(val) { clipVar.value = val }
}
public init(pos: Transform, opaque: NSObject = true, visible: NSObject = true, clip: Locus? = nil, tag: [String] = []) {
self.posProperty = ObservableValue<Transform>(value: pos)
self.opaqueProperty = ObservableValue<NSObject>(value: opaque)
self.visibleProperty = ObservableValue<NSObject>(value: visible)
self.clipProperty = ObservableValue<Locus?>(value: clip)
self.posVar = Variable<Transform>(pos)
self.opaqueVar = Variable<NSObject>(opaque)
self.visibleVar = Variable<NSObject>(visible)
self.clipVar = Variable<Locus?>(clip)
super.init(
tag: tag
)
// self.posProperty.addListener { (oldValue, newValue) in
// self.pos = newValue
// }
}
// GENERATED NOT

View File

@ -1,29 +1,30 @@
import Foundation
import RxSwift
public class Shape: Node {
public let formProperty: ObservableValue<Locus>
public let formVar: Variable<Locus>
public var form: Locus {
get { return formProperty.get() }
set(val) { formProperty.set(val) }
get { return formVar.value }
set(val) { formVar.value = val }
}
public let fillProperty: ObservableValue<Fill?>
public let fillVar: Variable<Fill?>
public var fill: Fill? {
get { return fillProperty.get() }
set(val) { fillProperty.set(val) }
get { return fillVar.value }
set(val) { fillVar.value = val }
}
public let strokeProperty: ObservableValue<Stroke?>
public let strokeVar: Variable<Stroke?>
public var stroke: Stroke? {
get { return strokeProperty.get() }
set(val) { strokeProperty.set(val) }
get { return strokeVar.value }
set(val) { strokeVar.value = val }
}
public init(form: Locus, fill: Fill? = nil, stroke: Stroke? = nil, pos: Transform = Transform(), opaque: NSObject = true, visible: NSObject = true, clip: Locus? = nil, tag: [String] = []) {
self.formProperty = ObservableValue<Locus>(value: form)
self.fillProperty = ObservableValue<Fill?>(value: fill)
self.strokeProperty = ObservableValue<Stroke?>(value: stroke)
self.formVar = Variable<Locus>(form)
self.fillVar = Variable<Fill?>(fill)
self.strokeVar = Variable<Stroke?>(stroke)
super.init(
pos: pos,
opaque: opaque,

View File

@ -1,43 +1,44 @@
import Foundation
import RxSwift
public class Text: Node {
public let textProperty: ObservableValue<String>
public let textVar: Variable<String>
public var text: String {
get { return textProperty.get() }
set(val) { textProperty.set(val) }
get { return textVar.value }
set(val) { textVar.value = val }
}
public let fontProperty: ObservableValue<Font>
public let fontVar: Variable<Font>
public var font: Font {
get { return fontProperty.get() }
set(val) { fontProperty.set(val) }
get { return fontVar.value }
set(val) { fontVar.value = val }
}
public let fillProperty: ObservableValue<Fill>
public let fillVar: Variable<Fill>
public var fill: Fill {
get { return fillProperty.get() }
set(val) { fillProperty.set(val) }
get { return fillVar.value }
set(val) { fillVar.value = val }
}
public let alignProperty: ObservableValue<Align>
public let alignVar: Variable<Align>
public var align: Align {
get { return alignProperty.get() }
set(val) { alignProperty.set(val) }
get { return alignVar.value }
set(val) { alignVar.value = val }
}
public let baselineProperty: ObservableValue<Baseline>
public let baselineVar: Variable<Baseline>
public var baseline: Baseline {
get { return baselineProperty.get() }
set(val) { baselineProperty.set(val) }
get { return baselineVar.value }
set(val) { baselineVar.value = val }
}
public init(text: String, font: Font, fill: Fill, align: Align = .min, baseline: Baseline = .top, pos: Transform = Transform(), opaque: NSObject = true, visible: NSObject = true, clip: Locus? = nil, tag: [String] = []) {
self.textProperty = ObservableValue<String>(value: text)
self.fontProperty = ObservableValue<Font>(value: font)
self.fillProperty = ObservableValue<Fill>(value: fill)
self.alignProperty = ObservableValue<Align>(value: align)
self.baselineProperty = ObservableValue<Baseline>(value: baseline)
self.textVar = Variable<String>(text)
self.fontVar = Variable<Font>(font)
self.fillVar = Variable<Fill>(fill)
self.alignVar = Variable<Align>(align)
self.baselineVar = Variable<Baseline>(baseline)
super.init(
pos: pos,
opaque: opaque,

View File

@ -1,5 +1,6 @@
import Foundation
import UIKit
import RxSwift
class GroupRenderer: NodeRenderer {
var ctx: RenderContext
@ -7,6 +8,7 @@ class GroupRenderer: NodeRenderer {
get { return group }
}
let group: Group
let disposeBag = DisposeBag()
init(group: Group, ctx: RenderContext) {
self.group = group
@ -15,10 +17,12 @@ class GroupRenderer: NodeRenderer {
}
func hook() {
func onGroupChange(old: [Node], new: [Node]) {
func onGroupChange(new: [Node]) {
ctx.view.setNeedsDisplay()
}
group.contentsProperty.addListener(onGroupChange)
group.contentsVar.asObservable().subscribeNext { new in
onGroupChange(new)
}.addDisposableTo(disposeBag)
}
func render() {

View File

@ -21,10 +21,12 @@ class ShapeRenderer: NodeRenderer {
}
private func hook() {
func onFormChange(old: Locus, new: Locus) {
func onFormChange(new: Locus) {
ctx.view.setNeedsDisplay()
}
shape.formProperty.addListener(onFormChange)
let _ = shape.formVar.asObservable().subscribeNext { newForm in
onFormChange(newForm)
}
}
private func setGeometry(locus: Locus, ctx: CGContext) {