leptos_use_window_size/options.rs
1use crate::Size;
2use default_struct_builder::DefaultBuilder;
3
4/// Options for [`fn@crate::use_window_size_with_options`].
5#[derive(DefaultBuilder)]
6pub struct UseWindowSizeOptions {
7 /// The initial size before anything is measured (like on the server side).
8 /// Defaults to `Size { width: INFINITY, height: INFINITY }`.
9 pub(crate) initial_size: Size,
10
11 /// Listen to the window ` orientationchange ` event. Defaults to `true`.
12 pub(crate) listen_orientation: bool,
13
14 /// Whether the scrollbar should be included in the width and height
15 /// Only effective when `measure_type` is `MeasureType::Inner`.
16 /// Defaults to `true`.
17 pub(crate) include_scrollbar: bool,
18
19 /// Use `window.innerWidth` or `window.outerWidth`.
20 /// Defaults to `MeasureType::Inner`.
21 pub(crate) measure_type: MeasureType,
22}
23
24/// Type of the `measure_type` option.
25#[derive(Default, Clone, Copy, PartialEq, Eq, Debug)]
26pub enum MeasureType {
27 /// Use `window.innerWidth`
28 #[default]
29 Inner,
30 /// Use `window.outerWidth`
31 Outer,
32}
33
34impl Default for UseWindowSizeOptions {
35 fn default() -> Self {
36 Self {
37 initial_size: Size {
38 width: f64::INFINITY,
39 height: f64::INFINITY,
40 },
41 listen_orientation: true,
42 include_scrollbar: true,
43 measure_type: MeasureType::default(),
44 }
45 }
46}