mirror of
https://github.com/sxyazi/yazi.git
synced 2026-07-21 23:01:05 +00:00
refactor: deprecate ui.Padding and ui.Rect:padding() (#2574)
This commit is contained in:
parent
9565c1b6fd
commit
fd007ab023
3 changed files with 15 additions and 5 deletions
|
|
@ -17,6 +17,13 @@ impl From<ratatui::widgets::Padding> for Pad {
|
|||
|
||||
impl Pad {
|
||||
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 {
|
||||
lua.create_function(|_, (_, top, right, bottom, left): (Table, u16, u16, u16, u16)| {
|
||||
Ok(Self(ratatui::widgets::Padding::new(left, right, top, bottom)))
|
||||
|
|
|
|||
|
|
@ -72,7 +72,10 @@ impl UserData for Rect {
|
|||
fn add_methods<M: mlua::UserDataMethods<Self>>(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())));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -49,10 +49,10 @@ impl File {
|
|||
|
||||
impl FromLua for File {
|
||||
fn from_lua(value: Value, _: &Lua) -> mlua::Result<Self> {
|
||||
match value {
|
||||
Value::UserData(ud) => ud.take().map(Self::new),
|
||||
_ => Err("Expected a File".into_lua_err()),
|
||||
}
|
||||
Ok(match value {
|
||||
Value::UserData(ud) => Self::new(ud.take::<Self>()?.inner),
|
||||
_ => Err("Expected a File".into_lua_err())?,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue