Giter Club home page Giter Club logo

cassowary-rs's Introduction

cassowary-rs

Build Status

This is a Rust implementation of the Cassowary constraint solving algorithm (Badros et. al 2001). It is based heavily on the implementation for C++ at nucleic/kiwi. The implementation does however differ in some details.

Cassowary is designed for solving constraints to lay out user interfaces. Constraints typically take the form "this button must line up with this text box", or "this box should try to be 3 times the size of this other box". Its most popular incarnation by far is in Apple's Autolayout system for Mac OS X and iOS user interfaces. UI libraries using the Cassowary algorithm manage to achieve a much more natural approach to specifying UI layouts than traditional approaches like those found in HTML.

This library is a low level interface to the solving algorithm, though it tries to be as convenient as possible. As a result it does not have any intrinsic knowledge of common user interface conventions like rectangular regions or even two dimensions. These abstractions belong in a higher level crate.

For more information, please read the documentation.

Getting Started

Add the following to your Cargo.toml:

[dependencies]
cassowary = "^0.3.0"

Please read the documentation (linked above) for how to best use this crate.

License

Licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

cassowary-rs's People

Contributors

andrewhickman avatar christolliday avatar dylanede avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

cassowary-rs's Issues

Pipe brackets syntax

I apologize ahead for a dumb question, but what exactly is the pipe brackets syntax used in Constraints definition. For example (taken from docs):

let mut solver = Solver::new();
solver.add_constraints(&[window_width |GE(REQUIRED)| 0.0, // positive window width
                          box1.left |EQ(REQUIRED)| 0.0, // left align
                          box2.right |EQ(REQUIRED)| window_width, // right align
                          box2.left |GE(REQUIRED)| box1.right, // no overlap
                          // positive widths
                          box1.left |LE(REQUIRED)| box1.right,
                          box2.left |LE(REQUIRED)| box2.right,
                          // preferred widths:
                          box1.right - box1.left |EQ(WEAK)| 50.0,
                          box2.right - box2.left |EQ(WEAK)| 100.0]).unwrap();

It's not a bitwise OR operator, and it doesn't seem to be an alternative pattern matching either. So, what an ENUM is doing between those pipe brackets, and how does it work?

casuarius fork

I just wanted to mention here that I've forked this repo to https://github.com/schell/casuarius. Our versions have diverged quite a bit and I don't want to put extra burden on maintaining this original repo. Thanks again for the great implementation :)

How to maximise particular variables?

I'm trying to find a maximal solution for my problem. I found an example where they maximize P here, which translated to Rust would be:

let p = Variable::new();
let x = Variable::new();
let y = Variable::new();

let mut solver = Solver::new();
solver.add_constraints(&[
    p |EQ(REQUIRED)| x * -3.0 + y * -4.0,
    x + y |LE(REQUIRED)| 4.0,
    x * 2.0 + y |LE(REQUIRED)| 5.0,
    x |GE(REQUIRED)| 0.0,
    y |GE(REQUIRED)| 0.0
]).unwrap();

println!("Values:");
println!("P: {}", solver.get_value(p));  // -15
println!("x: {}", solver.get_value(x));  // 1
println!("y: {}", solver.get_value(y));  // 3

Except, I don't know how to specify that I want to optimize for P. I should get the values P=-16, x=0, y=4. How can I get similar results using your Cassowary crate?

Required strength on edit variable

I am using edit variables to add variables that represent the width and height of the UI viewport. I am thinking these should probably be of REQUIRED strength, but the solver doesn't seem to accept this strength on edit variables.

If the size of the viewport is not required, I think I might sometimes get strange results where the solver decides to change the viewport size. This isn't supposed to happen. Do you have any ideas what I might do here?

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.