Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Style attributes in a condition #7

Open
vvoovv opened this issue Feb 1, 2021 · 9 comments
Open

Style attributes in a condition #7

vvoovv opened this issue Feb 1, 2021 · 9 comments

Comments

@vvoovv
Copy link
Member

vvoovv commented Feb 1, 2021

It's desirable to access some variables in the condition of a style block.

Example. A small building can have only one entrance. A larger building can have exactly two entrances.

That can be realized by using the style variable count in the condition. It's proposed to prefix it with the style namespace.

facade[item.front and style.count<=1] {
  class: facade_with_door;
}
@vvoovv
Copy link
Member Author

vvoovv commented Feb 1, 2021

Other style variables may be introduced later. They should be also accessed in the similar way: style.variable.

@vvoovv
Copy link
Member Author

vvoovv commented Feb 1, 2021

style.count should be translated to self.count.

@polarkernel
Copy link
Collaborator

I see.

It would be less complicated to implement, when style.variable could appear in both, in a condition and in an arithemtic expression. Would that be OK?

Is it important to restrict variable to count and other identifiers to be introduced later, or could it be just a free name?

@vvoovv
Copy link
Member Author

vvoovv commented Feb 1, 2021

Sorry, I didn't understand what you meant by the arithmetic expression.

@vvoovv
Copy link
Member Author

vvoovv commented Feb 1, 2021

Is it important to restrict variable to count and other identifiers to be introduced later, or could it be just a free name?

I thought it should be implemented in the same way as item.variable. As far as I can see a variable for the item can be any name. Is it correct?

@polarkernel
Copy link
Collaborator

Sorry, I didn't understand what you meant by the arithmetic expression.

Something like

levels: height * style.count

Don't know if such constructions could make sense somewhere, but it would be easier not to restrict it to conditions.

I thought it should be implemented in the same way as item.variable. As far as I can see a variable for the item can be any name. Is it correct?

Yes. Any name would be accepted by the translator and not just predefined names like count.

@vvoovv
Copy link
Member Author

vvoovv commented Feb 1, 2021

Something like

levels: height * style.count

Expressions for attributes could be a useful feature. It deserves a separate issue for discussions. I'll create one.
It can be translated to something like:
levels = Value(Expression(lambda item: ...)),

Don't know if such constructions could make sense somewhere, but it would be easier not to restrict it to conditions.

Ok, let's not restrict item.variable and style.variable to conditions.

Yes. Any name would be accepted by the translator and not just predefined names like count.

Let's do the same for style.variable.

@polarkernel
Copy link
Collaborator

Style attributes in a condition implemented and commited. The example

		facade[item.front and style.count<=1] {
		class: facade_with_door;
		}

translates to

        Facade(
            condition = lambda item : item.front and self.count <= 1,
            cl = "facade_with_door"
        )

Any name behind style gets accepted. Usage in expressions will be a separate issue for discussions, as proposed.

@vvoovv
Copy link
Member Author

vvoovv commented Feb 1, 2021

Style attributes in a condition implemented and commited.

Thanks! Now I'll have to introduce style.count in the code of the addon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants