refactor: deprecate ui.Rect.default

This commit is contained in:
sxyazi 2025-06-27 23:00:13 +08:00
parent e16c0da547
commit 98dfe78216
No known key found for this signature in database

View file

@ -3,6 +3,7 @@ use std::ops::Deref;
use mlua::{FromLua, IntoLua, Lua, MetaMethod, Table, UserData, Value};
use super::Pad;
use crate::deprecate;
#[derive(Clone, Copy, Debug, Default, FromLua)]
pub struct Rect(pub(super) ratatui::layout::Rect);
@ -34,9 +35,20 @@ impl Rect {
}))
})?;
let rect = lua.create_table_from([("default", Self(ratatui::layout::Rect::default()))])?;
let index = lua.create_function(move |lua, (_, key): (Table, mlua::String)| {
Ok(match key.as_bytes().as_ref() {
b"default" => {
deprecate!(lua, "`ui.Rect.default` is deprecated, use `ui.Rect{{}}` instead, in your {}");
Some(Self(Default::default()))
}
_ => None,
})
})?;
rect.set_metatable(Some(lua.create_table_from([(MetaMethod::Call.name(), new)])?));
let rect = lua.create_table()?;
rect.set_metatable(Some(
lua.create_table_from([(MetaMethod::Call.name(), new), (MetaMethod::Index.name(), index)])?,
));
rect.into_lua(lua)
}