vislyhq / stretch

High performance flexbox implementation written in rust
https://vislyhq.github.io/stretch/
MIT License
1.99k stars 107 forks source link

Question: How it combined with iOS and UIKit? #68

Closed BlakeRxxk closed 4 years ago

BlakeRxxk commented 4 years ago

I decided to try stretch in demo project and I get frustrated. How should I work with UIView/UILabels and etc.

for example (layout code from docs with small tweaks):

class ViewController: UIViewController {
  let firstView: UIView = UIView()
  let secondView: UIView = UIView()

  override func loadView() {
    view = UIView()

    view.addSubview(firstView)
    view.addSubview(secondView)
  }

  override func viewDidLoad() {
    super.viewDidLoad()
    view.backgroundColor = .systemTeal
    firstView.backgroundColor = .systemPink
    secondView.backgroundColor = .magenta
  }

  override func viewDidLayoutSubviews() {
    super.viewDidLayoutSubviews()
    let node = Node(
      style: Style(justifyContent: .center,
                   size: Size(width: .points(375.0), height: .points(100.0))),
      children: [
        Node(style: Style(size: Size(width: .percent(0.5), height: .percent(0.5))), children: []),
        Node(style: Style(size: Size(width: .percent(0.5), height: .percent(0.5))), children: [])
      ])

    let layout = node.computeLayout(thatFits: Size(width: nil, height: nil))

    print("width: \(layout.width), height: \(layout.height)")
  }
}

questions:

ps: stretch looks very promising and it need better documentation with examples

emilsjolander commented 4 years ago

Hey Blake, Stretch isn't really designed to be used from user-space code. It is more designed to be used at the heart of GUI libraries and thus provides a very low level api. It is up to higher level libraries and frameworks to provide a consistent api frontend to stretch. The reason for this is so that we can focus on the algorithmic implementation and low level platform bindings in this project and don't need to worry about supporting bindings for every platform and UI framework out there.

BlakeRxxk commented 4 years ago

Oh I see. I thought about Stretch as replacement of Yoga+YogaKit, my mistake. Anyway, interesting project 👍

emilsjolander commented 4 years ago

It's a replacement for Yoga :) I would love to have the YogaKit equivalent implemented on top of Stretch but it is not something we have the time to maintain as part of this repository. If that is something you would like to build I'm more than happy to give input on implementation as well as feature your project on the stretch website 👍

BlakeRxxk commented 4 years ago

Actually I was thinking about it. I'll take a shot 👍