Coder Social home page Coder Social logo

chml / textureswiftsupport Goto Github PK

View Code? Open in Web Editor NEW

This project forked from fluidgroup/textureswiftsupport

0.0 0.0 0.0 946 KB

[Alpha] It helps writing the code in Texture with Swift's power. [like SwiftUI]

License: MIT License

Ruby 10.15% Swift 84.76% Objective-C 5.09%

textureswiftsupport's Introduction

TextureSwiftSupport

TextureSwiftSupport is a support library for Texture
It helps writing the code in Texture with Swift's power.

Requirements

Swiift 5.1+

LayoutSpecBuilder (Using _functionBuidler)

Swift5.1 has FunctionBuilder(it's not officially)
With this, we can write layout spec with no more commas. (It's like SwiftUI)

SwiftUI-like Method Chain API

Inspiring from SwiftUI.

We can build a node hierarchy with the method chain.

For now, we have only a few methods. (e.g Padding, Overlay, Background)

textNode
  .padding([.vertical], padding: 4)
  .background(backgroundNode)

About Function builders

Function builders is a feature in Swift Language.
For example, SwiftUI uses it.

Implementation example

Plain

override func layoutSpecThatFits(_ constrainedSize: ASSizeRange) -> ASLayoutSpec {
    ASStackLayoutSpec(
        direction: .vertical,
        spacing: 0,
        justifyContent: .start,
        alignItems: .start,
        children: [
            textNode1,
            textNode2,
            textNode3,
        ]
    )
}

With TextureSwiftSupport

override func layoutSpecThatFits(_ constrainedSize: ASSizeRange) -> ASLayoutSpec {
    LayoutSpec {
        VStackLayout {
            textNode1
            textNode2
            textNode3
        }
    }
}

More example

override func layoutSpecThatFits(_ constrainedSize: ASSizeRange) -> ASLayoutSpec {
    LayoutSpec {
        VStackLayout {
            HStackLayout {
                InsetLayout {
                    node1
                }
                InsetLayout {
                    node2
                }
            }
            node3
            HStackLayout {
                node4,
                node5,
                node6,
            }
        }
    }
}

Layout Specs

  • VStackLayout
  • HStackLayout
  • ZStackLayout
  • InsetLayout
  • OverlayLayout
  • BackgroundLayout
  • AspectRatioLayout
  • VSpacerLayout
  • HSpacerLayout

Author

Muukii [email protected]

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.