Skip to main content

VisualDensity

Struct VisualDensity 

Source
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:

  • Checkbox
  • Chip
  • ElevatedButton
  • FilledButton
  • IconButton
  • InputDecorator (which gives density support to TextField, etc.)
  • ListTile
  • MaterialButton
  • OutlinedButton
  • Radio
  • RawMaterialButton
  • TextButton

See also:

Fields§

§horizontal: f64

The 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:

§vertical: f64

The 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:

Implementations§

Source§

impl VisualDensity

Source

pub const MINIMUM_DENSITY: f64 = -4.0

The minimum allowed density.

Source

pub const MAXIMUM_DENSITY: f64 = 4.0

The maximum allowed density.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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:

Source

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:

Source

pub fn copy_with( self, horizontal: Option<f64>, vertical: Option<f64>, ) -> VisualDensity

Copy the current VisualDensity with the given values replacing the current values.

Source

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.

Source

pub fn lerp(a: VisualDensity, b: VisualDensity, t: f64) -> VisualDensity

Linearly interpolate between two densities.

Source

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

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 Copy for VisualDensity

Source§

impl Debug for VisualDensity

Source§

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

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

impl Default for VisualDensity

Source§

fn default() -> VisualDensity

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

impl Diagnosticable for VisualDensity

Source§

fn to_string_short(&self) -> String

A brief description of this object, usually just the type and the hash.
Source§

fn debug_fill_properties(&self, properties: &mut DiagnosticPropertiesBuilder)

Add additional properties associated with the node.
Source§

fn type_name(&self) -> &'static str

Dart’s Object.runtimeType as diagnostics print it: the last segment of the Rust type path, without generic arguments.
Source§

fn identity_hash(&self) -> u64

Dart’s Object.hashCode as diagnostics print it: the object’s address.
Source§

fn to_diagnostics_node(&self) -> DiagnosticableNode

Returns a debug representation of the object used by debugging tools and by DiagnosticsNode::to_string_deep.
Source§

fn to_diagnostics_node_with( &self, name: Option<String>, style: Option<DiagnosticsTreeStyle>, ) -> DiagnosticableNode

Dart toDiagnosticsNode(name:, style:).
Source§

fn to_string(&self) -> String

Dart’s toString: a single-line description with properties and no children. Read more
Source§

fn to_string_at(&self, min_level: DiagnosticLevel) -> String

Dart’s toString(minLevel:).
Source§

impl Display for VisualDensity

Source§

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

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

impl PartialEq for VisualDensity

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for VisualDensity

Auto Trait Implementations§

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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> Downcast<T> for T

Source§

fn downcast(&self) -> &T

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. 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<T> Upcast<T> for T

Source§

fn upcast(&self) -> Option<&T>

Source§

impl<T> WasmNotSend for T
where T: Send,

Source§

impl<T> WasmNotSendSync for T

Source§

impl<T> WasmNotSync for T
where T: Sync,