constraint.dart 1.03 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

pq's avatar
pq committed
18
  @override
19 20 21 22 23 24
  String toString() {
    StringBuffer buffer = new StringBuffer();
    buffer.write(expression.toString());

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

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

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

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