Skip to main content

Style

Struct Style 

Source
pub struct Style {
Show 65 fields pub display: Display, pub visibility: Visibility, pub overflow: Point<Overflow>, pub scrollbar_width: AbsoluteLength, pub allow_concurrent_scroll: bool, pub restrict_scroll_to_axis: bool, pub position: Position, pub inset: Edges<Length>, pub size: Size<Length>, pub min_size: Size<Length>, pub max_size: Size<Length>, pub aspect_ratio: Option<f32>, pub margin: Edges<Length>, pub padding: Edges<DefiniteLength>, pub border_widths: Edges<AbsoluteLength>, pub align_items: Option<AlignItems>, pub align_self: Option<AlignSelf>, pub align_content: Option<AlignContent>, pub justify_content: Option<JustifyContent>, pub gap: Size<DefiniteLength>, pub flex_direction: FlexDirection, pub flex_wrap: FlexWrap, pub flex_basis: Length, pub flex_grow: f32, pub flex_shrink: f32, pub vn_order: i32, pub vn_object_position: Option<ObjectPosition>, pub background: Option<Fill>, pub background_layers: Vec<Background>, pub border_color: Option<Hsla>, pub vn_border_colors: Edges<Option<Hsla>>, pub border_style: BorderStyle, pub corner_radii: Corners<AbsoluteLength>, pub vn_corner_radii: Corners<Option<VnCornerRadius>>, pub box_shadow: Vec<BoxShadow>, pub vn_shadow_under_box: bool, pub backdrop_blur: Option<Pixels>, pub vn_effect: Option<EffectSpec>, pub vn_effect_fade: Option<EffectCrossFade>, pub vn_transform: Option<TransformSpec>, pub text: TextStyleRefinement, pub mouse_cursor: Option<CursorStyle>, pub opacity: Option<f32>, pub grid_cols: Option<GridTemplate>, pub grid_rows: Option<GridTemplate>, pub grid_location: Option<GridLocation>, pub vn_grid_cols: Option<Vec<GridTrack>>, pub vn_grid_rows: Option<Vec<GridTrack>>, pub vn_grid_cols_auto: Option<GridAutoRepeat>, pub vn_grid_rows_auto: Option<GridAutoRepeat>, pub vn_grid_auto_cols: Option<Vec<GridTrack>>, pub vn_grid_auto_rows: Option<Vec<GridTrack>>, pub vn_grid_auto_flow: Option<GridAutoFlow>, pub vn_justify_items: Option<AlignItems>, pub vn_justify_self: Option<AlignSelf>, pub vn_outline: Option<Outline>, pub vn_mask_ring: bool, pub vn_clip_path: VnClipPath, pub vn_color_matrix: Option<VnColorMatrix>, pub vn_capture: Option<u64>, pub vn_isolate: bool, pub vn_text_fill: Option<VnTextFill>, pub vn_mask: Option<VnMask>, pub debug: bool, pub debug_below: bool,
}
Expand description

The CSS styling that can be applied to an element via the Styled trait

Fields§

§display: Display

What layout strategy should be used?

§visibility: Visibility

Should the element be painted on screen?

§overflow: Point<Overflow>

How children overflowing their container should affect layout

§scrollbar_width: AbsoluteLength

How much space (in points) should be reserved for the scrollbars of Overflow::Scroll and Overflow::Auto nodes.

§allow_concurrent_scroll: bool

Whether both x and y axis should be scrollable at the same time.

§restrict_scroll_to_axis: bool

Whether scrolling should be restricted to the input gesture’s axis.

Pixel-based scroll gestures are locked to their initially dominant axis. The lock may be released when the gesture changes direction strongly. Touch phases delimit gestures when available, with a timeout fallback for platforms that only emit moved events.

This also prevents input from being remapped to another axis. For example, horizontal input will not scroll a container that only has vertical overflow enabled. Mouse wheel platforms typically report ordinary wheel input on the Y axis and Shift-modified input on the X axis.

§Motivation

On the web when scrolling with the mouse wheel, scrolling up and down will always scroll the Y axis, even when the mouse is over a horizontally-scrollable element.

The only way to scroll horizontally is to hold down Shift while scrolling, which then changes the scroll axis to the X axis.

Currently, GPUI operates differently from the web in that it will scroll an element in either the X or Y axis when scrolling with just the mouse wheel. This causes problems when scrolling in a vertical list that contains horizontally-scrollable elements, as when you get to the horizontally-scrollable elements the scroll will be hijacked.

Ideally we would match the web’s behavior and not have a need for this, but right now we’re adding this opt-in style property to limit the potential blast radius.

§position: Position

What should the position value of this struct use as a base offset?

