Skip to content

Commit

Permalink
Make grid scroll speed controllable
Browse files Browse the repository at this point in the history
  • Loading branch information
vhakulinen committed Oct 18, 2021
1 parent 3bd6154 commit 5f5aa19
Show file tree
Hide file tree
Showing 9 changed files with 43 additions and 3 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ $ cargo build --no-default-features
* No electron (!), build on GTK.
* Ligatures
* Animated cursor
* Animated scrolling
* Custom cursor tooltip feature to display markdown documents.
Useful for implementing features like hover information or signature help
(see [gnvim-lsp](https://github.com/vhakulinen/gnvim-lsp)).
Expand Down
17 changes: 17 additions & 0 deletions runtime/doc/gnvim.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ CONTENTS *gnvim-contents*
2. Popupmenu............................|gnvim-popupmenu|
3. Cursor...............................|gnvim-cursor|
4. Ext options..........................|gnvim-ext-opts|
5. Grid scroll..........................|gnvim-grid-scroll|

================================================================================
Cursor Tooltip *gnvim-cursor-tooltip*
Expand Down Expand Up @@ -66,6 +67,17 @@ Gnvim utilizes many of the externalized UI options nvim offers. Some of these
changes the visual representation of some nvim features and thus users might
want to revert back to the "default" (e.g. TUI) functionality. This can be
done either through cli flags or `gnvim#enable_ext_*` functions.
================================================================================
Grid scroll *gnvim-grid-scroll*
*gnvim-scroll*

Gnvim animates grid scrolling. The speed of the scroll animation can be
adjusted by `g:gnvim_grid_scroll_speed`. Setting it to zero effectively
disables the animation.

Current limitations:
* Big jumps (e.g. from beginning of the file to the end) aren't animated
* Empty background will be shown if the animation jumps to far

================================================================================
Commands *gnvim-commands*
Expand Down Expand Up @@ -133,4 +145,9 @@ gnvim#popupmenu#show_menu_on_all_items *gnvim#popupmenu#show_menu_on_all_items*
Instructs the popupmenu to show the `menu` item for all (e.g. inactive)
completion items. Accepts one parameter, 0 or 1.

g:gnvim_grid_scroll_speed *g:gnvim_grid_scroll_speed*

Control the grid scroll animation speed. Zero effectively disables the
animation.

vim:tw=78:ts=8:ft=help:norl:
3 changes: 3 additions & 0 deletions runtime/doc/tags
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
CursorTooltipStyle gnvim.txt /*CursorTooltipStyle*
g:gnvim_grid_scroll_speed gnvim.txt /*g:gnvim_grid_scroll_speed*
gnvim gnvim.txt /*gnvim*
gnvim#cursor_tooltip#get_styles gnvim.txt /*gnvim#cursor_tooltip#get_styles*
gnvim#cursor_tooltip#hide gnvim.txt /*gnvim#cursor_tooltip#hide*
Expand All @@ -19,4 +20,6 @@ gnvim-cursor-blinking gnvim.txt /*gnvim-cursor-blinking*
gnvim-cursor-tooltip gnvim.txt /*gnvim-cursor-tooltip*
gnvim-ext-options gnvim.txt /*gnvim-ext-options*
gnvim-functions gnvim.txt /*gnvim-functions*
gnvim-grid-scroll gnvim.txt /*gnvim-grid-scroll*
gnvim-popupmenu gnvim.txt /*gnvim-popupmenu*
gnvim-scroll gnvim.txt /*gnvim-scroll*
12 changes: 10 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,16 @@ async fn build(app: &gtk::Application, args: &args::Args) -> Result<(), Error> {

nvim.ui_attach(80, 30, &args.nvim_ui_opts()).await?;

let ui =
ui::UI::init(app, rx, args.geometry, nvim).expect("failed to init ui");
let grid_scroll_speed = nvim
.get_var("gnvim_grid_scroll_speed")
.await
.ok()
.and_then(|val| val.as_i64())
.unwrap_or(300)
.max(0);

let ui = ui::UI::init(app, rx, args.geometry, nvim, grid_scroll_speed)
.expect("failed to init ui");
ui.start();

Ok(())
Expand Down
4 changes: 4 additions & 0 deletions src/ui/grid/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ pub struct Context {

/// If the grid that this context belongs to is active or not.
pub active: bool,
/// Grid scroll speed, in ms.
pub scroll_speed: i64,

/// Areas to call queue_draw_area on the drawing area on flush.
pub queue_draw_area: Vec<(f64, f64, f64, f64)>,
Expand All @@ -45,6 +47,7 @@ impl Context {
rows: usize,
hl_defs: &HlDefs,
enable_cursor_animations: bool,
scroll_speed: i64,
) -> Result<Self, Error> {
let pango_context = da.pango_context();

Expand Down Expand Up @@ -79,6 +82,7 @@ impl Context {

busy: false,
active: false,
scroll_speed,

queue_draw_area: vec![],
})
Expand Down
2 changes: 2 additions & 0 deletions src/ui/grid/grid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ impl Grid {
rows: usize,
hl_defs: &HlDefs,
enable_cursor_animations: bool,
scroll_speed: i64,
) -> Result<Self, Error> {
let da = DrawingArea::new();
let ctx = Rc::new(RefCell::new(Context::new(
Expand All @@ -113,6 +114,7 @@ impl Grid {
rows,
hl_defs,
enable_cursor_animations,
scroll_speed,
)?));

da.connect_draw(clone!(ctx => move |_, cr| {
Expand Down
2 changes: 1 addition & 1 deletion src/ui/grid/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ pub fn scroll(
prev.restore()?;

ctx.queue_draw_area.push((x1, y1, w, h));
ctx.surfaces.set_animation(y, 300, frame_time);
ctx.surfaces.set_animation(y, ctx.scroll_speed, frame_time);

Ok(())
}
Expand Down
2 changes: 2 additions & 0 deletions src/ui/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ pub(crate) struct UIState {
pub line_space: i64,

pub enable_cursor_animations: bool,
pub grid_scroll_speed: i64,
}

impl UIState {
Expand Down Expand Up @@ -191,6 +192,7 @@ impl UIState {
e.height as usize,
&self.hl_defs,
self.enable_cursor_animations,
self.grid_scroll_speed,
)?;

if let Some(ref mode) = self.current_mode {
Expand Down
3 changes: 3 additions & 0 deletions src/ui/ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ impl UI {
rx: glib::Receiver<Message>,
window_size: (i32, i32),
nvim: GioNeovim,
grid_scroll_speed: i64,
) -> Result<Self, Error> {
// Create the main window.
let window = gtk::ApplicationWindow::new(app);
Expand Down Expand Up @@ -88,6 +89,7 @@ impl UI {
30,
&hl_defs,
true,
grid_scroll_speed,
)?;
// Mark the default grid as active at the beginning.
grid.set_active(true);
Expand Down Expand Up @@ -262,6 +264,7 @@ impl UI {
line_space,
current_mode: None,
enable_cursor_animations: true,
grid_scroll_speed,
})),
nvim,
})
Expand Down

0 comments on commit 5f5aa19

Please sign in to comment.