struct UI::DesignTokens::DeviceMetrics

Overview

A snapshot of the device's runtime layout metrics.

Renderers populate this at render time by calling the appropriate OS API:

iOS: UIScreen.main.bounds + view.safeAreaInsets + UITraitCollection macOS: NSScreen.mainScreen.frame + NSWindow size class web: window.innerWidth + window.innerHeight + media query

The Crystal-side screen author NEVER constructs one of these directly; they call DeviceMetrics.current (which delegates to the active renderer's runtime query) and read the semantic values.

Defined in:

ui/design_tokens.cr

Constructors

Class Method Summary

Instance Method Summary

Constructor Detail

def self.current : DeviceMetrics #

Returns the current renderer-provided metrics snapshot. Convenience that delegates to Device.current.


[View source]
def self.new(screen_width_pt : Float64, screen_height_pt : Float64, safe_area_top_pt : Float64, safe_area_bottom_pt : Float64, safe_area_leading_pt : Float64, safe_area_trailing_pt : Float64, horizontal_size_class : SizeClass, vertical_size_class : SizeClass) #

[View source]

Class Method Detail

def self.reset_provider : Nil #

Reset the installed provider to the spec-time fallback.


[View source]

Instance Method Detail

def clone #

[View source]
def compact_horizontal? : Bool #

true on iPhone portrait, an iPad Slide Over panel, a narrow macOS window. Authors branch layout on this to switch a 2-column split to a stacked single column.


[View source]
def compact_vertical? : Bool #

[View source]
def content_height_pt : Float64 #

[View source]
def content_width_pt : Float64 #

The content rectangle (frame minus safe-area insets). Use this when laying out a sticky header / bottom action bar that must respect the Dynamic Island + home indicator.


[View source]
def copy_with(screen_width_pt _screen_width_pt = @screen_width_pt, screen_height_pt _screen_height_pt = @screen_height_pt, safe_area_top_pt _safe_area_top_pt = @safe_area_top_pt, safe_area_bottom_pt _safe_area_bottom_pt = @safe_area_bottom_pt, safe_area_leading_pt _safe_area_leading_pt = @safe_area_leading_pt, safe_area_trailing_pt _safe_area_trailing_pt = @safe_area_trailing_pt, horizontal_size_class _horizontal_size_class = @horizontal_size_class, vertical_size_class _vertical_size_class = @vertical_size_class) #

[View source]
def horizontal_size_class : SizeClass #

def regular_horizontal? : Bool #

[View source]
def regular_vertical? : Bool #

[View source]
def safe_area_bottom_pt : Float64 #

def safe_area_leading_pt : Float64 #

def safe_area_top_pt : Float64 #

def safe_area_trailing_pt : Float64 #

def screen_height_pt : Float64 #

def screen_width_pt : Float64 #

def vertical_size_class : SizeClass #