Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ ratatui = { version = "0.30", default-features = false, features = ["all-widgets
console_error_panic_hook = "0.1.7"
thiserror = "2.0.18"
bitvec = { version = "1.0.1", default-features = false, features = ["alloc", "std"] }
beamterm-renderer = "0.16.0"
beamterm-renderer = "0.17.0"
unicode-width = "0.2.2"

[dev-dependencies]
Expand Down
38 changes: 2 additions & 36 deletions src/backend/webgl2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@
(None, None)
};

let mut backend = Self {
Ok(Self {
beamterm,
cursor_position: None,
options,
Expand All @@ -384,12 +384,7 @@
hyperlink_state,
_user_mouse_handler: None,
_user_key_handler: None,
};

// Convert handler metrics from physical pixels to CSS pixels
backend.update_mouse_handler_metrics();

Ok(backend)
})
}

/// Returns the options objects used to create this backend.
Expand Down Expand Up @@ -422,8 +417,6 @@
// Reset hyperlink cursor state when canvas is resized
self.cursor_over_hyperlink = false;

self.update_mouse_handler_metrics();

Ok(())
}

Expand All @@ -444,32 +437,9 @@
pub fn set_size(&mut self, width: u32, height: u32) -> Result<(), Error> {
self.beamterm.resize(width as i32, height as i32)?;
self.cursor_over_hyperlink = false;
self.update_mouse_handler_metrics();
Ok(())
}

/// Updates metrics on externally-managed mouse handlers after resize or DPR changes.
///
/// Beamterm's `Terminal::resize()` only updates its own internal mouse handler.
/// The user and hyperlink handlers created by ratzilla need their metrics updated
/// separately.
fn update_mouse_handler_metrics(&mut self) {
let (cols, rows) = self.beamterm.terminal_size();
let (phys_w, phys_h) = self.beamterm.cell_size();
let dpr = window()
.map(|w| w.device_pixel_ratio() as f32)
.unwrap_or(1.0);
let cell_width = phys_w as f32 / dpr;
let cell_height = phys_h as f32 / dpr;

if let Some(handler) = &mut self._user_mouse_handler {
handler.update_metrics(cols, rows, cell_width, cell_height);
}
if let Some(handler) = &mut self._hyperlink_mouse_handler {
handler.update_metrics(cols, rows, cell_width, cell_height);
}
}

/// Checks if the canvas size matches the display size and resizes it if necessary.
fn check_canvas_resize(&mut self) -> Result<(), Error> {
// Compare CSS display size against beamterm's stored logical size.
Expand Down Expand Up @@ -648,7 +618,7 @@
.is_some();
if self.cursor_over_hyperlink != is_over {
self.cursor_over_hyperlink = is_over;
Self::update_canvas_cursor_style(&self.beamterm.canvas(), is_over);

Check warning on line 621 in src/backend/webgl2.rs

View workflow job for this annotation

GitHub Actions / clippy

this expression creates a reference which is immediately dereferenced by the compiler

warning: this expression creates a reference which is immediately dereferenced by the compiler --> src/backend/webgl2.rs:621:50 | 621 | Self::update_canvas_cursor_style(&self.beamterm.canvas(), is_over); | ^^^^^^^^^^^^^^^^^^^^^^^ help: change this to: `self.beamterm.canvas()` | = help: for further information visit https://rust-lang.github.io/rust-clippy/rust-1.94.0/index.html#needless_borrow = note: `#[warn(clippy::needless_borrow)]` on by default
}
}

Expand Down Expand Up @@ -848,7 +818,7 @@
/// A `Debug`-derive friendly convenience wrapper
#[derive(Clone)]
struct HyperlinkCallback {
callback: Rc<RefCell<dyn FnMut(&str)>>,

Check warning on line 821 in src/backend/webgl2.rs

View workflow job for this annotation

GitHub Actions / clippy

very complex type used. Consider factoring parts into `type` definitions

warning: very complex type used. Consider factoring parts into `type` definitions --> src/backend/webgl2.rs:821:15 | 821 | callback: Rc<RefCell<dyn FnMut(&str)>>, | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/rust-1.94.0/index.html#type_complexity = note: `#[warn(clippy::type_complexity)]` on by default
}

impl HyperlinkCallback {
Expand Down Expand Up @@ -924,10 +894,6 @@

self._user_mouse_handler = Some(mouse_handler);

// TerminalMouseHandler is constructed with physical pixel metrics;
// convert to CSS pixels so coordinate translation is correct on HiDPI.
self.update_mouse_handler_metrics();

Ok(())
}

Expand Down
Loading