pub struct DrawCx<'a> { /* private fields */ }Expand description
Draw interface
This interface is provided to widgets in Layout::draw.
Lower-level interfaces may be accessed through Self::draw.
DrawCx is not a Copy or Clone type; instead it may be “reborrowed”
via Self::re.
draw.check_box(&*self, self.state);— note&*selfto convert from to&Wfrom&mut W, since the latter would cause borrow conflicts
Implementations§
Source§impl<'a> DrawCx<'a>
impl<'a> DrawCx<'a>
Sourcepub fn re<'b>(&'b mut self) -> DrawCx<'b>where
'a: 'b,
pub fn re<'b>(&'b mut self) -> DrawCx<'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.
Sourcepub fn set_id(&mut self, id: Id)
pub fn set_id(&mut self, id: Id)
Set the identity of the current widget
This struct tracks the Id of the calling widget to allow evaluation
of widget state (e.g. is disabled, is under the mouse, has key focus).
Usually you don’t need to worry about this since the #[widget] macro
injects a call to this method at the start of Layout::draw.
Sourcepub fn ev_state(&mut self) -> &mut EventState
pub fn ev_state(&mut self) -> &mut EventState
Access event-management state
Sourcepub fn size_cx(&mut self) -> SizeCx<'_>
pub fn size_cx(&mut self) -> SizeCx<'_>
Access a SizeCx
(This also allows access to EventState.)
Sourcepub fn colors(&self) -> &ColorsLinear
pub fn colors(&self) -> &ColorsLinear
Access theme colors
Access a DrawShared
Sourcepub fn draw(&mut self) -> &mut dyn Draw
pub fn draw(&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.
Sourcepub fn draw_rounded(&mut self) -> Option<&mut dyn DrawRounded>
pub fn draw_rounded(&mut self) -> Option<&mut dyn DrawRounded>
Access the draw device as a DrawRounded implementation, if possible
Warning: this does not reflect whether the underlying draw device
supports DrawRounded (which would require specialization) but
whether the theme in question requires DrawRounded. As such, this
method is only useful with a theme requiring this extension such as
FlatTheme.
Sourcepub fn draw_iface<DS: DrawSharedImpl>(&mut self) -> Option<DrawIface<'_, DS>>
pub fn draw_iface<DS: DrawSharedImpl>(&mut self) -> Option<DrawIface<'_, DS>>
Access the low-level draw device (implementation type)
The implementing type must be specified. See DrawIface::downcast_from.
Sourcepub fn with_pass<F: FnOnce(DrawCx<'_>)>(&mut self, f: F)
pub fn with_pass<F: FnOnce(DrawCx<'_>)>(&mut self, f: F)
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.
Warning: the number of passes used can have a substantial performance impact, potentially more on GPU communication than CPU usage.
Sourcepub fn with_clip_region<F: FnOnce(DrawCx<'_>)>(
&mut self,
rect: Rect,
offset: Offset,
f: F,
)
pub fn with_clip_region<F: FnOnce(DrawCx<'_>)>( &mut self, rect: Rect, offset: Offset, f: F, )
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.
Warning: the number of passes used can have a substantial performance impact, potentially more on GPU communication than CPU usage.
Sourcepub fn with_overlay<F: FnOnce(DrawCx<'_>)>(
&mut self,
rect: Rect,
offset: Offset,
f: F,
)
pub fn with_overlay<F: FnOnce(DrawCx<'_>)>( &mut self, rect: Rect, offset: Offset, f: F, )
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.
Warning: the number of passes used can have a substantial performance impact, potentially more on GPU communication than CPU usage.
Sourcepub fn get_clip_rect(&mut self) -> Rect
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.
Sourcepub fn access_key(&mut self, id: &Id, key: &Key) -> bool
pub fn access_key(&mut self, id: &Id, key: &Key) -> bool
Register widget id as handler of an access key
An access key (also known as mnemonic) is a shortcut key able to directly open menus, activate buttons, etc. Usually this requires that the Alt is held, though alt-bypass mode is available.
The widget id is bound to the given key, if available. When the
access key is pressed (assuming that this binding succeeds), widget id
will receive navigation focus (if supported; otherwise an ancestor may
receive focus) and is sent Command::Activate (likewise, an ancestor
may handle this if widget id does not).
If multiple widgets attempt to register themselves as handlers of the
same key, then only the first succeeds.
Returns true when the key should be underlined.
Sourcepub fn frame(&mut self, rect: Rect, style: FrameStyle, bg: Background)
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.
Sourcepub fn selection(&mut self, rect: Rect, style: SelectionStyle)
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.
Sourcepub fn text<T: FormattableText>(&mut self, rect: Rect, text: &Text<T>)
pub fn text<T: FormattableText>(&mut self, rect: Rect, text: &Text<T>)
Draw text
Text is clipped to rect.
This is a convenience method over Self::text_with_effects.
The text should be prepared before calling this method.
Sourcepub fn text_with_color<T: FormattableText>(
&mut self,
rect: Rect,
text: &Text<T>,
color: Rgba,
)
pub fn text_with_color<T: FormattableText>( &mut self, rect: Rect, text: &Text<T>, color: Rgba, )
Draw text with specified color
Text is clipped to rect and drawn using color.
This is a convenience method over Self::text_with_effects.
The text should be prepared before calling this method.
Sourcepub fn text_with_position<T: FormattableText>(
&mut self,
pos: Coord,
rect: Rect,
text: &Text<T>,
)
pub fn text_with_position<T: FormattableText>( &mut self, pos: Coord, rect: Rect, text: &Text<T>, )
Draw text with effects and an offset
Text is clipped to rect, drawing from pos; use pos = rect.pos if
the text is not scrolled.
This is a convenience method over Self::text_with_effects.
The text should be prepared before calling this method.
Sourcepub fn text_with_effects<T: FormattableText>(
&mut self,
pos: Coord,
rect: Rect,
text: &Text<T>,
colors: &[Rgba],
effects: &[Effect],
)
pub fn text_with_effects<T: FormattableText>( &mut self, pos: Coord, rect: Rect, text: &Text<T>, colors: &[Rgba], effects: &[Effect], )
Draw text with a given effect list
Text is clipped to rect, drawing from pos; use pos = rect.pos if
the text is not scrolled.
If colors is empty, it is replaced with a single theme-defined color.
Text is then drawn using colors[0] except as specified by effects.
The list of effects (if not empty) controls render effects:
Effect::e is an index into colors while Effect::flags controls
underline and strikethrough. Effect::start is the text index at
which this effect first takes effect, and must effects must be ordered
such that the sequence of Effect::start values is strictly
increasing. Effect::default() is used if effects is empty or while
index < effects.first().unwrap().start.
Text objects may embed their own list of effects, accessible using
Text::effect_tokens. It is always valid to disregard these
and use a custom effects list or empty list.
Sourcepub fn text_with_selection<T: FormattableText>(
&mut self,
pos: Coord,
rect: Rect,
text: &Text<T>,
range: Range<usize>,
)
pub fn text_with_selection<T: FormattableText>( &mut self, pos: Coord, rect: Rect, text: &Text<T>, range: Range<usize>, )
Draw some text with a selection
Text is drawn like Self::text_with_position except that the subset
identified by range is highlighted using theme-defined colors.
Sourcepub fn text_cursor<T: FormattableText>(
&mut self,
pos: Coord,
rect: Rect,
text: &Text<T>,
byte: usize,
)
pub fn text_cursor<T: FormattableText>( &mut self, pos: Coord, rect: Rect, text: &Text<T>, 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.
The text should be prepared before calling this method.
Sourcepub fn check_box(
&mut self,
rect: Rect,
checked: bool,
last_change: Option<Instant>,
)
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.
Sourcepub fn radio_box(
&mut self,
rect: Rect,
checked: bool,
last_change: Option<Instant>,
)
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.
Sourcepub fn mark(&mut self, rect: Rect, style: MarkStyle)
pub fn mark(&mut self, rect: Rect, style: MarkStyle)
Draw UI element: mark
If rect is larger than required, the mark will be centered.
Sourcepub fn scroll_bar<W: Tile>(
&mut self,
track_rect: Rect,
grip: &W,
dir: Direction,
)
pub fn scroll_bar<W: Tile>( &mut self, track_rect: Rect, grip: &W, dir: Direction, )
Draw UI element: scroll bar
Sourcepub fn slider<W: Tile>(&mut self, track_rect: Rect, grip: &W, dir: Direction)
pub fn slider<W: Tile>(&mut self, track_rect: Rect, grip: &W, dir: Direction)
Draw UI element: slider
Sourcepub fn progress_bar(&mut self, rect: Rect, dir: Direction, value: f32)
pub fn progress_bar(&mut self, rect: Rect, dir: Direction, value: f32)
Draw UI element: progress bar
rect: area of whole widgetdir: direction of progress barstate: highlighting informationvalue: progress value, between 0.0 and 1.0
Trait Implementations§
Auto Trait Implementations§
impl<'a> Freeze for DrawCx<'a>
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> 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.