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>
impl<'a> SizeCx<'a>
Sourcepub fn re<'b>(&'b self) -> SizeCx<'b>where
'a: 'b,
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.
Sourcepub fn scale_factor(&self) -> f32
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
.
Sourcepub fn dpem(&self) -> f32
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
).
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.
Sourcepub fn min_element_size(&self) -> i32
pub fn min_element_size(&self) -> i32
The smallest reasonable size for a visible (non-frame) component
This is used as a suggestion by some heuristics.
Sourcepub fn min_scroll_size(&self, axis: impl Directional) -> i32
pub fn min_scroll_size(&self, axis: impl Directional) -> i32
The minimum size of a scrollable area
Sourcepub fn grip_len(&self) -> i32
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
.
Sourcepub fn scroll_bar_width(&self) -> i32
pub fn scroll_bar_width(&self) -> i32
The width of a vertical scroll bar
This value is also available through Self::feature
.
Sourcepub fn margins(&self, style: MarginStyle) -> Margins
pub fn margins(&self, style: MarginStyle) -> Margins
Get margin size
Sourcepub fn inner_margins(&self) -> Margins
pub fn inner_margins(&self) -> Margins
Get margins for MarginStyle::Inner
Sourcepub fn tiny_margins(&self) -> Margins
pub fn tiny_margins(&self) -> Margins
Get margins for MarginStyle::Tiny
Sourcepub fn small_margins(&self) -> Margins
pub fn small_margins(&self) -> Margins
Get margins for MarginStyle::Small
Sourcepub fn large_margins(&self) -> Margins
pub fn large_margins(&self) -> Margins
Get margins for MarginStyle::Large
Sourcepub fn text_margins(&self) -> Margins
pub fn text_margins(&self) -> Margins
Get margins for MarginStyle::Text
Sourcepub fn feature(&self, feature: Feature, axis: impl Directional) -> SizeRules
pub fn feature(&self, feature: Feature, axis: impl Directional) -> SizeRules
Size rules for a feature
Sourcepub fn frame(&self, style: FrameStyle, axis: impl Directional) -> FrameRules
pub fn frame(&self, style: FrameStyle, axis: impl Directional) -> FrameRules
Size of a frame around another element
Sourcepub fn text_rules<T: FormattableText>(
&self,
text: &mut Text<T>,
axis: AxisInfo,
) -> SizeRules
pub fn text_rules<T: FormattableText>( &self, text: &mut Text<T>, axis: AxisInfo, ) -> SizeRules
Get SizeRules
for a text element
The TextClass
is used to select a font and controls whether line
wrapping is enabled.
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_configure
before text display for correct results.
Auto Trait Implementations§
impl<'a> Freeze for SizeCx<'a>
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<S, T> CastApprox<T> for Swhere
T: ConvApprox<S>,
impl<S, T> CastApprox<T> for Swhere
T: ConvApprox<S>,
Source§fn try_cast_approx(self) -> Result<T, Error>
fn try_cast_approx(self) -> Result<T, Error>
Source§fn cast_approx(self) -> T
fn cast_approx(self) -> T
Source§impl<S, T> CastFloat<T> for Swhere
T: ConvFloat<S>,
impl<S, T> CastFloat<T> for Swhere
T: ConvFloat<S>,
Source§fn cast_trunc(self) -> T
fn cast_trunc(self) -> T
Source§fn cast_nearest(self) -> T
fn cast_nearest(self) -> T
Source§fn cast_floor(self) -> T
fn cast_floor(self) -> T
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
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
.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait>
(where Trait: Downcast
) to Rc<Any>
. Rc<Any>
can then be
further downcast
into Rc<ConcreteType>
where ConcreteType
implements Trait
.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &Any
’s vtable from &Trait
’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&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> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more