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

Write chapter about modifiers in ref() #21

Closed
veosotano opened this issue Dec 15, 2011 · 7 comments
Closed

Write chapter about modifiers in ref() #21

veosotano opened this issue Dec 15, 2011 · 7 comments
Labels

Comments

@veosotano
Copy link
Member

When the selector in a ref() points to multiple elements, by default the first one is chosen (or should it error out?), unless you set a modifier (min, max, avg, total), in which case the element is taken from the appropriate element (or in case of total [or should it be called "sum"?] from all of them).

For example:

ref(total width of foo) //uses the sum of all widths of all selected foo elements
ref(avg height of bar) //uses the average of all heights of all selected bar elements

Complete example:

XML:
<root>
    <elementA />
    <elementB />
    <elementC />
</root>

HSS:
root
{
    elementA
    {
        width: ref(max height of *); //this would choose the height of elementB
        height: 100;
    }
    elementB
    {
        height: 200;
    }
    elementC
    {
        height: 150;
    }
}

Udated: fixed the example

@Apanatshka
Copy link

Perhaps total is more intuitive for non-programmers, but programmers will expect sum.

As for the error or choosing the first, perhaps it should do both?

I would like being able to use these modifiers on variable height as well so you could do something like this:

XML:
<columnwrapper>
    <column>Short or long column text.</column>
    <column>Other short or long column text. </column>
</columnwrapper>

HSS:
columnwrapper {
    column {
        height: ref(max height of column);
    }
}

So the column with the largest amount of text will have the largest height, and the other column next to it has the same height.

@veosotano
Copy link
Member Author

This is exactly what they are meant for. In the example I used fixed values just to illustrate the concept, but if the height is dependent on the parent (with percentages), for example, or bases on the content text, or ref'd, it would work just as well, no worries.

@Mouvedia
Copy link
Member

That's an edge case but in your example I think if you are using min it should select elementB elementA (and elementC for max). All these modifiers must have a common/consistent behavior: act on every elements selected. If negative numbers aren't allowed Id choose sum over total.

@veosotano
Copy link
Member Author

How is equal height columns an edge case? And yes, you are totally right, my example is screwed up. It should select elementC instead. But why do you think it should select elementB with min? elementA is only 100 points tall, so it should be selected, don't you think?

Positive or negative would depend on the property you are ref'ing, and I guess the height property will have its own requirements, but that's besides the point.

@Mouvedia
Copy link
Member

elementA is only 100 points tall, so it should be selected, don't you think?

Yes indeed.

@veosotano
Copy link
Member Author

I'll sum up the questions of this thread, to focus our discussion:

1 - If ref(property of element) is used and multiple elements are selected (by element), should it error out, or just select the first one? There maybe should be the notion of "default selection", which spells out some rules to know what will be selected by default.
One place where we need to have special rules is with @this. Consider this example:

    @container square
    {
        height: ref(width of @this);  //A

        @this:first //B
        {
            background: #D;
        }
    }

    myElement { isA: square; width: 200; }
    myElement:first { width: 150 }
    myElement:last  { width: 250 }

In the case of A, it seems pretty obvious that @this should select the current element that is using the ref(), but in case of B, the @this selector should select all myElement elements, and then filter down to the first one. Therefore selector chains using @this inside a ref() need to select all applicable elements (just as rules using @this do), but by default select the element that is using the ref(), if no modifier has been used.

2 - We need to agree on a list of modifiers. My proposal is:

min
max
avg
total

@Mouvedia
Copy link
Member

1 - It should error out to the first match (it could be considered an alias of element[1]). But you should be able to use [Nth]: for example ref(property of element[2]) would select the second one.
Lemme explain if the height of the multiple elements is not set in the HSS but depends on the content of these elements (variable) it means that each element will return a different height hence the ref() will need a default element (first match seems the most logical choice) unless you are using [Nth].

2 -
I prefer sum over total. It will be coherent with the other modifiers (3 letters):

min
max
avg
sum

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

No branches or pull requests

3 participants