pub struct VisualDensity {
pub horizontal: f64,
pub vertical: f64,
}Expand description
Defines the visual density of user interface components.
Density, in the context of a UI, is the vertical and horizontal “compactness” of the components in the UI. It is unitless, since it means different things to different UI components.
The default for visual densities is zero for both vertical and horizontal densities, which corresponds to the default visual density of components in the Material Design specification. It does not affect text sizes, icon sizes, or padding values.
The default visual density varies by platform: mobile platforms (Android, iOS,
Fuchsia) use VisualDensity::STANDARD, while desktop platforms (macOS, Windows,
Linux) use VisualDensity::COMPACT. See
default_density_for_platform for more details.
For example, for buttons, it affects the spacing around the child of the button. For lists, it affects the distance between baselines of entries in the list. For chips, it only affects the vertical size, not the horizontal size.
Here are some examples of widgets that respond to density changes:
CheckboxChipElevatedButtonFilledButtonIconButtonInputDecorator(which gives density support toTextField, etc.)ListTileMaterialButtonOutlinedButtonRadioRawMaterialButtonTextButton
See also:
ThemeData::visual_density, where this property is used to specify the base horizontal density of Material components.- Material design guidance on density.
Fields§
§horizontal: f64The horizontal visual density of UI components.
This property affects only the horizontal spacing between and within
components, to allow for different UI visual densities. It does not affect
text sizes, icon sizes, or padding values. The default value is 0.0,
corresponding to the metrics specified in the Material Design
specification. The value can range from MINIMUM_DENSITY
to MAXIMUM_DENSITY, inclusive.
See also:
ThemeData::visual_density, where this property is used to specify the base horizontal density of Material components.- Material design guidance on density.
vertical: f64The vertical visual density of UI components.
This property affects only the vertical spacing between and within
components, to allow for different UI visual densities. It does not affect
text sizes, icon sizes, or padding values. The default value is 0.0,
corresponding to the metrics specified in the Material Design
specification. The value can range from MINIMUM_DENSITY
to MAXIMUM_DENSITY, inclusive.
See also:
ThemeData::visual_density, where this property is used to specify the base vertical density of Material components.- Material design guidance on density.
Implementations§
Source§impl VisualDensity
impl VisualDensity
Sourcepub const MINIMUM_DENSITY: f64 = -4.0
pub const MINIMUM_DENSITY: f64 = -4.0
The minimum allowed density.
Sourcepub const MAXIMUM_DENSITY: f64 = 4.0
pub const MAXIMUM_DENSITY: f64 = 4.0
The maximum allowed density.
Sourcepub const STANDARD: VisualDensity
pub const STANDARD: VisualDensity
The default profile for VisualDensity in ThemeData.
This default value represents a visual density that is less dense than
either COMFORTABLE or COMPACT, and
corresponds to density values of zero in both axes.
Sourcepub const COMFORTABLE: VisualDensity
pub const COMFORTABLE: VisualDensity
The profile for a “comfortable” interpretation of VisualDensity.
Individual components will interpret the density value independently,
making themselves more visually dense than STANDARD and less
dense than COMPACT to different degrees based on the Material
Design specification of the “comfortable” setting for their particular use case.
It corresponds to a density value of -1 in both axes.
Sourcepub const COMPACT: VisualDensity
pub const COMPACT: VisualDensity
The profile for a “compact” interpretation of VisualDensity.
Individual components will interpret the density value independently,
making themselves more visually dense than STANDARD and
COMFORTABLE to different degrees based on the Material
Design specification of the “comfortable” setting for their particular use case.
It corresponds to a density value of -2 in both axes.
Sourcepub const fn new(horizontal: f64, vertical: f64) -> VisualDensity
pub const fn new(horizontal: f64, vertical: f64) -> VisualDensity
A const constructor for VisualDensity; Dart’s two named arguments default to 0.0.
The horizontal and vertical arguments must be in the interval between
MINIMUM_DENSITY and MAXIMUM_DENSITY,
inclusive.
Sourcepub fn adaptive_platform_density(app: &App) -> VisualDensity
pub fn adaptive_platform_density(app: &App) -> VisualDensity
Returns a VisualDensity that is adaptive based on the current platform
on which the framework is executing, from defaultTargetPlatform.
When defaultTargetPlatform is a desktop platform, this returns
COMPACT, and for other platforms, it returns a
default-constructed VisualDensity.
See also:
default_density_for_platformwhich returns aVisualDensitythat is adaptive based on the platform given to it.
Sourcepub fn default_density_for_platform(platform: TargetPlatform) -> VisualDensity
pub fn default_density_for_platform(platform: TargetPlatform) -> VisualDensity
Returns a VisualDensity that is adaptive based on the given platform.
For mobile platforms (Android, iOS, Fuchsia), this returns
VisualDensity::STANDARD, and for desktop platforms (macOS, Windows, Linux), it
returns VisualDensity::COMPACT.
See also:
adaptive_platform_densitywhich returns aVisualDensitythat is adaptive based ondefaultTargetPlatform.
Sourcepub fn copy_with(
self,
horizontal: Option<f64>,
vertical: Option<f64>,
) -> VisualDensity
pub fn copy_with( self, horizontal: Option<f64>, vertical: Option<f64>, ) -> VisualDensity
Copy the current VisualDensity with the given values replacing the
current values.
Sourcepub fn base_size_adjustment(&self) -> Offset
pub fn base_size_adjustment(&self) -> Offset
The base adjustment in logical pixels of the visual density of UI components.
The input density values are multiplied by a constant to arrive at a base size adjustment that fits Material Design guidelines.
Individual components may adjust this value based upon their own individual interpretation of density.
Sourcepub fn lerp(a: VisualDensity, b: VisualDensity, t: f64) -> VisualDensity
pub fn lerp(a: VisualDensity, b: VisualDensity, t: f64) -> VisualDensity
Linearly interpolate between two densities.
Sourcepub fn effective_constraints(
&self,
constraints: BoxConstraints,
) -> BoxConstraints
pub fn effective_constraints( &self, constraints: BoxConstraints, ) -> BoxConstraints
Return a copy of constraints whose minimum width and height have been
updated with the base_size_adjustment.
The resulting min_width and min_height values are clamped to not exceed the max_width and max_height values, respectively.
Trait Implementations§
Source§impl Clone for VisualDensity
impl Clone for VisualDensity
impl Copy for VisualDensity
Source§impl Debug for VisualDensity
impl Debug for VisualDensity
Source§impl Default for VisualDensity
impl Default for VisualDensity
Source§fn default() -> VisualDensity
fn default() -> VisualDensity
Source§impl Diagnosticable for VisualDensity
impl Diagnosticable for VisualDensity
Source§fn to_string_short(&self) -> String
fn to_string_short(&self) -> String
Source§fn debug_fill_properties(&self, properties: &mut DiagnosticPropertiesBuilder)
fn debug_fill_properties(&self, properties: &mut DiagnosticPropertiesBuilder)
Source§fn type_name(&self) -> &'static str
fn type_name(&self) -> &'static str
Object.runtimeType as diagnostics print it: the last segment of
the Rust type path, without generic arguments.Source§fn identity_hash(&self) -> u64
fn identity_hash(&self) -> u64
Object.hashCode as diagnostics print it: the object’s address.Source§fn to_diagnostics_node(&self) -> DiagnosticableNode
fn to_diagnostics_node(&self) -> DiagnosticableNode
DiagnosticsNode::to_string_deep.Source§fn to_diagnostics_node_with(
&self,
name: Option<String>,
style: Option<DiagnosticsTreeStyle>,
) -> DiagnosticableNode
fn to_diagnostics_node_with( &self, name: Option<String>, style: Option<DiagnosticsTreeStyle>, ) -> DiagnosticableNode
toDiagnosticsNode(name:, style:).Source§fn to_string(&self) -> String
fn to_string(&self) -> String
toString: a single-line description with properties and no
children. Read moreSource§fn to_string_at(&self, min_level: DiagnosticLevel) -> String
fn to_string_at(&self, min_level: DiagnosticLevel) -> String
toString(minLevel:).