Pass scrolltop in custom Lua function

pull/709/head
Arijit Basu 2 months ago
parent 90df0a2b5a
commit 10028e5618
No known key found for this signature in database
GPG Key ID: 0F8EF5258DC38077

@ -42,9 +42,16 @@ Set it to `true` if you want to hide all remaps in the help menu.
Type: boolean
#### xplr.config.general.vimlike_scrolling
#### xplr.config.general.paginated_scrolling
Set it to `true` if you want vim-like scrolling.
Set it to `true` if you want paginated scrolling.
Type: boolean
#### xplr.config.general.scroll_padding
Set the padding value to the scroll area.
Only applicable when `xplr.config.general.paginated_scrolling = false`.
Type: boolean

@ -495,6 +495,7 @@ It contains the following information:
- [layout_size][37]
- [screen_size][37]
- [scrolltop][57]
- [app][38]
### Size
@ -508,6 +509,12 @@ It contains the following information:
Every field is of integer type.
### scrolltop
Type: integer
The start index of the visible nodes in the table.
### app
This is a lightweight version of the [Lua Context][39]. In this context, the
@ -587,3 +594,4 @@ Hence, only the following fields are available.
[54]: borders.md#border-type
[55]: #customlayout
[56]: sum-type.md
[57]: #scrolltop

@ -132,6 +132,8 @@ compatibility.
`xplr.config.general.paginated_scrolling = true` to revert back to the
paginated scrolling.
- Set `xplr.config.general.scroll_padding` to customize the scroll padding.
- The calculated `scrolltop` value will be passed as part of the
`Content Rendeder Argument` in `Dynamic` layout renderer functions.
Thanks to @noahmayr for contributing to a major part of this release.

@ -85,6 +85,7 @@ pub fn draw_custom_content(
app: app.to_lua_ctx_light(),
layout_size: layout_size.into(),
screen_size: ui.screen_size.into(),
scrolltop: ui.scrolltop as u16,
};
let render = lua::serialize(ui.lua, &ctx)
@ -121,6 +122,7 @@ pub fn draw_custom_content(
app: app.to_lua_ctx_light(),
layout_size: layout_size.into(),
screen_size: ui.screen_size.into(),
scrolltop: ui.scrolltop as u16,
};
let items = lua::serialize(ui.lua, &ctx)
@ -182,6 +184,7 @@ pub fn draw_custom_content(
app: app.to_lua_ctx_light(),
layout_size: layout_size.into(),
screen_size: ui.screen_size.into(),
scrolltop: ui.scrolltop as u16,
};
let rows = lua::serialize(ui.lua, &ctx)

@ -96,8 +96,8 @@ xplr.config.general.hide_remaps_in_help_menu = false
-- Type: boolean
xplr.config.general.paginated_scrolling = false
-- Set the padding value to the scroll area. Only applicable when
-- `xplr.config.general.paginated_scrolling` is set to `false`.
-- Set the padding value to the scroll area.
-- Only applicable when `xplr.config.general.paginated_scrolling = false`.
--
-- Type: boolean
xplr.config.general.scroll_padding = 5

@ -84,6 +84,7 @@ pub struct ContentRendererArg {
pub app: app::LuaContextLight,
pub screen_size: Rect,
pub layout_size: Rect,
pub scrolltop: u16,
}
#[derive(Debug, Clone, Default, Serialize, Deserialize, PartialEq, Eq)]
@ -764,8 +765,7 @@ impl UI<'_> {
let config = panel_config.default.clone().extend(&panel_config.table);
let app_config = app.config.clone();
let header_height = app_config.general.table.header.height.unwrap_or(1);
let height: usize =
(layout_size.height.max(header_height + 2) - (header_height + 2)).into();
let height: usize = layout_size.height.saturating_sub(header_height + 2).into();
let row_style = app_config.general.table.row.style.clone();
let rows = app
@ -777,12 +777,12 @@ impl UI<'_> {
// Paginated scrolling
self.scrolltop = height * (dir.focus / height.max(1))
} else {
// vim-like-scrolling
// Vim-like-scrolling
self.scrolltop = match dir.focus.cmp(&self.scrolltop) {
Ordering::Greater => {
// Scrolling down
if dir.focus >= self.scrolltop + height {
dir.focus - height + 1
dir.focus.saturating_sub(height + 1)
} else {
self.scrolltop
}
@ -1326,6 +1326,7 @@ impl UI<'_> {
app: app.to_lua_ctx_light(),
layout_size: layout_size.into(),
screen_size: self.screen_size.into(),
scrolltop: self.scrolltop as u16,
};
let panel: CustomPanel = lua::serialize(self.lua, &ctx)

Loading…
Cancel
Save