egui_simple_term 0.1.0

A small embeddable terminal widget for egui: a colored prompt, line editing, command history, and a scrollable output backlog.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
use eframe::egui::{Context, FontId};

/// Width and height of one terminal cell for the given font — the glyph width of
/// a fixed-width character and the row height.
pub(crate) fn cell_size(ctx: &Context, font_id: &FontId) -> [f32; 2] {
    ctx.fonts_mut(|f| [f.glyph_width(font_id, 'A'), f.row_height(font_id)])
}

/// How many screen rows `len` cells occupy at `cell_per_row` cells per row
/// (at least one, so an empty line still takes up a row).
pub(crate) fn visual_rows(len: usize, cell_per_row: usize) -> usize {
    len.div_ceil(cell_per_row).max(1)
}