Skip to content

Commit 6ddbc51

Browse files
dlibby-tabatkins
andauthored
[css-env-1] Introduce environment variable indexing and viewport segment environment variables w3c#5622 (w3c#6474)
This change adds the ability to index multiple dimensions via the env() syntax. Also adds the viewport segment variables, of which there are 6 values (viewport-segment-{width, height, top, right, bottom, left}), all of which have two dimensions representing their physical location in grid-like organization of the divided viewport. Co-authored-by: Tab Atkins Jr. <jackalmage@gmail.com>
1 parent dfce5cd commit 6ddbc51

File tree

1 file changed

+91
-3
lines changed

1 file changed

+91
-3
lines changed

css-env-1/Overview.bs

+91-3
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,17 @@ These "global" variables have both benefits and downsides versus cascading varia
5252
can be retrieved via ''env()'',
5353
whereas the element-specific nature of ''var()'' was not an appropriate place to pipe that information in.
5454

55+
Most [=environment variables=] will have a single value at a time.
56+
Some, however, are "indexed", representing multiple values at once,
57+
such as the sizes and positions of several distinct panes of content
58+
in the ''viewport-segment-*'' variables.
59+
To refer to these indexed variables, one or more integers must be provided
60+
alongside the variable name,
61+
like ''viewport-segment-width 1 0'',
62+
to select a single value from the list or grid of possibilities,
63+
similar to selecting one element from a list in a traditional programming language
64+
with a syntax like <code>values[0]</code>.
65+
5566
Environment Variables {#environment}
5667
====================================
5768

@@ -85,18 +96,23 @@ Safe area inset variables {#safe-area-insets}
8596
<tr>
8697
<th>Name
8798
<th>Value
99+
<th>Number of dimensions
88100
<tr>
89101
<td><dfn>safe-area-inset-top</dfn>
90102
<td><<length>>
103+
<td>0 (scalar)
91104
<tr>
92105
<td><dfn>safe-area-inset-right</dfn>
93106
<td><<length>>
107+
<td>0 (scalar)
94108
<tr>
95109
<td><dfn>safe-area-inset-bottom</dfn>
96110
<td><<length>>
111+
<td>0 (scalar)
97112
<tr>
98113
<td><dfn>safe-area-inset-left</dfn>
99114
<td><<length>>
115+
<td>0 (scalar)
100116
</table>
101117

102118
The safe area insets are four [=environment variables=] that define a rectangle by
@@ -108,14 +124,81 @@ the rectangle to be invisible due to the nonrectangular nature of the display. T
108124
allows authors to limit the layout of essential content to the space inside of the
109125
safe area rectangle.
110126

127+
<index type=value for=env()></index>
128+
129+
Viewport segment variables {#viewport-segments}
130+
------------------------------------------------------------------
131+
132+
<table dfn-type=value dfn-for="env()">
133+
<tr>
134+
<th>Name
135+
<th>Value
136+
<th>Number of dimensions
137+
<tr>
138+
<td><dfn>viewport-segment-width</dfn>
139+
<td><<length>>
140+
<td>2
141+
<tr>
142+
<td><dfn>viewport-segment-height</dfn>
143+
<td><<length>>
144+
<td>2
145+
<tr>
146+
<td><dfn>viewport-segment-top</dfn>
147+
<td><<length>>
148+
<td>2
149+
<tr>
150+
<td><dfn>viewport-segment-left</dfn>
151+
<td><<length>>
152+
<td>2
153+
<tr>
154+
<td><dfn>viewport-segment-bottom</dfn>
155+
<td><<length>>
156+
<td>2
157+
<tr>
158+
<td><dfn>viewport-segment-right</dfn>
159+
<td><<length>>
160+
<td>2
161+
</table>
162+
163+
The viewport segments are [=environment variables=] that define the position and
164+
dimensions of a logically separate region of the viewport. Viewport
165+
segments are created when the viewport is split by one or more hardware features
166+
(such as a fold or a hinge between separate displays) that act as a divider;
167+
segments are the regions of the viewport that can be treated as logically distinct
168+
by the author.
169+
170+
The viewport segment [=environment variables=] have two dimensions, which represent
171+
the x and y position, respectively, in the two dimensional grid created by the
172+
hardware features separating the segments.
173+
Segments along the left edge have x position ''0'', those in the next column to the right have x position ''1'', etc.
174+
Similarly, segments along the top edge have y position ''0'', etc.
175+
176+
Note: In certain hardware configurations, the separator itself may occupy logical
177+
space within the viewport. The dimensions of the separator can be computed by
178+
calculating the area between the position of the viewport segments.
179+
180+
<div class="example">
181+
When the viewport is split into two side-by-side segments, the viewport segment on
182+
the left would have indices (0, 0). It's width would be represented as
183+
''env(viewport-segment-width 0 0, 300px)''.
184+
The viewport segment on the right would have indices (1, 0).
185+
Similarly, for a viewport split into two vertical segments, the viewport segment
186+
on the top would have indices (0, 0) and the one on the bottom (0, 1).
187+
</div>
188+
189+
These variables are only defined when there are at least two such segments.
190+
Viewport units should be used instead when there is no hardware feature
191+
splitting the viewport, otherwise content will not display as intended when
192+
viewed on a device with multiple segments.
193+
111194
Using Environment Variables: the ''env()'' notation {#env-function}
112195
===================================================================
113196

114197
In order to substitute the value of an [=environment variable=] into a CSS context,
115198
use the ''env()'' function:
116199

117200
<pre class=prod>
118-
<dfn function>env()</dfn> = env( <<custom-ident>> , <<declaration-value>>? )
201+
<dfn function>env()</dfn> = env( <<custom-ident>> <<integer [0,∞]>>*, <<declaration-value>>? )
119202
</pre>
120203

121204
The ''env()'' function can be used in place of any part of a value in any property on any element,
@@ -133,7 +216,10 @@ and in several other places where CSS values are allowed.
133216
</div>
134217

135218
The first argument to ''env()'' provides the name of an [=environment variable=] to be substituted.
136-
The second argument, if provided, is a fallback value,
219+
Following the first argument are integers that represent indices into the
220+
dimensions of the [=environment variable=], if the provided name
221+
represents an array-like [=environment variable=].
222+
The argument after the comma, if provided, is a fallback value,
137223
which is used as the substitution value
138224
when the referenced [=environment variable=] does not exist.
139225

@@ -156,7 +242,9 @@ It is only syntax-checked after ''env()'' functions have been [=substituted=].
156242
To <dfn export local-lt=substitute>substitute an env()</dfn> in a property or descriptor:
157243

158244
1. If the name provided by the first argument of the ''env()'' function
159-
is a recognized [=environment variable=],
245+
is a recognized [=environment variable=] name, the number of supplied integers
246+
matches the number of dimensions of the [=environment variable=] referenced
247+
by that name, and values of the indices correspond to a known sub-value,
160248
replace the ''env()'' function by the value of the named [=environment variable=].
161249

162250
2. Otherwise, if the ''env()'' function has a fallback value as its second argument,

0 commit comments

Comments
 (0)