nvim_api/types/
window_config.rs1use derive_builder::Builder;
2use nvim_types::{
3 conversion::{self, FromObject},
4 serde::Deserializer,
5 Array,
6 Float,
7 Integer,
8 Object,
9};
10use serde::Deserialize;
11
12use super::{WindowAnchor, WindowBorder, WindowRelativeTo, WindowStyle};
13
14#[non_exhaustive]
15#[derive(Clone, Debug, Default, PartialEq, Builder, Deserialize)]
16#[builder(default, build_fn(private, name = "fallible_build"))]
17pub struct WindowConfig {
18 #[builder(setter(strip_option))]
20 pub anchor: Option<WindowAnchor>,
21
22 #[builder(setter(strip_option))]
24 pub border: Option<WindowBorder>,
25
26 #[builder(setter(custom))]
32 pub bufpos: Option<(usize, usize)>,
33
34 #[builder(setter(into, strip_option))]
36 pub col: Option<Float>,
37
38 #[builder(setter(strip_option))]
41 pub external: Option<bool>,
42
43 #[builder(setter(strip_option))]
46 pub focusable: Option<bool>,
47
48 #[builder(setter(strip_option))]
50 pub height: Option<u32>,
51
52 #[builder(setter(strip_option))]
55 pub noautocmd: Option<bool>,
56
57 #[builder(setter(strip_option))]
59 pub relative: Option<WindowRelativeTo>,
60
61 #[builder(setter(into, strip_option))]
63 pub row: Option<Float>,
64
65 #[builder(setter(strip_option))]
67 pub style: Option<WindowStyle>,
68
69 #[builder(setter(strip_option))]
71 pub width: Option<u32>,
72
73 #[builder(setter(strip_option))]
76 pub zindex: Option<u32>,
77}
78
79impl WindowConfig {
80 #[inline(always)]
81 pub fn builder() -> WindowConfigBuilder {
83 WindowConfigBuilder::default()
84 }
85}
86
87impl WindowConfigBuilder {
88 pub fn bufpos(&mut self, line: usize, column: usize) -> &mut Self {
94 self.bufpos = Some(Some((line, column)));
95 self
96 }
97
98 pub fn build(&mut self) -> WindowConfig {
99 self.fallible_build().expect("never fails, all fields have defaults")
100 }
101}
102
103impl FromObject for WindowConfig {
104 fn from_object(obj: Object) -> Result<Self, conversion::Error> {
105 Self::deserialize(Deserializer::new(obj)).map_err(Into::into)
106 }
107}
108
109#[derive(Default)]
110#[allow(non_camel_case_types)]
111#[repr(C)]
112pub(crate) struct KeyDict_float_config {
113 col: Object,
114 row: Object,
115 win: Object,
116 style: Object,
117 width: Object,
118 height: Object,
119 zindex: Object,
120 anchor: Object,
121 border: Object,
122 bufpos: Object,
123 external: Object,
124 relative: Object,
125 focusable: Object,
126 noautocmd: Object,
127}
128
129impl From<&WindowConfig> for KeyDict_float_config {
130 fn from(config: &WindowConfig) -> Self {
131 let win = match &config.relative {
132 Some(WindowRelativeTo::Window(win)) => win.0.into(),
133 _ => Object::nil(),
134 };
135
136 let bufpos = match config.bufpos {
137 Some((line, column)) => {
138 Array::from_iter([line as Integer, column as Integer]).into()
139 },
140 _ => Object::nil(),
141 };
142
143 Self {
144 col: config.col.into(),
145 row: config.row.into(),
146 win,
147 style: config.style.into(),
148 width: config.width.into(),
149 height: config.height.into(),
150 zindex: config.zindex.into(),
151 anchor: config.anchor.into(),
152 border: config.border.clone().into(),
153 bufpos,
154 external: config.external.into(),
155 relative: config.relative.as_ref().into(),
156 focusable: config.focusable.into(),
157 noautocmd: config.noautocmd.into(),
158 }
159 }
160}