Struct kas::theme::SizeCx

source ·
pub struct SizeCx<'a>(/* private fields */);
Expand description

Size and scale interface

This interface is provided to widgets in crate::Layout::size_rules. It may also be accessed through crate::event::EventCx::size_cx, DrawCx::size_cx.

Most methods get or calculate the size of some feature. These same features may be drawn through DrawCx.

Implementations§

source§

impl<'a> SizeCx<'a>

source

pub fn re<'b>(&'b self) -> SizeCx<'b>
where 'a: 'b,

Reborrow with a new lifetime

Rust allows references like &T or &mut T to be “reborrowed” through coercion: essentially, the pointer is copied under a new, shorter, lifetime. Until rfcs#1403 lands, reborrows on user types require a method call.

Calling this method is zero-cost.

source

pub fn scale_factor(&self) -> f32

Get the scale factor

“Traditional” PC screens have a scale factor of 1; high-DPI screens may have a factor of 2 or higher. This may be fractional and may be adjusted to suit the device type (e.g. a phone or desktop monitor) as well as the user’s preference.

One could use this value to calculate physical size, but be warned that the result may be quite inaccurate on anything other than a desktop monitor: 25.4 mm = 1 inch = (96 * scale_factor) pixels

To calculate screen pixel sizes from virtual pixel sizes:

use kas_core::cast::*;
let size: i32 = (100.0 * scale_factor).cast_ceil();

This value may change during a program’s execution (e.g. when a window is moved to a different monitor); in this case all widgets will be resized via crate::Layout::size_rules.

source

pub fn dpem(&self) -> f32

The Em size of the standard font in pixels

The Em is a unit of typography (variously defined as the point-size of the font, the height of the font or the width of an upper-case M). The method Self::line_height returns a related but distinct value.

This method returns the size of 1 Em in physical pixels, derived from the font size in use by the theme and the screen’s scale factor.

source

pub fn min_scroll_size(&self, axis: impl Directional) -> i32

The minimum size of a scrollable area

source

pub fn grip_len(&self) -> i32

The length of the grip (draggable handle) on a scroll bar or slider

This is the length in line with the control. The size on the opposite axis is assumed to be equal to the feature size as reported by Self::feature.

source

pub fn scroll_bar_width(&self) -> i32

The width of a vertical scroll bar

This value is also available through Self::feature.

source

pub fn margins(&self, style: MarginStyle) -> Margins

Get margin size

source

pub fn inner_margins(&self) -> Margins

Get margins for MarginStyle::Inner

source

pub fn tiny_margins(&self) -> Margins

Get margins for MarginStyle::Tiny

source

pub fn small_margins(&self) -> Margins

Get margins for MarginStyle::Small

source

pub fn large_margins(&self) -> Margins

Get margins for MarginStyle::Large

source

pub fn text_margins(&self) -> Margins

Get margins for MarginStyle::Text

source

pub fn feature(&self, feature: Feature, axis: impl Directional) -> SizeRules

Size rules for a feature

source

pub fn frame(&self, style: FrameStyle, axis: impl Directional) -> FrameRules

Size of a frame around another element

source

pub fn line_height(&self, class: TextClass) -> i32

The height of a line of text using the corresponding font

This method looks up the font face corresponding to the given class, scales this according to Self::dpem, then measures the line height. The result is typically 100% - 150% of the value returned by Self::dpem, depending on the font face.

source

pub fn text_rules( &self, text: &mut dyn TextApi, class: TextClass, axis: AxisInfo ) -> SizeRules

Get SizeRules for a text element

The TextClass is used to select a font and controls whether line wrapping is enabled.

Alignment is set from AxisInfo::align_or_default. If other alignment is desired, modify axis before calling this method.

Horizontal size without wrapping is simply the size the text. Horizontal size with wrapping is bounded to some width dependant on the theme, and may have non-zero Stretch depending on the size.

Vertical size is the size of the text with or without wrapping, but with the minimum at least the height of one line of text.

Widgets with editable text contents or internal scrolling enabled may wish to adjust the result.

Note: this method partially prepares the text object. It is not required to call this method but it is required to call ConfigCx::text_set_size before text display for correct results.

Auto Trait Implementations§

§

impl<'a> !RefUnwindSafe for SizeCx<'a>

§

impl<'a> !Send for SizeCx<'a>

§

impl<'a> !Sync for SizeCx<'a>

§

impl<'a> Unpin for SizeCx<'a>

§

impl<'a> !UnwindSafe for SizeCx<'a>

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
§

impl<S, T> Cast<T> for S
where T: Conv<S>,

§

fn cast(self) -> T

Cast from Self to T Read more
§

fn try_cast(self) -> Result<T, Error>

Try converting from Self to T Read more
§

impl<S, T> CastApprox<T> for S
where T: ConvApprox<S>,

§

fn try_cast_approx(self) -> Result<T, Error>

Try approximate conversion from Self to T Read more
§

fn cast_approx(self) -> T

Cast approximately from Self to T Read more
§

impl<S, T> CastFloat<T> for S
where T: ConvFloat<S>,

§

fn cast_trunc(self) -> T

Cast to integer, truncating Read more
§

fn cast_nearest(self) -> T

Cast to the nearest integer Read more
§

fn cast_floor(self) -> T

Cast the floor to an integer Read more
§

fn cast_ceil(self) -> T

Cast the ceiling to an integer Read more
§

fn try_cast_trunc(self) -> Result<T, Error>

Try converting to integer with truncation Read more
§

fn try_cast_nearest(self) -> Result<T, Error>

Try converting to the nearest integer Read more
§

fn try_cast_floor(self) -> Result<T, Error>

Try converting the floor to an integer Read more
§

fn try_cast_ceil(self) -> Result<T, Error>

Try convert the ceiling to an integer Read more
§

impl<T> Downcast<T> for T

§

fn downcast(&self) -> &T

§

impl<T> Downcast for T
where T: Any,

§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.
§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
§

fn as_any(&self) -> &(dyn Any + 'static)

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

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

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

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.

§

impl<T> Pointable for T

§

const ALIGN: usize = _

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
source§

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

§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

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

§

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.
§

impl<T> Upcast<T> for T

§

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

§

impl<T> WithSubscriber for T

§

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
§

fn with_current_subscriber(self) -> WithDispatch<Self>

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