a proposal for improved ergonomics
Opened this issue · 2 comments
mreinstein commented
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 commented
current working implementation of this https://github.com/mreinstein/constraint-solver
mreinstein commented
updated implementation, replaced my janky parser with one based on pegjs. (adapted the grammar from cassowary.js)