refactor: deprecate ui.Padding and ui.Rect:padding()

This commit is contained in:
sxyazi 2025-04-05 11:06:25 +08:00
parent 9565c1b6fd
commit 9d7af58824
No known key found for this signature in database
2 changed files with 11 additions and 1 deletions

View file

@ -17,6 +17,13 @@ impl From<ratatui::widgets::Padding> for Pad {
impl Pad { impl Pad {
pub fn compose(lua: &Lua, v4: bool) -> mlua::Result<Table> { pub fn compose(lua: &Lua, v4: bool) -> mlua::Result<Table> {
if !v4 {
crate::deprecate!(
lua,
"The `ui.Padding` has been deprecated, please use `ui.Pad` instead, in your {}"
);
}
let new = if v4 { let new = if v4 {
lua.create_function(|_, (_, top, right, bottom, left): (Table, u16, u16, u16, u16)| { lua.create_function(|_, (_, top, right, bottom, left): (Table, u16, u16, u16, u16)| {
Ok(Self(ratatui::widgets::Padding::new(left, right, top, bottom))) Ok(Self(ratatui::widgets::Padding::new(left, right, top, bottom)))

View file

@ -72,7 +72,10 @@ impl UserData for Rect {
fn add_methods<M: mlua::UserDataMethods<Self>>(methods: &mut M) { fn add_methods<M: mlua::UserDataMethods<Self>>(methods: &mut M) {
methods.add_method("pad", |_, me, pad: Pad| Ok(me.pad(pad))); methods.add_method("pad", |_, me, pad: Pad| Ok(me.pad(pad)));
// TODO: deprecate this // TODO: deprecate this
methods.add_method("padding", |_, me, pad: Pad| Ok(me.pad(pad))); methods.add_method("padding", |lua, me, pad: Pad| {
crate::deprecate!(lua, "The `padding()` method of `ui.Rect` has been deprecated, please use `pad()` instead, in your {}");
Ok(me.pad(pad))
});
methods.add_method("contains", |_, me, Rect(rect)| Ok(me.contains(rect.into()))); methods.add_method("contains", |_, me, Rect(rect)| Ok(me.contains(rect.into())));
} }
} }