Exemplo n.º 1
0
    def create(self):
        self.native = NSTextField.new()
        self.native.interface = self.interface

        self.native.bezeled = True
        self.native.bezelStyle = NSTextFieldSquareBezel

        # Add the layout constraints
        self.add_constraints()
Exemplo n.º 2
0
    def create(self):
        self.native = TogaView.alloc().init()

        self.input = NSTextField.new()
        self.input.interface = self.interface
        self.input.bezeled = True
        self.input.bezelStyle = NSTextFieldSquareBezel
        self.input.translatesAutoresizingMaskIntoConstraints = False

        self.stepper = TogaStepper.alloc().init()
        self.stepper.interface = self.interface
        self.stepper._impl = self
        self.stepper.translatesAutoresizingMaskIntoConstraints = False

        self.stepper.target = self.stepper
        self.stepper.action = SEL('onChange:')

        self.stepper.controller = self.input
        self.input.delegate = self.stepper

        # Add the input and stepper to the constraining box.
        self.native.addSubview(self.input)
        self.native.addSubview(self.stepper)

        # Add constraints to lay out the input and stepper.
        # Stepper is always top right corner.
        self.native.addConstraint(
            NSLayoutConstraint.
            constraintWithItem_attribute_relatedBy_toItem_attribute_multiplier_constant_(
                self.native, NSLayoutAttributeTop, NSLayoutRelationEqual,
                self.stepper, NSLayoutAttributeTop, 1.0, 0))
        self.native.addConstraint(
            NSLayoutConstraint.
            constraintWithItem_attribute_relatedBy_toItem_attribute_multiplier_constant_(
                self.native, NSLayoutAttributeRight, NSLayoutRelationEqual,
                self.stepper, NSLayoutAttributeRight, 1.0, 0))

        # Stepper height matches container box height
        self.native.addConstraint(
            NSLayoutConstraint.
            constraintWithItem_attribute_relatedBy_toItem_attribute_multiplier_constant_(
                self.native, NSLayoutAttributeBottom, NSLayoutRelationEqual,
                self.stepper, NSLayoutAttributeBottom, 1.0, 0))

        # Input is always left, centred vertically on the stepper
        self.native.addConstraint(
            NSLayoutConstraint.
            constraintWithItem_attribute_relatedBy_toItem_attribute_multiplier_constant_(
                self.stepper, NSLayoutAttributeCenterY, NSLayoutRelationEqual,
                self.input, NSLayoutAttributeCenterY, 1.0, 0))
        self.native.addConstraint(
            NSLayoutConstraint.
            constraintWithItem_attribute_relatedBy_toItem_attribute_multiplier_constant_(
                self.native, NSLayoutAttributeLeft, NSLayoutRelationEqual,
                self.input, NSLayoutAttributeLeft, 1.0, 0))

        # Stepper and input meet in the middle with a small gap
        self.native.addConstraint(
            NSLayoutConstraint.
            constraintWithItem_attribute_relatedBy_toItem_attribute_multiplier_constant_(
                self.stepper, NSLayoutAttributeLeft, NSLayoutRelationEqual,
                self.input, NSLayoutAttributeRight, 1.0, 2))

        # Add the layout constraints for the main box
        self.add_constraints()
Exemplo n.º 3
0
    def create(self):
        self.native = TogaView.alloc().init()

        self.input = NSTextField.new()
        self.input.interface = self.interface
        self.input.bezeled = True
        self.input.bezelStyle = NSTextFieldSquareBezel
        self.input.translatesAutoresizingMaskIntoConstraints = False

        self.stepper = TogaStepper.alloc().init()
        self.stepper.interface = self.interface
        self.stepper._impl = self
        self.stepper.translatesAutoresizingMaskIntoConstraints = False

        self.stepper.target = self.stepper
        self.stepper.action = SEL('onChange:')

        self.stepper.controller = self.input
        self.input.delegate = self.stepper

        # Add the input and stepper to the constraining box.
        self.native.addSubview(self.input)
        self.native.addSubview(self.stepper)

        # Add constraints to lay out the input and stepper.
        # Stepper is always top right corner.
        self.native.addConstraint(
            NSLayoutConstraint.constraintWithItem_attribute_relatedBy_toItem_attribute_multiplier_constant_(
                self.native, NSLayoutAttributeTop,
                NSLayoutRelationEqual,
                self.stepper, NSLayoutAttributeTop,
                1.0, 0
            )
        )
        self.native.addConstraint(
            NSLayoutConstraint.constraintWithItem_attribute_relatedBy_toItem_attribute_multiplier_constant_(
                self.native, NSLayoutAttributeRight,
                NSLayoutRelationEqual,
                self.stepper, NSLayoutAttributeRight,
                1.0, 0
            )
        )

        # Stepper height matches container box height
        self.native.addConstraint(
            NSLayoutConstraint.constraintWithItem_attribute_relatedBy_toItem_attribute_multiplier_constant_(
                self.native, NSLayoutAttributeBottom,
                NSLayoutRelationEqual,
                self.stepper, NSLayoutAttributeBottom,
                1.0, 0
            )
        )

        # Input is always left, centred vertically on the stepper
        self.native.addConstraint(
            NSLayoutConstraint.constraintWithItem_attribute_relatedBy_toItem_attribute_multiplier_constant_(
                self.stepper, NSLayoutAttributeCenterY,
                NSLayoutRelationEqual,
                self.input, NSLayoutAttributeCenterY,
                1.0, 0
            )
        )
        self.native.addConstraint(
            NSLayoutConstraint.constraintWithItem_attribute_relatedBy_toItem_attribute_multiplier_constant_(
                self.native, NSLayoutAttributeLeft,
                NSLayoutRelationEqual,
                self.input, NSLayoutAttributeLeft,
                1.0, 0
            )
        )

        # Stepper and input meet in the middle with a small gap
        self.native.addConstraint(
            NSLayoutConstraint.constraintWithItem_attribute_relatedBy_toItem_attribute_multiplier_constant_(
                self.stepper, NSLayoutAttributeLeft,
                NSLayoutRelationEqual,
                self.input, NSLayoutAttributeRight,
                1.0, 2
            )
        )

        # Add the layout constraints for the main box
        self.add_constraints()