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

This commit is contained in:
三咲雅 · Misaki Masa 2025-04-05 11:16:56 +08:00 committed by sxyazi
parent 9565c1b6fd
commit fd007ab023
No known key found for this signature in database
3 changed files with 15 additions and 5 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())));
} }
} }

View file

@ -49,10 +49,10 @@ impl File {
impl FromLua for File { impl FromLua for File {
fn from_lua(value: Value, _: &Lua) -> mlua::Result<Self> { fn from_lua(value: Value, _: &Lua) -> mlua::Result<Self> {
match value { Ok(match value {
Value::UserData(ud) => ud.take().map(Self::new), Value::UserData(ud) => Self::new(ud.take::<Self>()?.inner),
_ => Err("Expected a File".into_lua_err()), _ => Err("Expected a File".into_lua_err())?,
} })
} }
} }