Struct conrod::glyph_cache::GlyphCache
[−]
[src]
pub struct GlyphCache<C> { // some fields omitted }
A wrapper over some CharacterCache, exposing it's functionality via a RefCell.
The GlyphCache is frequently needed in order to calculate text dimensions. We wrap the CharacterCache in a RefCell in order to avoid ownership issues that this may cause.
Methods
impl<C> GlyphCache<C>
[src]
fn new(cache: C) -> Self
Construct a new GlyphCache.
fn char_width(&self, font_size: FontSize, ch: char) -> Scalar where C: CharacterCache
The width of a single character with the given size.
fn char_widths<I>(&self, font_size: FontSize, chars: I) -> CharWidths<C, I::IntoIter> where I: IntoIterator<Item=char>
Converts the given sequence of char
s into their Scalar widths.
fn char_xs<I>(&self, font_size: FontSize, start_x: Scalar, chars: I) -> CharXs<C, I::IntoIter> where C: CharacterCache, I: IntoIterator<Item=char>
Converts the given sequnce of char
s into their consecutive positions along the x-axis.
fn width(&self, font_size: FontSize, text: &str) -> Scalar where C: CharacterCache
Return the width of the given text.
fn widths<I>(&self, font_size: FontSize, strs: I) -> Widths<C, I::IntoIter> where I: IntoIterator<Item=&'a str>
Converts the given sequence of &str
s into their Scalar widths.
fn line_breaks_by<'a, F>(&'a self, font_size: FontSize, text: &'a str, max_width: Scalar, line_break_fn: F) -> LineBreaksBy<'a, C, F>
An iterator that yields the indices at which some text should wrap in accordance with the given wrap function.
fn line_breaks_by_character<'a>(&'a self, font_size: FontSize, text: &'a str, max_width: Scalar) -> LineBreaksByCharacter<'a, C> where C: CharacterCache
An iterator that yields the indices at which some text should wrap via a character.
fn line_breaks_by_whitespace<'a>(&'a self, font_size: FontSize, text: &'a str, max_width: Scalar) -> LineBreaksByWhitespace<'a, C> where C: CharacterCache
An iterator that yields the indices at which some text should wrap via whitespace.
fn lines_wrapped_by<'a, F>(&'a self, font_size: FontSize, text: &'a str, max_width: Scalar, wrap_fn: F) -> LinesWrappedBy<'a, C, F>
An iterator that behaves the same as text.lines()
but inserts a break before the first
character that would cause the line to exceed the given max_width
.
fn lines_wrapped_by_character<'a>(&'a self, font_size: FontSize, text: &'a str, max_width: Scalar) -> LinesWrappedByCharacter<'a, C> where C: CharacterCache
An iterator that behaves the same as text.lines()
but inserts a break before the first
character that would cause the line to exceed the given max_width
.
fn lines_wrapped_by_whitespace<'a>(&'a self, font_size: FontSize, text: &'a str, max_width: Scalar) -> LinesWrappedByWhitespace<'a, C> where C: CharacterCache
An iterator that behaves the same as text.lines()
but inserts a break before the first
character that would cause the line to exceed the given max_width
.
Methods from Deref<Target=RefCell<C>>
fn into_inner(self) -> T
1.0.0
Consumes the RefCell
, returning the wrapped value.
Examples
use std::cell::RefCell; let c = RefCell::new(5); let five = c.into_inner();
fn borrow_state(&self) -> BorrowState
borrow_state
)Query the current state of this RefCell
The returned value can be dispatched on to determine if a call to
borrow
or borrow_mut
would succeed.
Examples
#![feature(borrow_state)] use std::cell::{BorrowState, RefCell}; let c = RefCell::new(5); match c.borrow_state() { BorrowState::Writing => println!("Cannot be borrowed"), BorrowState::Reading => println!("Cannot be borrowed mutably"), BorrowState::Unused => println!("Can be borrowed (mutably as well)"), }
fn borrow(&self) -> Ref<T>
1.0.0
Immutably borrows the wrapped value.
The borrow lasts until the returned Ref
exits scope. Multiple
immutable borrows can be taken out at the same time.
Panics
Panics if the value is currently mutably borrowed.
Examples
use std::cell::RefCell; let c = RefCell::new(5); let borrowed_five = c.borrow(); let borrowed_five2 = c.borrow();
An example of panic:
use std::cell::RefCell; use std::thread; let result = thread::spawn(move || { let c = RefCell::new(5); let m = c.borrow_mut(); let b = c.borrow(); // this causes a panic }).join(); assert!(result.is_err());
fn borrow_mut(&self) -> RefMut<T>
1.0.0
Mutably borrows the wrapped value.
The borrow lasts until the returned RefMut
exits scope. The value
cannot be borrowed while this borrow is active.
Panics
Panics if the value is currently borrowed.
Examples
use std::cell::RefCell; let c = RefCell::new(5); *c.borrow_mut() = 7; assert_eq!(*c.borrow(), 7);
An example of panic:
use std::cell::RefCell; use std::thread; let result = thread::spawn(move || { let c = RefCell::new(5); let m = c.borrow(); let b = c.borrow_mut(); // this causes a panic }).join(); assert!(result.is_err());
unsafe fn as_unsafe_cell(&self) -> &UnsafeCell<T>
as_unsafe_cell
)Returns a reference to the underlying UnsafeCell
.
This can be used to circumvent RefCell
's safety checks.
This function is unsafe
because UnsafeCell
's field is public.
Examples
#![feature(as_unsafe_cell)] use std::cell::RefCell; let c = RefCell::new(5); let c = unsafe { c.as_unsafe_cell() };
fn get_mut(&mut self) -> &mut T
1.11.0
Returns a mutable reference to the underlying data.
This call borrows RefCell
mutably (at compile-time) so there is no
need for dynamic checks.
Examples
use std::cell::RefCell; let mut c = RefCell::new(5); *c.get_mut() += 1; assert_eq!(c, RefCell::new(6));
Trait Implementations
impl<C> Deref for GlyphCache<C>
[src]
type Target = RefCell<C>
The resulting type after dereferencing
fn deref<'a>(&'a self) -> &'a RefCell<C>
The method called to dereference a value