From 9d7af58824698b3a9bc1fd2007370e18b62c733f Mon Sep 17 00:00:00 2001 From: sxyazi Date: Sat, 5 Apr 2025 11:06:25 +0800 Subject: [PATCH] refactor: deprecate `ui.Padding` and `ui.Rect:padding()` --- yazi-plugin/src/elements/pad.rs | 7 +++++++ yazi-plugin/src/elements/rect.rs | 5 ++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/yazi-plugin/src/elements/pad.rs b/yazi-plugin/src/elements/pad.rs index 141ccaf7..94d97e41 100644 --- a/yazi-plugin/src/elements/pad.rs +++ b/yazi-plugin/src/elements/pad.rs @@ -17,6 +17,13 @@ impl From for Pad { impl Pad { pub fn compose(lua: &Lua, v4: bool) -> mlua::Result { + if !v4 { + crate::deprecate!( + lua, + "The `ui.Padding` has been deprecated, please use `ui.Pad` instead, in your {}" + ); + } + let new = if v4 { lua.create_function(|_, (_, top, right, bottom, left): (Table, u16, u16, u16, u16)| { Ok(Self(ratatui::widgets::Padding::new(left, right, top, bottom))) diff --git a/yazi-plugin/src/elements/rect.rs b/yazi-plugin/src/elements/rect.rs index d0d16db0..78b9690d 100644 --- a/yazi-plugin/src/elements/rect.rs +++ b/yazi-plugin/src/elements/rect.rs @@ -72,7 +72,10 @@ impl UserData for Rect { fn add_methods>(methods: &mut M) { methods.add_method("pad", |_, me, pad: Pad| Ok(me.pad(pad))); // 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()))); } }