§inset: Edges<Length>

How should the position of this element be tweaked relative to the layout defined?

§size: Size<Length>

Sets the initial size of the item

§min_size: Size<Length>

Controls the minimum size of the item

§max_size: Size<Length>

Controls the maximum size of the item

§aspect_ratio: Option<f32>

Sets the preferred aspect ratio for the item. The ratio is calculated as width divided by height.

§margin: Edges<Length>

How large should the margin be on each side?

§padding: Edges<DefiniteLength>

How large should the padding be on each side?

§border_widths: Edges<AbsoluteLength>

How large should the border be on each side?

§align_items: Option<AlignItems>

How this node’s children aligned in the cross/block axis?

§align_self: Option<AlignSelf>

How this node should be aligned in the cross/block axis. Falls back to the parents AlignItems if not set

§align_content: Option<AlignContent>

How should content contained within this item be aligned in the cross/block axis

§justify_content: Option<JustifyContent>

How should contained within this item be aligned in the main/inline axis

§gap: Size<DefiniteLength>

How large should the gaps between items in a flex container be?

§flex_direction: FlexDirection

Which direction does the main axis flow in?

§flex_wrap: FlexWrap

Should elements wrap, or stay in a single line?

§flex_basis: Length

Sets the initial main axis size of the item

§flex_grow: f32

The relative rate at which this item grows when it is expanding to fill space, 0.0 is the default value, and this value must be positive.

§flex_shrink: f32

The relative rate at which this item shrinks when it is contracting to fit into space, 1.0 is the default value, and this value must be positive.

§vn_order: i32

CSS order: a flex or grid item is laid out in ascending order, ties in document order. Painting, hit-testing and focus order keep document order.

§vn_object_position: Option<ObjectPosition>

CSS object-position of an image painted in this box; None keeps ObjectFit::get_bounds’s placement.

§background: Option<Fill>

The fill color of this element

§background_layers: Vec<Background>

Extra background layers painted OVER Style::background, bottom layer first — CSS’s background-image stack, which sits above background-color.

One quad per layer rather than a layer array inside the quad: painter’s order already composites them in the right sequence, the scene’s sort and cull need no new concept, and nothing about the shader changes. The cost is one extra primitive per layer, which is why a caller is expected to keep the stack short.

CSS lists layers top-first; this vector is bottom-first, so the mapper reverses.

§border_color: Option<Hsla>

The border color of this element

§vn_border_colors: Edges<Option<Hsla>>

CSS side colours override the shared colour independently.

§border_style: BorderStyle

The border style of this element

§corner_radii: Corners<AbsoluteLength>

The radius of the corners of this element

§vn_corner_radii: Corners<Option<VnCornerRadius>>

vue-native fork: a CSS corner radius corner_radii cannot hold. That is a percentage of the box, a calc() with one, or an elliptical a / b corner. Where a corner has one, it replaces that corner’s corner_radii, and it resolves against the box at paint (Style::corner_radii_for). vn-css writes both fields for every corner it maps, so the later declaration wins whichever it used.

§box_shadow: Vec<BoxShadow>

Box shadow of the element

§vn_shadow_under_box: bool

vue-native fork: draw the outer shadows under the border box too.

CSS clips an outer box-shadow to the outside of the border box (CSS Backgrounds 3 §7.1): the shadow is cast as if the box were opaque, so a translucent background shows what is behind the element, not the shadow. Window::paint_drop_shadows does that by default. This switch is for a shadow that stands in for the element’s own painting: vue-native draws filter: blur() on a solid box as the box’s own Gaussian shadow, whose middle must stay filled.

§backdrop_blur: Option<Pixels>

CSS backdrop-filter: blur(<length>): blur everything already painted behind this element’s border box, clipped to corner_radii.

None (and a non-positive radius) means no backdrop filter. Only the blur() filter function is modelled; the rest of the CSS filter function list is not.

§vn_effect: Option<EffectSpec>

The --shading: <effect>(<args>) custom property: shade this element’s border box with one of the built-in effect pipelines.

None means the property was never declared. --shading: none is EffectSpec::NONE — a value, because a refinement cannot spell “explicitly nothing” and that is what has to cancel an effect declared by an earlier rule in the cascade. Same shape as backdrop-filter: none mapping to a 0px radius.

Deliberate divergence from CSS, documented for authors: a browser inherits custom properties down the subtree. vue-native applies --shading to the declaring element only — inheriting a GPU effect into every descendant is never what an author means, and a browser ignores the property entirely anyway, so nothing renders differently there.

§vn_effect_fade: Option<EffectCrossFade>

A --shading transition between different effects: the outgoing one, painted beneath vn_effect while they cross-fade.

