Trait kas::draw::SizeHandle[][src]

pub trait SizeHandle {
Show 22 methods fn scale_factor(&self) -> f32;
fn pixels_from_points(&self, pt: f32) -> f32;
fn pixels_from_em(&self, em: f32) -> f32;
fn frame(&self, vert: bool) -> FrameRules;
fn menu_frame(&self, vert: bool) -> FrameRules;
fn separator(&self) -> Size;
fn nav_frame(&self, vert: bool) -> FrameRules;
fn inner_margin(&self) -> Size;
fn outer_margins(&self) -> Margins;
fn frame_margins(&self) -> Margins;
fn text_margins(&self) -> Margins;
fn line_height(&self, class: TextClass) -> i32;
fn text_bound(
        &self,
        text: &mut dyn TextApi,
        class: TextClass,
        axis: AxisInfo
    ) -> SizeRules;
fn edit_marker_width(&self) -> f32;
fn button_surround(&self, vert: bool) -> FrameRules;
fn edit_surround(&self, vert: bool) -> FrameRules;
fn checkbox(&self) -> Size;
fn radiobox(&self) -> Size;
fn scrollbar(&self) -> (Size, i32);
fn slider(&self) -> (Size, i32);
fn progress_bar(&self) -> Size; fn pixels_from_virtual(&self, px: f32) -> f32 { ... }
}
Expand description

A handle to the active theme, used for sizing

The shell provides widgets a &dyn SizeHandle in crate::Layout::size_rules. It may also be accessed through crate::event::Manager::size_handle and DrawHandle::size_handle.

All methods get or calculate the size of some feature.

See also DrawHandle.

Required methods

Get the scale (DPI) 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. It is recommended to calculate sizes as follows:

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.

Convert a size in font Points to physical pixels

Convert a size in font Em to physical pixels

(This depends on the font size.)

Size of a frame around child widget(s)

This already includes the margins specified by Self::frame_margins.

Frame/margin around a menu entry

Size of a separator frame between items

Size of a navigation highlight margin around a child widget

The margin around content within a widget

Though inner margins are usually empty, they are sometimes drawn to, for example focus indicators.

The margin between UI elements, where desired

Widgets must not draw in outer margins.

The margin around frames and separators

The margin around text elements

Similar to Self::outer_margins, but intended for things like text labels which do not have a visible hard edge.

The height of a line of text

Update a Text and get a size bound

First, this method updates the text’s Environment: bounds, dpp and pt_size are set. Second, the text is prepared (which is necessary to calculate size requirements). Finally, this converts the requirements to a SizeRules value and returns it.

Usually this method is used in Layout::size_rules, then TextApiExt::update_env is used in Layout::set_rect.

Width of an edit marker

Size of the sides of a button.

Size of the frame around an edit box, including margin

Note: though text should not be drawn in the margin, the edit cursor may be. The margin included here should be large enough!

Size of the element drawn by DrawHandle::checkbox.

Size of the element drawn by DrawHandle::radiobox.

Dimensions for a scrollbar

Returns:

  • size: minimum size of handle in horizontal orientation; size.1 is also the width of the scrollbar
  • min_len: minimum length for the whole bar

Required bound: min_len >= size.0.

Dimensions for a slider

Returns:

  • size: minimum size of handle in horizontal orientation; size.1 is also the width of the slider
  • min_len: minimum length for the whole bar

Required bound: min_len >= size.0.

Dimensions for a progress bar

Returns the minimum size for a horizontal progress bar. It is assumed that the width is adjustable while the height is (preferably) not. For a vertical bar, the values are swapped.

Provided methods

Convert a size in virtual pixels to physical pixels

Implementations on Foreign Types

Implementors