Skip to main content

GlyphBuffer

Struct GlyphBuffer 

Source
pub struct GlyphBuffer { /* private fields */ }
Expand description

A grid of Cells, row-major.

Implementations§

Source§

impl GlyphBuffer

Source

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 ───┐");
Source

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, "██████░░░░");
Source

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..");
Source

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

Source

pub fn new(width: u16, height: u16, fill: Cell) -> Self

A width × height buffer of 8 × 16-pixel cells (ConsoleSpec::text) with every cell set to fill. Nothing is wide in it (with_widths).

Source

pub fn with_spec(spec: ConsoleSpec, fill: Cell) -> Self

A buffer the size of a spec console, with every cell set to fill. Nothing is wide in it (with_widths).

Source

pub fn with_widths(self, widths: CellWidths) -> Self

The same buffer, printing the characters widths has wide in two cells: those of the font atlas it is drawn with (CellWidths::of).

Source

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.

Source

pub fn widths(&self) -> &CellWidths

Which characters it prints in two cells: what text drawn into it is measured with (text_width).

Source

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).

Source

pub fn spec(&self) -> ConsoleSpec

Its size in cells and the size of a cell, in pixels.

Source

pub fn backdrop(&self) -> Option<&Backdrop>

The scene shown behind the see-through cells, if one is set.

Source

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.

Source

pub fn pictures(&self) -> &PaintedTable

The pictures skins paint (ADR-0078), which its painted items show.

Source

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.

Source

pub fn clear_backdrop(&mut self)

Removes the backdrop.

Source

pub fn pixel_bounds(&self) -> PxRect

The whole buffer in console pixels.

Source

pub fn items(&self) -> &[Item]

The rectangles and sprites, in drawing order (within a layer, later ones on top).

Source

pub fn overlays(&self) -> Vec<Overlay>

Only the rectangles, in drawing order.

Source

pub fn sprites(&self) -> Vec<Sprite>

Only the sprites, in drawing order.

Source

pub fn painted_sprites(&self) -> Vec<PaintedSprite>

Only the painted pictures’ items, in drawing order.

Source

pub fn add_overlay(&mut self, overlay: Overlay)

Adds overlay, clipped to the buffer; one wholly outside (or empty) is dropped.

Source

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.

Source

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.

Source

pub fn gizmos(&self) -> Vec<GizmoItem>

The debug view’s gizmos, in drawing order.

Source

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.

Source

pub fn width(&self) -> u16

Width in cells.

Source

pub fn height(&self) -> u16

Height in cells.

Source

pub fn bounds(&self) -> Rect

The whole buffer as a rectangle.

Source

pub fn get(&self, x: i32, y: i32) -> Option<&Cell>

The cell at (x, y), or None if out of bounds.

Source

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.

Source

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.

Source

pub fn print_fg(&mut self, x: i32, y: i32, text: &str, fg: Rgb) -> u16

Like print but keeps each cell’s background.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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).

Source

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).

Source

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

Source

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

Source§

fn clone(&self) -> GlyphBuffer

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for GlyphBuffer

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl PartialEq for GlyphBuffer

Source§

fn eq(&self, other: &GlyphBuffer) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for GlyphBuffer

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.