§vn_transform: Option<TransformSpec>

CSS transform: rotate, scale and translate this element’s PAINTED output — its background, borders, shadows, text and its whole subtree — about its own centre, changing no layout at all.

None means the property was never declared; TransformSpec::IDENTITY is transform: none, a value, because a refinement cannot spell “explicitly nothing” and that is what has to cancel a transform declared by an earlier rule in the cascade. Same shape as vn_effect above, and as backdrop-filter: none mapping to a 0px radius.

Layout is untouched on purpose, and that is the browser’s rule rather than a shortcut: a transformed element still occupies exactly the box it laid out in, its siblings do not move, and its scroll container does not grow. It also means translate() here is NOT interchangeable with a margin offset — which is the divergence this field exists to retire.

Hit-testing follows the picture: a hitbox records the matrix in force when it was inserted and the pointer is mapped back through the inverse, so a rotated button is clickable where it is drawn.

§text: TextStyleRefinement

The text style of this element

§mouse_cursor: Option<CursorStyle>

The mouse cursor style shown when the mouse pointer is over an element.

§opacity: Option<f32>

The opacity of this element

§grid_cols: Option<GridTemplate>

The grid columns of this element Roughly equivalent to the Tailwind grid-cols-<number>

§grid_rows: Option<GridTemplate>

The row span of this element Equivalent to the Tailwind grid-rows-<number>

§grid_location: Option<GridLocation>

The grid location of this element

§vn_grid_cols: Option<Vec<GridTrack>>

CSS grid-template-columns as an ARBITRARY track list — 1fr auto, minmax(0, 1fr) 200px, repeat(3, 1fr) (expanded by the caller).

Takes precedence over Style::grid_cols, which stays as the cheap repeat(N, …) shorthand the Styled helpers write. None means “this element declared no track list”, not “no columns”.

§vn_grid_rows: Option<Vec<GridTrack>>

CSS grid-template-rows as an arbitrary track list. See Style::vn_grid_cols.

§vn_grid_cols_auto: Option<GridAutoRepeat>

The repeat(auto-fill | auto-fit, …) run of Style::vn_grid_cols, if it has one. Meaningless without that list.

§vn_grid_rows_auto: Option<GridAutoRepeat>

The repeat(auto-fill | auto-fit, …) run of Style::vn_grid_rows.

§vn_grid_auto_cols: Option<Vec<GridTrack>>

CSS grid-auto-columns: a repeating pattern for implicit column tracks.

§vn_grid_auto_rows: Option<Vec<GridTrack>>

CSS grid-auto-rows: a repeating pattern for implicit row tracks.

§vn_grid_auto_flow: Option<GridAutoFlow>

CSS grid-auto-flow — the direction the auto-placement algorithm fills, and whether it packs densely.

§vn_justify_items: Option<AlignItems>

CSS justify-items — the inline-axis alignment this container gives its children. (align_items is the block axis; taffy honours both, gpui only ever exposed the second.)

§vn_justify_self: Option<AlignSelf>

CSS justify-self — this item’s own inline-axis alignment, overriding its container’s justify-items.

§vn_outline: Option<Outline>

CSS outline — a ring painted OUTSIDE the border box that takes no layout space at all, which is what makes it (and not a border) the right primitive for a focus indicator.

gpui has no outline in its scene; this is painted as one extra border-only quad at dilated bounds, after the element’s own border, so it lands on top of the element and outside it. None = never declared.

§vn_mask_ring: bool

vue-native fork: CSS mask in the one shape the paint path can cut, the gradient-border idiom. That is two opaque layers, the top one clipped to the content box, composited with exclude: mask: linear-gradient(#fff 0 0) content-box, linear-gradient(#fff 0 0); mask-composite: exclude. What is left visible is the ring of padding and border around the content box.

When set, the background and its layers paint only in that ring, as one quad each whose border widths are the border plus the padding (color::BG_RING). The border lies inside the ring and paints as usual. Not painted at all: the outer shadows and the outline, which lie outside the border box and which the mask cuts entirely, and the inset shadows, backdrop blur and effect quads, which the ring would show only a strip of. The children are NOT masked. vn-tree says so when there are any. A percentage padding resolves against the element’s own width here, not its containing block’s.

§vn_clip_path: VnClipPath

vue-native fork: CSS clip-path, in the shapes a rounded content mask carries (VnClipPath). It clips the element’s whole painting, its shadows, background, border, outline and subtree, and its hit test, inside its transform.

§vn_color_matrix: Option<VnColorMatrix>

SVG color filtering of the whole painted subtree.

§vn_capture: Option<u64>

vue-native fork: paint this element into the snapshot of this id instead of the page (Window::vn_with_capture).

§vn_isolate: bool

vue-native fork: paint the subtree into an isolated group, so a plus-lighter composite inside blends with the group only.

§vn_text_fill: Option<VnTextFill>

CSS backgrounds painted through the descendant glyph alpha, not the box.

§vn_mask: Option<VnMask>

CSS mask over the element’s whole painting, inside its clip-path.

§debug: bool

Whether to draw a red debugging outline around this element

§debug_below: bool

Whether to draw a red debugging outline around this element and all of its conforming children

Implementations§

Source§

impl Style

Source

pub fn has_opaque_background(&self) -> bool

Returns true if the style is visible and the background is opaque.

Source

pub fn text_style(&self) -> Option<&TextStyleRefinement>

Get the text style in this element style.

Source

pub fn text_style_for_bounds( &self, bounds: Bounds<Pixels>, window: &Window, ) -> Option<TextStyleRefinement>

Text refinements with the background positioning box resolved for paint. Layout uses text_style because this scope must not change glyph shaping.

Source

pub fn corner_radii_for( &self, size: Size<Pixels>, rem_size: Pixels, ) -> Corners<Pixels>

vue-native fork: the corner radii this style paints on a box of size, percentages, the overlap rule and all. See vn_resolve_corner_radii.

Source

pub fn overflow_mask( &self, bounds: Bounds<Pixels>, rem_size: Pixels, ) -> Option<ContentMask<Pixels>>

Get the content mask for this element style, based on the given bounds. If the element does not hide its overflow, this will return None.

Source

pub fn vn_clip_mask( &self, bounds: Bounds<Pixels>, rem_size: Pixels, ) -> Option<ContentMask<Pixels>>

vue-native fork: the mask clip-path cuts this element’s painting and hit test to (Style::vn_clip_path), for the border box bounds, in the element’s own frame. None without a clip.

A shape that is no rounded rectangle (Style::vn_clip_outline) gives the rectangle around its outline here, which culls and cuts the isolated layer the outline is then composited through.

Source

pub fn vn_clip_outline( &self, bounds: Bounds<Pixels>, rem_size: Pixels, ) -> Option<VnClipOutline>

vue-native fork: the outline of a clip-path that is no rounded rectangle (polygon(), path(), an ellipse whose radii differ), laid against its reference box for the border box bounds, in the element’s own frame. None for no clip and for a shape Style::vn_clip_mask carries alone. The element paints into an isolated layer composited through it (Window::vn_with_clip_shape).

Source

pub fn transform_matrix( &self, bounds: Bounds<Pixels>, scale_factor: f32, ) -> TransformationMatrix

The device-space matrix this style’s CSS transform produces for an element laid out at bounds, or the identity when there is none.

Shared by paint (which pushes it onto the primitives) and prepaint (which records it on the hitbox), so the picture and the hit test can never disagree about where the element is.

Source

pub fn paint( &self, bounds: Bounds<Pixels>, window: &mut Window, cx: &mut App, continuation: impl FnOnce(&mut Window, &mut App), )

Paints the background of an element styled with this style.

Source

pub fn vn_reads_content(&self) -> bool

Whether an effect of this style reads the element’s content, whose deferred descendants then paint into it (Window::vn_with_defer_scope).

Trait Implementations§

Source§

impl Clone for Style

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Style

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Style

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl From<StyleRefinement> for Style

Source§

fn from(value: StyleRefinement) -> Self

Converts to this type from the input type.
Source§

impl Refineable for Style

Source§

type Refinement = StyleRefinement

Source§

fn refine(&mut self, refinement: &Self::Refinement)

Applies the given refinement to this instance, modifying it in place. Read more
Source§

fn refined(self, refinement: Self::Refinement) -> Self

Returns a new instance with the refinement applied, equivalent to cloning self and calling refine on it.
Source§

fn is_superset_of(&self, refinement: &Self::Refinement) -> bool

Returns true if this instance would contain all values from the refinement. Read more
Source§

fn subtract(&self, refinement: &Self::Refinement) -> Self::Refinement

Returns a refinement that represents the difference between this instance and the given refinement. Read more
Source§

fn from_cascade(cascade: &Cascade<Self>) -> Self
where Self: Sized + Default,

Creates an instance from a cascade by merging all refinements atop the default value.

Auto Trait Implementations§

§

impl !RefUnwindSafe for Style

§

impl !Send for Style

§

impl !Sync for Style

§

impl !UnwindSafe for Style

§

impl Forget for Style

§

impl Freeze for Style

§

impl Move for Style

§

impl Unpin for Style

§

impl UnsafeUnpin for Style

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more