pub struct CosmicTextMeasurer { /* private fields */ }Implementations§
Source§impl CosmicTextMeasurer
impl CosmicTextMeasurer
Sourcepub fn new() -> Self
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 }pub fn with_fonts(fonts: FontLibrary) -> Self
pub fn font_library(&self) -> &FontLibrary
pub fn set_fonts(&mut self, fonts: FontLibrary) -> &mut Self
Trait Implementations§
Source§impl Default for CosmicTextMeasurer
Available on crate feature text-cosmic only.
impl Default for CosmicTextMeasurer
Available on crate feature
text-cosmic only.Source§impl TextMeasurer for CosmicTextMeasurer
Available on crate feature text-cosmic only.
impl TextMeasurer for CosmicTextMeasurer
Available on crate feature
text-cosmic only.fn measure( &mut self, text: &TextContent, known: KnownSize, available: AvailableSize, ) -> UiSize
Auto Trait Implementations§
impl !Freeze for CosmicTextMeasurer
impl !RefUnwindSafe for CosmicTextMeasurer
impl Send for CosmicTextMeasurer
impl Sync for CosmicTextMeasurer
impl Unpin for CosmicTextMeasurer
impl UnsafeUnpin for CosmicTextMeasurer
impl !UnwindSafe for CosmicTextMeasurer
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
Mutably borrows from an owned value. Read more
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>
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>
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)
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)
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.