Skip to content

Commit 2030bc3

Browse files
authored
feat(webgl2): add cell_size() and set_size() to WebGl2Backend (#164)
1 parent 28b4934 commit 2030bc3

3 files changed

Lines changed: 73 additions & 8 deletions

File tree

Cargo.lock

Lines changed: 51 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ ratatui = { version = "0.30", default-features = false, features = ["all-widgets
4444
console_error_panic_hook = "0.1.7"
4545
thiserror = "2.0.18"
4646
bitvec = { version = "1.0.1", default-features = false, features = ["alloc", "std"] }
47-
beamterm-renderer = "0.15.0"
47+
beamterm-renderer = "0.16.0"
4848
unicode-width = "0.2.2"
4949

5050
[dev-dependencies]

src/backend/webgl2.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -427,6 +427,27 @@ impl WebGl2Backend {
427427
Ok(())
428428
}
429429

430+
/// Returns the cell size in physical pixels at the current device
431+
/// pixel ratio.
432+
///
433+
/// For static atlases, this is the cell size from the atlas data.
434+
/// For dynamic atlases, this is measured from the rasterized font.
435+
pub fn cell_size(&self) -> (i32, i32) {
436+
self.beamterm.cell_size()
437+
}
438+
439+
/// Resizes the canvas and terminal grid to the specified logical pixel dimensions.
440+
///
441+
/// This updates the canvas buffer, CSS display size (if auto-resize is enabled),
442+
/// viewport, and recalculates the terminal grid dimensions based on the current
443+
/// cell size.
444+
pub fn set_size(&mut self, width: u32, height: u32) -> Result<(), Error> {
445+
self.beamterm.resize(width as i32, height as i32)?;
446+
self.cursor_over_hyperlink = false;
447+
self.update_mouse_handler_metrics();
448+
Ok(())
449+
}
450+
430451
/// Updates metrics on externally-managed mouse handlers after resize or DPR changes.
431452
///
432453
/// Beamterm's `Terminal::resize()` only updates its own internal mouse handler.

0 commit comments

Comments
 (0)