blob: f7311a033d8646476427efe762bf17e3bc0f5da9 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
use mlua::UserData;
use super::{window::Window, GlobalState};
#[derive(Debug, Default)]
pub struct LogState {
pub visible: bool,
}
impl LogState {
pub const fn new() -> Self {
Self { visible: false }
}
}
macro_rules! cfg {
() => {
GlobalState::instance().log
};
}
impl UserData for LogState {
fn add_fields<'lua, F: mlua::prelude::LuaUserDataFields<'lua, Self>>(fields: &mut F) {
fields.add_field_function_get("visible", |_, _| Ok(cfg!().visible));
fields.add_field_function_set("visible", |_, _, visible: bool| {
let mut state = GlobalState::instance_mut();
state.log.visible = visible;
if let Window::Log = state.active_window {
if !visible {
state.set_focus(Window::Log);
}
}
Ok(())
});
}
}
|