Skip to main content

CosmicTextMeasurer

Struct CosmicTextMeasurer 

Source
pub struct CosmicTextMeasurer { /* private fields */ }

Implementations§

Source§

impl CosmicTextMeasurer

Source

pub fn new() -> Self

Examples found in repository?
examples/showcase.rs (line 1817)
1812    fn measured_open_window_sizes(&self, desktop_size: UiSize) -> Vec<ShowcaseWindowMeasurement> {
1813        let measure_height = desktop_size.height.max(SHOWCASE_ORGANIZE_MEASURE_HEIGHT);
1814        let viewport = UiSize::new(desktop_size.width + RIGHT_PANEL_WIDTH, measure_height);
1815        let mut document = self.window_measurement_view(viewport);
1816        #[cfg(feature = "text-cosmic")]
1817        let mut measurer = CosmicTextMeasurer::new();
1818        #[cfg(not(feature = "text-cosmic"))]
1819        let mut measurer = ApproxTextMeasurer;
1820        if document.compute_layout(viewport, &mut measurer).is_err() {
1821            return Vec::new();
1822        }
1823        let theme = self.app_theme();
1824        let options = showcase_desktop_options(desktop_size, &theme);
1825        let mut measurements = SHOWCASE_WIDGET_WINDOW_IDS
1826            .into_iter()
1827            .filter(|id| self.windows.is_visible(id))
1828            .filter_map(|id| {
1829                let name = format!("showcase.windows.window.{id}");
1830                let collapsed_size = showcase_collapsed_window_size(id, &options);
1831                document
1832                    .nodes()
1833                    .iter()
1834                    .find(|node| node.name() == name)
1835                    .map(|node| {
1836                        let min_size = node.style().layout_style().min_size();
1837                        ShowcaseWindowMeasurement {
1838                            id: id.to_string(),
1839                            size: UiSize::new(node.layout().rect.width, node.layout().rect.height),
1840                            min_size: UiSize::new(
1841                                min_size
1842                                    .and_then(|size| size.width.points_value())
1843                                    .unwrap_or(node.layout().rect.width),
1844                                min_size
1845                                    .and_then(|size| size.height.points_value())
1846                                    .unwrap_or(node.layout().rect.height),
1847                            ),
1848                            collapsed_size,
1849                        }
1850                    })
1851            })
1852            .collect::<Vec<_>>();
1853
1854        let mut compact_desktop = self.desktop.clone();
1855        compact_desktop.collapsed.clear();
1856        for measurement in &measurements {
1857            compact_desktop.sizes.insert(
1858                measurement.id.clone(),
1859                UiSize::new(
1860                    measurement.min_size.width,
1861                    default_window_state_min_size(&measurement.id).height,
1862                ),
1863            );
1864            compact_desktop.user_sized.insert(measurement.id.clone());
1865        }
1866        let mut compact_document =
1867            self.window_measurement_view_with_desktop(viewport, compact_desktop);
1868        #[cfg(feature = "text-cosmic")]
1869        let mut compact_measurer = CosmicTextMeasurer::new();
1870        #[cfg(not(feature = "text-cosmic"))]
1871        let mut compact_measurer = ApproxTextMeasurer;
1872        if compact_document
1873            .compute_layout(viewport, &mut compact_measurer)
1874            .is_ok()
1875        {
1876            for measurement in &mut measurements {
1877                let name = format!("showcase.windows.window.{}", measurement.id);
1878                if let Some(node) = compact_document
1879                    .nodes()
1880                    .iter()
1881                    .find(|node| node.name() == name)
1882                {
1883                    measurement.min_size.width =
1884                        measurement.min_size.width.max(node.layout().rect.width);
1885                    measurement.min_size.height =
1886                        measurement.min_size.height.max(node.layout().rect.height);
1887                }
1888            }
1889        }
1890
1891        measurements
1892    }
Source

pub fn with_fonts(fonts: FontLibrary) -> Self

Source

pub fn font_library(&self) -> &FontLibrary

Source

pub fn set_fonts(&mut self, fonts: FontLibrary) -> &mut Self

Trait Implementations§

Source§

impl Default for CosmicTextMeasurer

Available on crate feature text-cosmic only.
Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl TextMeasurer for CosmicTextMeasurer

Available on crate feature text-cosmic only.
Source§

fn measure( &mut self, text: &TextContent, known: KnownSize, available: AvailableSize, ) -> UiSize

Auto Trait Implementations§

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
Source§

impl<T> Downcast<T> for T

Source§

fn downcast(&self) -> &T

Source§

impl<T> Downcast for T
where T: Any,

Source§

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.
Source§

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.
Source§

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.
Source§

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> DowncastSync for T
where T: Any + Send + Sync,

Source§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Sync + Send>

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

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.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

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>,

Source§

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.
Source§

impl<T> Upcast<T> for T

Source§

fn upcast(&self) -> Option<&T>

Source§

impl<T> WithSubscriber for T

Source§

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
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> WasmNotSend for T
where T: Send,

Source§

impl<T> WasmNotSendSync for T

Source§

impl<T> WasmNotSync for T
where T: Sync,