dioxus_use_window/hooks/use_width/
mod.rs

1mod display;
2use super::*;
3
4/// Window width effect handler
5#[derive(Debug)]
6pub struct UseWindowWidth {
7    inner: UseWindow,
8}
9
10impl UseWindowWidth {
11    pub(crate) fn new(size: UseWindow) -> Self {
12        Self { inner: size }
13    }
14}
15
16impl UseWindowWidth {
17    /// get width of current window
18    #[inline]
19    pub fn get(&self) -> usize {
20        self.inner.data_ref().inner_width() as _
21    }
22    /// set width of current window, return `false` if failed to run
23    #[inline]
24    pub fn set(&self, width: usize) -> bool {
25        self.inner.data_ref().set_inner_width(width).is_some()
26    }
27    /// get layout of current window, return `false` if failed to run
28    #[inline]
29    pub fn layout<T>(&self) -> T
30    where
31        T: From<usize>,
32    {
33        self.inner.layout()
34    }
35}