oleksii-demedetskyi / Parus

Parus is simple chain style auto-layout helper for objective-c.
MIT License
106 stars 4 forks source link

Lib should allow user to create single constraint and save it via user defined variable or path. #5

Closed oleksii-demedetskyi closed 11 years ago

oleksii-demedetskyi commented 11 years ago

We should have ability to save single constraint into variable or property.

self.property = ;

localVariable = ;

Both this cases should be supported.

oleksii-demedetskyi commented 11 years ago

So we need discuss syntax of one constraint.

In simple case layout of views is looking as this

[view addConstraint:constraint];
[view addConstraint:constraint];
[view addConstraint:constraint];
[view addConstraint:constraint];

we can handle layout chains via custom block, but we need also support single constraint adding.

leftOf(view1).equal.rightOf(view2).plus(10);

This code will produce filled PVConstraintContext that need to be saved. Also we need access to start methods.

Also, this constraint can be described as VFL

@"H:[view1]-10-[view2]"

VFL are much more simpler and readable even our solution.

Our goal is in shorthand record both types of constraints.

layout(view).(
     @"H:[view1]-10-[view2]",
     @"V:|-[view1]-[view3]-|",
     leftOf(view1).equal.centerXOf(superview).plus(10),
);

In this case all constraints, even VFL, are listed in one expression.w

Or in current case:

[view setupLayout:^(LMMaster* $) {
    $.vfl(@"H:[view1]-10-[view2]");
    $.vfl(@"V:|-[view1]-[view3]-|");
    $.leftOf(view1).equal.centerXOf(superview).plus(10);
];
oleksii-demedetskyi commented 11 years ago

@xNekOIx @AndreyMoskvin What do you think?

oleksii-demedetskyi commented 11 years ago
layout(view).withViews(NSDictionaryBinding(...)).metrics(@{})).(
    vfl(@"H:[view1]-10-[view2]").options(...),
    vfl(@"V:|-[view1]-[view3]-|"),
    leftOf(view1).equal.centerXOf(superview).plus(10)
);
oleksii-demedetskyi commented 11 years ago

NSLayoutConstraint *constraint = ... How to define single constraint?

oleksii-demedetskyi commented 11 years ago

NSLayoutConstraint *constraint = constraintWhere(leftOf().equal.centerXOf().plus());

oleksii-demedetskyi commented 11 years ago

Another option for single constraint is

NSLayoutConstraint *consraint = rv_equation().where.leftOf(view1).equal.centerXOf(self).plus(10).asConstraint;
xNekOIx commented 11 years ago

@DAlOG @AndreyMoskvin Should it be like this: NSLayoutConstraint *consraint = PV.leftOf(view1).equal.centerXOf(self).plus(10).asConstraint; or it still could be better to use this syntax: NSLayoutConstraint *consraint = PVLeftOf(view1).equal.centerXOf(self).plus(10).asConstraint; what do you think? I like second one.

oleksii-demedetskyi commented 11 years ago

Agreed