mirror of
https://github.com/sxyazi/yazi.git
synced 2026-07-25 08:41:05 +00:00
refactor: deprecate ui.Rect.default (#2927)
This commit is contained in:
parent
e16c0da547
commit
8ef28ec678
1 changed files with 14 additions and 2 deletions
|
|
@ -3,6 +3,7 @@ use std::ops::Deref;
|
||||||
use mlua::{FromLua, IntoLua, Lua, MetaMethod, Table, UserData, Value};
|
use mlua::{FromLua, IntoLua, Lua, MetaMethod, Table, UserData, Value};
|
||||||
|
|
||||||
use super::Pad;
|
use super::Pad;
|
||||||
|
use crate::deprecate;
|
||||||
|
|
||||||
#[derive(Clone, Copy, Debug, Default, FromLua)]
|
#[derive(Clone, Copy, Debug, Default, FromLua)]
|
||||||
pub struct Rect(pub(super) ratatui::layout::Rect);
|
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 {}\nSee #2927 for more details: https://github.com/sxyazi/yazi/pull/2927");
|
||||||
|
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)
|
rect.into_lua(lua)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue