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
).
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.
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 line_height(&self, class: TextClass) -> i32
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.
sourcepub fn text_rules(
&self,
text: &mut dyn TextApi,
class: TextClass,
axis: AxisInfo
) -> SizeRules
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> 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
§impl<S, T> CastApprox<T> for Swhere
T: ConvApprox<S>,
impl<S, T> CastApprox<T> for Swhere
T: ConvApprox<S>,
§fn try_cast_approx(self) -> Result<T, Error>
fn try_cast_approx(self) -> Result<T, Error>
§fn cast_approx(self) -> T
fn cast_approx(self) -> T
§impl<S, T> CastFloat<T> for Swhere
T: ConvFloat<S>,
impl<S, T> CastFloat<T> for Swhere
T: ConvFloat<S>,
§fn cast_trunc(self) -> T
fn cast_trunc(self) -> T
§fn cast_nearest(self) -> T
fn cast_nearest(self) -> T
§fn cast_floor(self) -> T
fn cast_floor(self) -> T
§fn try_cast_trunc(self) -> Result<T, Error>
fn try_cast_trunc(self) -> Result<T, Error>
§fn try_cast_nearest(self) -> Result<T, Error>
fn try_cast_nearest(self) -> Result<T, Error>
§fn try_cast_floor(self) -> Result<T, Error>
fn try_cast_floor(self) -> Result<T, Error>
§fn try_cast_ceil(self) -> Result<T, Error>
fn try_cast_ceil(self) -> Result<T, Error>
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§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
.§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
.§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.§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.