mirror of
https://github.com/sxyazi/yazi.git
synced 2026-07-25 08:41:05 +00:00
..
This commit is contained in:
parent
a51298f0d6
commit
a8bd21ad5f
4 changed files with 65 additions and 1 deletions
56
yazi-fm/src/app/commands/reflow.rs
Normal file
56
yazi-fm/src/app/commands/reflow.rs
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
use std::sync::Arc;
|
||||
|
||||
use mlua::Value;
|
||||
use ratatui::layout::Position;
|
||||
use tracing::error;
|
||||
use yazi_config::LAYOUT;
|
||||
use yazi_macro::render;
|
||||
use yazi_shared::event::Cmd;
|
||||
|
||||
use crate::{Root, app::App, lives::Lives};
|
||||
|
||||
struct Opt;
|
||||
|
||||
impl From<Cmd> for Opt {
|
||||
fn from(_: Cmd) -> Self { Self }
|
||||
}
|
||||
|
||||
impl From<()> for Opt {
|
||||
fn from(_: ()) -> Self { Self }
|
||||
}
|
||||
|
||||
impl App {
|
||||
#[yazi_codegen::command]
|
||||
pub fn reflow(&mut self, _: Opt) {
|
||||
let Some(size) = self.term.as_ref().and_then(|t| t.size().ok()) else { return };
|
||||
let mut layout = *LAYOUT.load_full();
|
||||
|
||||
let result = Lives::scope(&self.cx, |_| {
|
||||
let comps = Root::reflow((Position::ORIGIN, size).into())?;
|
||||
|
||||
for v in comps.sequence_values::<Value>() {
|
||||
let Value::Table(t) = v? else {
|
||||
error!("`reflow()` must return a table of components");
|
||||
continue;
|
||||
};
|
||||
|
||||
let id: mlua::String = t.get("_id")?;
|
||||
match id.to_str()? {
|
||||
"current" => layout.current = *t.raw_get::<_, yazi_plugin::elements::Rect>("_area")?,
|
||||
"preview" => layout.preview = *t.raw_get::<_, yazi_plugin::elements::Rect>("_area")?,
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
});
|
||||
|
||||
if layout != *LAYOUT.load_full() {
|
||||
LAYOUT.store(Arc::new(layout));
|
||||
render!();
|
||||
}
|
||||
|
||||
if let Err(e) = result {
|
||||
error!("Failed to `reflow()` the `Root` component:\n{e}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -16,7 +16,7 @@ impl App {
|
|||
#[yazi_codegen::command]
|
||||
pub fn resize(&mut self, _: Opt) {
|
||||
self.cx.manager.active_mut().preview.reset();
|
||||
self.render();
|
||||
self.reflow(());
|
||||
|
||||
self.cx.manager.current_mut().sync_page(true);
|
||||
self.cx.manager.hover(None);
|
||||
|
|
|
|||
|
|
@ -12,6 +12,12 @@ pub(super) struct Root<'a> {
|
|||
|
||||
impl<'a> Root<'a> {
|
||||
pub(super) fn new(cx: &'a Ctx) -> Self { Self { cx } }
|
||||
|
||||
pub(super) fn reflow<'lua>(area: Rect) -> mlua::Result<Table<'lua>> {
|
||||
let area = yazi_plugin::elements::Rect::from(area);
|
||||
let root = LUA.globals().raw_get::<_, Table>("Root")?.call_method::<_, Table>("new", area)?;
|
||||
root.call_method("reflow", ())
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> Widget for Root<'a> {
|
||||
|
|
|
|||
|
|
@ -131,6 +131,8 @@ function Status:position()
|
|||
}
|
||||
end
|
||||
|
||||
function Status:reflow() return { self } end
|
||||
|
||||
function Status:redraw()
|
||||
local left = self:children_redraw(self.LEFT)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue