vstyle.h Header
Platform Contract
Types
| struct | ResolvedStyle | Style values resolved for a single node, ready for a reconciler to apply to its native widget. |
Functions
| ResolvedStyle | resolve_style(Layers::LLayer * style, const std::vector<std::string> & states = {}) |
| void | apply_mobile_scale(ResolvedStyle & rs, Layers::LLayer * style, const std::vector<std::string> & states, bool is_icon, double icon_scale, double font_scale, double metric_scale) |
Function Documentation
ResolvedStyle resolve_style(Layers::LLayer * style, const std::vector<std::string> & states = {})
Resolves a style's attributes into a ResolvedStyle for the given states.
states holds the active state names without the @, like
{ "Desktop", "Narrow" }, and each attribute takes its most specific
matching value. A missing attribute leaves its member at the default
instead of failing, and a null style returns all defaults.
This only reads the style. While building the render tree, the core then
applies apply_mobile_scale(), runtime binds, and
the style's bind to the result.
void apply_mobile_scale(ResolvedStyle & rs, Layers::LLayer * style, const std::vector<std::string> & states, bool is_icon, double icon_scale, double font_scale, double metric_scale)
Scales a resolved style's pixel values up for phone-class platforms.
An interface sized for desktop and web is generally too small on a phone.
Rather than needing an @Mobile value on every attribute, this multiplies
the resolved values by one of three factors, chosen by what each value
sizes:
| Factor | Scales... |
|---|---|
icon_scale |
width and height on an Icon node |
font_scale |
fontSize |
metric_scale |
width and height on other nodes, plus spacing, the margins, padding, corner radii, and borderThickness |
Each group needs a different increase at the same screen size: icons the
most, text a little less, and spacing in step with the content around it.
VApp passes 1.5 for icons and 1.25 for the others by default (see
VPlatform::set_mobile_icon_scale()).
An attribute with its own @Mobile value (including a combined state like
@Mobile&Narrow) keeps that value as authored, so exceptions still work.
Only pixel lengths scale, so values like grow, rotation, and
fontWeight don't. maxWidth doesn't scale either, since it caps a size
rather than setting one.
Label << Vortex/Text:
Font.Size: 14 // 17.5 with a `font_scale` of 1.25
Padding.(Left,Right): 8 // 10 with a `metric_scale` of 1.25
Margins.Top: 4 @Mobile: 12 // 12, since it has an `@Mobile` value
Layout.Grow: 1 // 1, since it isn't a pixel length
Does nothing unless states contains "Mobile". A factor of 1, or a
value of 0 (unset), also leaves a value alone.
rs is the style to scale, from resolve_style().style and states are the same arguments passed to resolve_style(),
used to find @Mobile values.is_icon picks icon_scale over metric_scale for width and
height.