constraint.dart 1.01 KB
Newer Older
Chinmay Garde's avatar
Chinmay Garde committed
1 2 3 4 5 6 7 8 9 10 11
// Copyright (c) 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

part of cassowary;

enum Relation { equalTo, lessThanOrEqualTo, greaterThanOrEqualTo, }

class Constraint {
  final Relation relation;
  final Expression expression;
12
  double priority = Priority.required;
Chinmay Garde's avatar
Chinmay Garde committed
13

14
  Constraint(this.expression, this.relation);
15 16

  Constraint operator |(double p) => this..priority = p;
17 18 19 20 21 22 23

  String toString() {
    StringBuffer buffer = new StringBuffer();
    buffer.write(expression.toString());

    switch (relation) {
      case Relation.equalTo:
Hixie's avatar
Hixie committed
24
        buffer.write(' == 0 ');
25 26
        break;
      case Relation.greaterThanOrEqualTo:
Hixie's avatar
Hixie committed
27
        buffer.write(' >= 0 ');
28 29
        break;
      case Relation.lessThanOrEqualTo:
Hixie's avatar
Hixie committed
30
        buffer.write(' <= 0 ');
31 32 33
        break;
    }

Hixie's avatar
Hixie committed
34
    buffer.write(' | priority = $priority');
35

36
    if (priority == Priority.required) {
Hixie's avatar
Hixie committed
37
      buffer.write(' (required)');
38 39 40 41
    }

    return buffer.toString();
  }
Chinmay Garde's avatar
Chinmay Garde committed
42
}