Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Attribute をAPI 使用者が追加できるようにする #34

Open
rrbox opened this issue May 1, 2023 · 3 comments
Open

Attribute をAPI 使用者が追加できるようにする #34

rrbox opened this issue May 1, 2023 · 3 comments

Comments

@rrbox
Copy link
Owner

rrbox commented May 1, 2023

再帰型構造体を使用し、SKNodeBuilder の Modifier と同じように実装することで Attribute を自作できるようになります。

@rrbox
Copy link
Owner Author

rrbox commented May 1, 2023

protocol CustomElement {
    associatedtype T
    var value: T { get }
    var keyPath: WritableKeyPath<AttributeContext, T> { get }
}

@rrbox
Copy link
Owner Author

rrbox commented May 1, 2023

protocol AttributeLinkList {
    associatedtype T: CustomElement
}

@rrbox
Copy link
Owner Author

rrbox commented May 1, 2023

構造体に KeyPath をプロパティに持たせようと以下のようなコードにしました。

struct AttributeContext {
    var container = AttributeContainer()
}

struct BackgroundColor: CustomElement {
    let value: Color
    var keyPath: WritableKeyPath<AttributeContext, Color> {
        \.container.backgroundColor
    }
}

しかし、KeyPath が static subscript を指し示すことはできないようでした。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant