hex_patch/app/plugins/
popup_context.rs1use mlua::{Lua, Scope, Table};
2use ratatui::text::Text;
3
4pub struct PopupContext<'app> {
5 pub text: &'app mut Text<'static>,
6 pub title: &'app mut String,
7 pub height: &'app mut usize,
8 pub width: &'app mut usize,
9}
10
11impl<'app> PopupContext<'app> {
12 pub fn new(
13 text: &'app mut Text<'static>,
14 title: &'app mut String,
15 height: &'app mut usize,
16 width: &'app mut usize,
17 ) -> Self {
18 Self {
19 text,
20 title,
21 height,
22 width,
23 }
24 }
25
26 pub fn to_lua<'scope, 'env>(
27 &'env mut self,
28 lua: &Lua,
29 scope: &'scope Scope<'scope, 'env>,
30 ) -> Table {
31 let table = lua.create_table().unwrap();
32 table
33 .set(
34 "text",
35 scope.create_any_userdata_ref_mut(self.text).unwrap(),
36 )
37 .unwrap();
38 table
39 .set(
40 "title",
41 scope.create_any_userdata_ref_mut(self.title).unwrap(),
42 )
43 .unwrap();
44 table
45 .set(
46 "height",
47 scope.create_any_userdata_ref_mut(self.height).unwrap(),
48 )
49 .unwrap();
50 table
51 .set(
52 "width",
53 scope.create_any_userdata_ref_mut(self.width).unwrap(),
54 )
55 .unwrap();
56 table
57 }
58}