Struct kas::theme::DrawCx

source ·
pub struct DrawCx<'a> { /* private fields */ }
Expand description

Draw interface

This interface is provided to widgets in crate::Layout::draw. Lower-level interfaces may be accessed through Self::draw_device.

DrawCx is not a Copy or Clone type; instead it may be “reborrowed” via Self::re_id or Self::re_clone.

  • draw.check_box(&*self, self.state); — note &*self to convert from to &W from &mut W, since the latter would cause borrow conflicts

Implementations§

source§

impl<'a> DrawCx<'a>

source

pub fn re_id<'b>(&'b mut self, id: Id) -> DrawCx<'b>
where 'a: 'b,

Reborrow with a new lifetime and new id

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.

source

pub fn re_clone<'b>(&'b mut self) -> DrawCx<'b>
where 'a: 'b,

Reborrow with a new lifetime and same id

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.

source

pub fn recurse(&mut self, child: &mut (impl Layout + ?Sized))

Recurse drawing to a child

source

pub fn ev_state(&mut self) -> &mut EventState

Access event-management state

source

pub fn size_cx(&mut self) -> SizeCx<'_>

Access a SizeCx

source

pub fn config_cx<F, T>(&mut self, f: F) -> T
where F: FnOnce(&mut ConfigCx<'_>) -> T,

Access a ConfigCx

source

pub fn draw_shared(&mut self) -> &mut dyn DrawShared

Access a DrawShared

source

pub fn draw_device(&mut self) -> &mut dyn Draw

Access the low-level draw device

Note: this drawing API is modular, with limited functionality in the base trait Draw. To access further functionality, it is necessary to downcast with crate::draw::DrawIface::downcast_from.

source

pub fn draw_iface<DS>(&mut self) -> Option<DrawIface<'_, DS>>
where DS: DrawSharedImpl,

Access the low-level draw device (implementation type)

The implementing type must be specified. See DrawIface::downcast_from.

source

pub fn with_pass<F>(&mut self, f: F)
where F: FnOnce(DrawCx<'_>),

Draw to a new pass

Adds a new draw pass for purposes of enforcing draw order. Content of the new pass will be drawn after content in the parent pass.

source

pub fn with_clip_region<F>(&mut self, rect: Rect, offset: Offset, f: F)
where F: FnOnce(DrawCx<'_>),

Draw to a new pass with clipping and offset (e.g. for scrolling)

Adds a new draw pass of type PassType::Clip, with draw operations clipped to rect and translated by `offset.

source

pub fn with_overlay<F>(&mut self, rect: Rect, offset: Offset, f: F)
where F: FnOnce(DrawCx<'_>),

Draw to a new pass as an overlay (e.g. for pop-up menus)

Adds a new draw pass of type PassType::Overlay, with draw operations clipped to rect.

The theme is permitted to enlarge the rect for the purpose of drawing a frame or shadow around this overlay, thus the Self::get_clip_rect may be larger than expected.

source

pub fn get_clip_rect(&mut self) -> Rect

Target area for drawing

Drawing is restricted to this Rect, which may be the whole window, a clip region or an overlay. This may be used to cull hidden items from lists inside a scrollable view.

source

pub fn frame(&mut self, rect: Rect, style: FrameStyle, bg: Background)

Draw a frame inside the given rect

The frame dimensions are given by SizeCx::frame.

source

pub fn separator(&mut self, rect: Rect)

Draw a separator in the given rect

source

pub fn selection(&mut self, rect: Rect, style: SelectionStyle)

Draw a selection highlight / frame

Adjusts the background color and/or draws a line around the given rect. In the latter case, a margin of size SizeCx::inner_margins around rect is expected.

source

pub fn text( &mut self, rect: Rect, text: impl AsRef<TextDisplay>, class: TextClass )

Draw text

Text is drawn from rect.pos and clipped to rect. If the text scrolls, rect should be the size of the whole text, not the window.

ConfigCx::text_set_size should be called prior to this method to select a font, font size and wrap options (based on the TextClass).

source

pub fn text_effects(&mut self, rect: Rect, text: &dyn TextApi, class: TextClass)

Draw text with effects

Text is drawn from rect.pos and clipped to rect. If the text scrolls, rect should be the size of the whole text, not the window.

Self::text already supports font effects: bold, emphasis, text size. In addition, this method supports underline and strikethrough effects.

ConfigCx::text_set_size should be called prior to this method to select a font, font size and wrap options (based on the TextClass).

source

pub fn text_selected<R>( &mut self, rect: Rect, text: impl AsRef<TextDisplay>, range: R, class: TextClass )
where R: RangeBounds<usize>,

Draw some text using the standard font, with a subset selected

Other than visually highlighting the selection, this method behaves identically to Self::text. It is likely to be replaced in the future by a higher-level API.

source

pub fn text_cursor( &mut self, rect: Rect, text: impl AsRef<TextDisplay>, class: TextClass, byte: usize )

Draw an edit marker at the given byte index on this text

The text cursor is draw from rect.pos and clipped to rect. If the text scrolls, rect should be the size of the whole text, not the window.

ConfigCx::text_set_size should be called prior to this method to select a font, font size and wrap options (based on the TextClass).

source

pub fn check_box( &mut self, rect: Rect, checked: bool, last_change: Option<Instant> )

Draw UI element: check box (without label)

The check box is a small visual element, typically a distinctive square box with or without a “check” selection mark.

The theme may animate transitions. To achieve this, last_change should be the time of the last state change caused by the user, or none when the last state change was programmatic.

source

pub fn radio_box( &mut self, rect: Rect, checked: bool, last_change: Option<Instant> )

Draw UI element: radio box (without label)

The radio box is a small visual element, typically a disinctive circular box with or without a “radio” selection mark.

The theme may animate transitions. To achieve this, last_change should be the time of the last state change caused by the user, or none when the last state change was programmatic.

source

pub fn mark(&mut self, rect: Rect, style: MarkStyle)

Draw UI element: mark

source

pub fn scroll_bar<W>(&mut self, track_rect: Rect, grip: &W, dir: Direction)
where W: Layout,

Draw UI element: scroll bar

source

pub fn slider<W>(&mut self, track_rect: Rect, grip: &W, dir: Direction)
where W: Layout,

Draw UI element: slider

source

pub fn progress_bar(&mut self, rect: Rect, dir: Direction, value: f32)

Draw UI element: progress bar

  • rect: area of whole widget
  • dir: direction of progress bar
  • state: highlighting information
  • value: progress value, between 0.0 and 1.0
source

pub fn image(&mut self, rect: Rect, id: ImageId)

Draw an image

Auto Trait Implementations§

§

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

§

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

§

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

§

impl<'a> Unpin for DrawCx<'a>

§

impl<'a> !UnwindSafe for DrawCx<'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