pub struct GlyphBuffer { /* private fields */ }Expand description
A grid of Cells, row-major.
Implementations§
Source§impl GlyphBuffer
impl GlyphBuffer
Sourcepub fn panel(&mut self, rect: Rect, look: &PanelLook, title: Option<&str>)
pub fn panel(&mut self, rect: Rect, look: &PanelLook, title: Option<&str>)
A panel: clears rect to look.text on look.bg, frames it in
look.style and look.border, and sets title, if any, into the
top border in look.title, two cells from the left with a space
each side of it. A title that doesn’t fit is cut; the border
keeps a line and its corner on each side.
use shuyi_ui::frame::draw::PanelLook;
use shuyi_ui::frame::{BoxStyle, Cell, GlyphBuffer, Rgb};
let (white, black) = (Rgb::new(255, 255, 255), Rgb::new(0, 0, 0));
let look = PanelLook::new(BoxStyle::Single, white, black);
let mut buf = GlyphBuffer::new(12, 3, Cell::new(' ', white, black));
buf.panel(buf.bounds(), &look, Some("Shop"));
let top: String = (0..12).map(|x| buf.get(x, 0).unwrap().glyph).collect();
assert_eq!(top, "┌─ Shop ───┐");Sourcepub fn meter(
&mut self,
rect: Rect,
filled: u32,
of: u32,
full: Cell,
empty: Cell,
)
pub fn meter( &mut self, rect: Rect, filled: u32, of: u32, full: Cell, empty: Cell, )
A meter: each row of rect is rect.w cells, the first
meter_fill of them full and the rest empty, showing filled
of of.
use shuyi_ui::frame::{Cell, GlyphBuffer, Rect, Rgb};
let (white, black) = (Rgb::new(255, 255, 255), Rgb::new(0, 0, 0));
let mut buf = GlyphBuffer::new(10, 1, Cell::new(' ', white, black));
let (full, empty) = (Cell::new('█', white, black), Cell::new('░', white, black));
buf.meter(buf.bounds(), 12, 20, full, empty);
let row: String = (0..10).map(|x| buf.get(x, 0).unwrap().glyph).collect();
assert_eq!(row, "██████░░░░");Sourcepub fn print_centred(&mut self, rect: Rect, text: &str, fg: Rgb) -> u16
pub fn print_centred(&mut self, rect: Rect, text: &str, fg: Rgb) -> u16
Prints text in fg on the middle row of rect (the upper of two
middles), centred across it (a cell left of the middle when the
cells left over are odd) and cut to its width, keeping each
cell’s background. Returns how many cells were written.
use shuyi_ui::frame::{Cell, GlyphBuffer, Rect, Rgb};
let (white, black) = (Rgb::new(255, 255, 255), Rgb::new(0, 0, 0));
let mut buf = GlyphBuffer::new(9, 1, Cell::new('.', white, black));
buf.print_centred(buf.bounds(), "Paused", white);
let row: String = (0..9).map(|x| buf.get(x, 0).unwrap().glyph).collect();
assert_eq!(row, ".Paused..");Sourcepub fn print_cut(
&mut self,
x: i32,
y: i32,
width: usize,
text: &str,
fg: Rgb,
) -> u16
pub fn print_cut( &mut self, x: i32, y: i32, width: usize, text: &str, fg: Rgb, ) -> u16
Prints text in fg from (x, y) in at most width cells,
cut if it is longer, keeping each cell’s background: a
print_fg of cut. Returns how many cells
were written.
use shuyi_ui::frame::{Cell, GlyphBuffer, Rgb};
let (white, black) = (Rgb::new(255, 255, 255), Rgb::new(0, 0, 0));
let mut buf = GlyphBuffer::new(8, 1, Cell::new('.', white, black));
buf.print_cut(0, 0, 5, "Backspace", white);
let row: String = (0..8).map(|x| buf.get(x, 0).unwrap().glyph).collect();
assert_eq!(row, "Back…...");Source§impl GlyphBuffer
impl GlyphBuffer
Sourcepub fn new(width: u16, height: u16, fill: Cell) -> GlyphBuffer
pub fn new(width: u16, height: u16, fill: Cell) -> GlyphBuffer
A width × height buffer of 8 × 16-pixel cells
(ConsoleSpec::text) with every cell set to fill. Nothing is
wide in it (with_widths).
Sourcepub fn with_spec(spec: ConsoleSpec, fill: Cell) -> GlyphBuffer
pub fn with_spec(spec: ConsoleSpec, fill: Cell) -> GlyphBuffer
A buffer the size of a spec console, with every cell set to
fill. Nothing is wide in it (with_widths).
Sourcepub fn with_widths(self, widths: CellWidths) -> GlyphBuffer
pub fn with_widths(self, widths: CellWidths) -> GlyphBuffer
The same buffer, printing the characters widths has wide in two
cells: those of the font atlas it is drawn with
(CellWidths::of).
Sourcepub fn set_widths(&mut self, widths: CellWidths)
pub fn set_widths(&mut self, widths: CellWidths)
Prints the characters widths has wide in two cells from now on;
what is already printed stays.
Sourcepub fn widths(&self) -> &CellWidths
pub fn widths(&self) -> &CellWidths
Which characters it prints in two cells: what text drawn into it is
measured with (text_width).
Sourcepub fn text_cells(&self, text: &str) -> i32
pub fn text_cells(&self, text: &str) -> i32
How many cells text takes here (text_width with
widths), as an i32 for a position (saturated).
Sourcepub fn spec(&self) -> ConsoleSpec
pub fn spec(&self) -> ConsoleSpec
Its size in cells and the size of a cell, in pixels.
Sourcepub fn backdrop(&self) -> Option<&Backdrop>
pub fn backdrop(&self) -> Option<&Backdrop>
The scene shown behind the see-through cells, if one is set.
Sourcepub fn set_backdrop(
&mut self,
scene: Rc<GlyphBuffer>,
clip: Rect,
origin_px: (f32, f32),
zoom: u8,
)
pub fn set_backdrop( &mut self, scene: Rc<GlyphBuffer>, clip: Rect, origin_px: (f32, f32), zoom: u8, )
Shows scene behind the see-through cells of clip (console
cells, clipped to the buffer), replacing any backdrop already set:
the scene pixel origin_px is at the top-left of clip, and each
scene pixel is zoom console pixels big (1 to MAX_ZOOM; other
values are clamped). A clip wholly outside the buffer (or empty)
removes the backdrop. A backdrop scene has of its own is not drawn.
Sourcepub fn pictures(&self) -> &PaintedTable
pub fn pictures(&self) -> &PaintedTable
The pictures skins paint (ADR-0078), which its painted items show.
Sourcepub fn pictures_mut(&mut self) -> &mut PaintedTable
pub fn pictures_mut(&mut self) -> &mut PaintedTable
The pictures to paint: what a skin writes a picture’s pixels in
before it places it (add_painted). Drawing
the buffer again keeps them.
Sourcepub fn clear_backdrop(&mut self)
pub fn clear_backdrop(&mut self)
Removes the backdrop.
Sourcepub fn pixel_bounds(&self) -> Rect
pub fn pixel_bounds(&self) -> Rect
The whole buffer in console pixels.
Sourcepub fn items(&self) -> &[Item]
pub fn items(&self) -> &[Item]
The rectangles and sprites, in drawing order (within a layer, later ones on top).
Sourcepub fn painted_sprites(&self) -> Vec<PaintedSprite>
pub fn painted_sprites(&self) -> Vec<PaintedSprite>
Only the painted pictures’ items, in drawing order.
Sourcepub fn add_overlay(&mut self, overlay: Overlay)
pub fn add_overlay(&mut self, overlay: Overlay)
Adds overlay, clipped to the buffer; one wholly outside (or empty)
is dropped.
Sourcepub fn add_sprite(&mut self, sprite: Sprite)
pub fn add_sprite(&mut self, sprite: Sprite)
Adds sprite with its clip clipped to its dest and to the
buffer; src and dest are kept as given. One with nothing to show
(wholly outside, or an empty src, dest or clip) is dropped.
Sourcepub fn add_painted(&mut self, painted: PaintedSprite)
pub fn add_painted(&mut self, painted: PaintedSprite)
Adds painted with its clip clipped to its dest and to the
buffer, as add_sprite does; one with nothing
to show is dropped. Its picture is looked up in
pictures when the frame is drawn: write it
before or after, but in the same frame.
Sourcepub fn add_gizmo(&mut self, gizmo: GizmoItem)
pub fn add_gizmo(&mut self, gizmo: GizmoItem)
Adds gizmo over everything drawn so far, its clip clipped to its
shape’s bounds (but a label’s, which is the
cells it was printed in) and to the buffer; one with nothing to show
is dropped.
Sourcepub fn get(&self, x: i32, y: i32) -> Option<&Cell>
pub fn get(&self, x: i32, y: i32) -> Option<&Cell>
The cell at (x, y), or None if out of bounds.
Sourcepub fn set(&mut self, x: i32, y: i32, cell: Cell)
pub fn set(&mut self, x: i32, y: i32, cell: Cell)
Sets the cell at (x, y); out of bounds is silently ignored. A wide
character’s other half, if this was one, becomes a space.
Sourcepub fn print(&mut self, x: i32, y: i32, text: &str, fg: Rgb, bg: Rgb) -> u16
pub fn print(&mut self, x: i32, y: i32, text: &str, fg: Rgb, bg: Rgb) -> u16
Writes text left to right from (x, y), clipped to the buffer:
one char per cell, and a wide one (widths) in
two, its second a continuation in the same colours. A no-break
space (NO_BREAK_SPACE) is written as a space. A wide one
that the buffer’s edge would cut isn’t drawn. Returns how many
cells were written.
Sourcepub fn print_fg(&mut self, x: i32, y: i32, text: &str, fg: Rgb) -> u16
pub fn print_fg(&mut self, x: i32, y: i32, text: &str, fg: Rgb) -> u16
Like print but keeps each cell’s background.
Sourcepub fn glyphs(&self) -> impl Iterator<Item = (i32, i32, &Cell, bool)>
pub fn glyphs(&self) -> impl Iterator<Item = (i32, i32, &Cell, bool)>
Each cell’s glyph as a renderer draws it, row by row: (x, y, cell, wide), where wide says it is drawn over this cell and the next
(the continuation of a wide character). Continuations are left out.
Sourcepub fn fill_rect(&mut self, rect: Rect, cell: Cell)
pub fn fill_rect(&mut self, rect: Rect, cell: Cell)
Sets every cell of rect to cell, removing the parts of items
(rectangles and sprites) over it. Filling the whole buffer with a
solid cell (how a frame is cleared) also removes the backdrop.
Sourcepub fn draw_box(&mut self, rect: Rect, style: BoxStyle, fg: Rgb, bg: Rgb)
pub fn draw_box(&mut self, rect: Rect, style: BoxStyle, fg: Rgb, bg: Rgb)
Draws the border of rect in style; the interior is untouched.
Sourcepub fn blend_bg(&mut self, rect: Rect, color: Rgb, t: f32)
pub fn blend_bg(&mut self, rect: Rect, color: Rgb, t: f32)
Tints the background of every cell in rect towards color by t
(0 = unchanged, 1 = color); used for range overlays.
Sourcepub fn dim(&mut self, rect: Rect, factor: f32)
pub fn dim(&mut self, rect: Rect, factor: f32)
Scales foreground and background of every cell in rect by factor
(e.g. to dim an inactive portrait). Cells only: rectangles and
sprites over them are not touched (a sprite is dimmed by its
opacity).
Sourcepub fn fade(&mut self, brightness: f32)
pub fn fade(&mut self, brightness: f32)
Darkens the whole frame towards black by brightness (1 = as it
is, 0 = black; clamped, and not a number counts as 1): every cell’s
colours, every rectangle’s colour, every sprite’s brightness, and
the backdrop’s scene the same way. Unlike dim it
leaves nothing out (game ADR-0060, game ADR-0075).
Sourcepub fn blit(&mut self, other: &GlyphBuffer, dest_x: i32, dest_y: i32)
pub fn blit(&mut self, other: &GlyphBuffer, dest_x: i32, dest_y: i32)
Copies all of other so its top-left lands at (dest_x, dest_y),
clipped to this buffer. Items already over the copied area are
removed, and other’s items come along, offset and clipped (a
sprite’s dest moves with it, its clip is clipped). Both buffers
have cells of the same size. A wide character comes whole or not
at all: one this buffer’s edge cuts becomes a space.
Source§impl GlyphBuffer
impl GlyphBuffer
Sourcepub fn to_snapshot(&self, palette: &Palette) -> String
pub fn to_snapshot(&self, palette: &Palette) -> String
Renders the buffer in the snapshot format described in crate::frame::snapshot.
Trait Implementations§
Source§impl Clone for GlyphBuffer
impl Clone for GlyphBuffer
Source§fn clone(&self) -> GlyphBuffer
fn clone(&self) -> GlyphBuffer
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more