Пример #1
0
 def constrain_to_scrollview(self, widget):
     # The scrollview should know the content size as long as the
     # view contained has an intrinsic size and the constraints are
     # not ambiguous in any axis.
     view = widget.native
     leading_constraint = \
         NSLayoutConstraint.constraintWithItem_attribute_relatedBy_toItem_attribute_multiplier_constant_(
             view,
             NSLayoutAttributeLeading,
             NSLayoutRelationEqual,
             self.native,
             NSLayoutAttributeLeading,
             1.0,
             0
         )
     trailing_constraint = \
         NSLayoutConstraint.constraintWithItem_attribute_relatedBy_toItem_attribute_multiplier_constant_(
             self.native,
             NSLayoutAttributeTrailing,
             NSLayoutRelationEqual,
             view,
             NSLayoutAttributeTrailing,
             1.0,
             0
         )
     top_constraint = \
         NSLayoutConstraint.constraintWithItem_attribute_relatedBy_toItem_attribute_multiplier_constant_(
             view,
             NSLayoutAttributeTop,
             NSLayoutRelationEqual,
             self.native,
             NSLayoutAttributeTop,
             1.0,
             0
         )
     bottom_constraint = \
         NSLayoutConstraint.constraintWithItem_attribute_relatedBy_toItem_attribute_multiplier_constant_(
             self.native,
             NSLayoutAttributeBottom,
             NSLayoutRelationEqual,
             view,
             NSLayoutAttributeBottom,
             1.0,
             0
         )
     self.native.addConstraints_([
         leading_constraint,
         trailing_constraint,
         top_constraint,
         bottom_constraint
     ])
Пример #2
0
 def constrain_placeholder_label(self):
     leading_constraint = \
         NSLayoutConstraint.constraintWithItem_attribute_relatedBy_toItem_attribute_multiplier_constant_(
             self.placeholder_label,
             NSLayoutAttributeLeading,
             NSLayoutRelationEqual,
             self.native,
             NSLayoutAttributeLeading,
             1.0,
             4.0
         )
     trailing_constraint = \
         NSLayoutConstraint.constraintWithItem_attribute_relatedBy_toItem_attribute_multiplier_constant_(
             self.placeholder_label,
             NSLayoutAttributeTrailing,
             NSLayoutRelationEqual,
             self.native,
             NSLayoutAttributeTrailing,
             1.0,
             0
         )
     top_constraint = \
         NSLayoutConstraint.constraintWithItem_attribute_relatedBy_toItem_attribute_multiplier_constant_(
             self.placeholder_label,
             NSLayoutAttributeTop,
             NSLayoutRelationEqual,
             self.native,
             NSLayoutAttributeTop,
             1.0,
             8.0
         )
     bottom_constraint = \
         NSLayoutConstraint.constraintWithItem_attribute_relatedBy_toItem_attribute_multiplier_constant_(
             self.placeholder_label,
             NSLayoutAttributeBottom,
             NSLayoutRelationEqual,
             self.native,
             NSLayoutAttributeBottom,
             1.0,
             0
         )
     self.native.addConstraints_([
         leading_constraint,
         trailing_constraint,
         top_constraint,
         bottom_constraint
     ])
Пример #3
0
 def constrain_placeholder_label(self):
     leading_constraint = NSLayoutConstraint.constraintWithItem_attribute_relatedBy_toItem_attribute_multiplier_constant_(
         self.placeholder_label,
         NSLayoutAttributeLeading,
         NSLayoutRelationEqual,
         self.native,
         NSLayoutAttributeLeading,
         1.0,
         4.0
     )
     trailing_constraint = NSLayoutConstraint.constraintWithItem_attribute_relatedBy_toItem_attribute_multiplier_constant_(
         self.placeholder_label,
         NSLayoutAttributeTrailing,
         NSLayoutRelationEqual,
         self.native,
         NSLayoutAttributeTrailing,
         1.0,
         0
     )
     top_constraint = NSLayoutConstraint.constraintWithItem_attribute_relatedBy_toItem_attribute_multiplier_constant_(
         self.placeholder_label,
         NSLayoutAttributeTop,
         NSLayoutRelationEqual,
         self.native,
         NSLayoutAttributeTop,
         1.0,
         8.0
     )
     bottom_constraint = NSLayoutConstraint.constraintWithItem_attribute_relatedBy_toItem_attribute_multiplier_constant_(
         self.placeholder_label,
         NSLayoutAttributeBottom,
         NSLayoutRelationEqual,
         self.native,
         NSLayoutAttributeBottom,
         1.0,
         0
     )
     self.native.addConstraints_([
         leading_constraint,
         trailing_constraint,
         top_constraint,
         bottom_constraint
     ])
Пример #4
0
    def container(self, value):
        self._container = value
        # print("Add constraints for", self.widget, 'in', self.container, self.widget.interface.layout)
        self.left_constraint = \
            NSLayoutConstraint.constraintWithItem_attribute_relatedBy_toItem_attribute_multiplier_constant_(
                self.widget.native, NSLayoutAttributeLeft,
                NSLayoutRelationEqual,
                self.container.native, NSLayoutAttributeLeft,
                1.0, 10  # Use a dummy, non-zero value for now
            )
        self.container.native.addConstraint_(self.left_constraint)

        self.top_constraint = \
            NSLayoutConstraint.constraintWithItem_attribute_relatedBy_toItem_attribute_multiplier_constant_(
                self.widget.native, NSLayoutAttributeTop,
                NSLayoutRelationEqual,
                self.container.native, NSLayoutAttributeTop,
                1.0, 5  # Use a dummy, non-zero value for now
            )
        self.container.native.addConstraint_(self.top_constraint)

        self.width_constraint = \
            NSLayoutConstraint.constraintWithItem_attribute_relatedBy_toItem_attribute_multiplier_constant_(
                self.widget.native, NSLayoutAttributeRight,
                NSLayoutRelationEqual,
                self.widget.native, NSLayoutAttributeLeft,
                1.0, 50  # Use a dummy, non-zero value for now
            )
        self.container.native.addConstraint_(self.width_constraint)

        self.height_constraint = \
            NSLayoutConstraint.constraintWithItem_attribute_relatedBy_toItem_attribute_multiplier_constant_(
                self.widget.native, NSLayoutAttributeBottom,
                NSLayoutRelationEqual,
                self.widget.native, NSLayoutAttributeTop,
                1.0, 30  # Use a dummy, non-zero value for now
            )
        self.container.native.addConstraint_(self.height_constraint)