Skip to content
This repository has been archived by the owner on Dec 2, 2021. It is now read-only.

a proposal for improved ergonomics #14

Open
mreinstein opened this issue Jan 5, 2019 · 2 comments
Open

a proposal for improved ergonomics #14

mreinstein opened this issue Jan 5, 2019 · 2 comments

Comments

@mreinstein
Copy link

mreinstein commented Jan 5, 2019

kiwi.js is really cool! One thing I've found painful is having to construct all of the constraints in javascript. I've developed a simplistic parser and wrapper interface to make this easier. Here's what I've currently got:

import constraints from './lib/constraints.js'   // the wrapper for kiwi.js


const layout = constraints({
    editableVariables: [
        {
            name: 'mine', 
            strength: 'strong'   // optional parameter
        }
    ],
    constraints: `
        windowWidth  <= (windowHeight - modalHeight) / 25
        windowHeight == 45 / 6
        modalHeight  == mine * 10
        windowWidth  >= 0 required
        windowHeight >= 0 required
    `
})

layout.suggestValue('mine', 102)

layout.updateVariables()

console.log(layout.getValues())
// { mine: 102, windowWidth: 0, windowHeight: 7.5, modalHeight: 1020 }

Would something like this be a welcome addition to kiwi? Open for suggestions on changing the API etc.

thanks for a great module!!

@mreinstein
Copy link
Author

current working implementation of this https://github.com/mreinstein/constraint-solver

@mreinstein
Copy link
Author

updated implementation, replaced my janky parser with one based on pegjs. (adapted the grammar from cassowary.js)

https://github.com/mreinstein/constraint-solver

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

No branches or pull requests

1 participant