Trait immi::Draw [] [src]

pub trait Draw {
    type ImageResource: ?Sized;
    type TextStyle: ?Sized;
    fn draw_triangle(
        &mut self,
        texture: &Self::ImageResource,
        matrix: &Matrix,
        uv_coords: [[f32; 2]; 3]
    );
fn get_image_width_per_height(&mut self, name: &Self::ImageResource) -> f32;
fn draw_glyph(
        &mut self,
        text_style: &Self::TextStyle,
        glyph: char,
        matrix: &Matrix
    );
fn line_height(&self, text_style: &Self::TextStyle) -> f32;
fn glyph_infos(
        &self,
        text_style: &Self::TextStyle,
        glyph: char
    ) -> GlyphInfos;
fn kerning(
        &self,
        text_style: &Self::TextStyle,
        first_char: char,
        second_char: char
    ) -> f32; fn draw_image(&mut self, name: &Self::ImageResource, matrix: &Matrix) { ... }
fn draw_image_uv(
        &mut self,
        name: &Self::ImageResource,
        matrix: &Matrix,
        top_left: [f32; 2],
        top_right: [f32; 2],
        bottom_right: [f32; 2],
        bottom_left: [f32; 2]
    ) { ... } }

Trait for a context that can handle drawing.

Associated Types

Type of a resource that represents an image.

Type of a resource that represents the style of a text: its font, color, etc.

Required Methods

Draws a single triangle that covers the top-left hand corner of the surface, pre-multiplied by the matrix.

To do so, draw a triangle whose coordinatges are [-1.0, 1.0], [-1.0, -1.0] and [1.0, 1.0], then pre-muliplty these coordinates with the matrix given as parameter. If you use Vulkan or DirectX, you have to perform an additional step. Pre-multiply that result with a matrix that inverts the y coordinate (ie. an identity matrix but whose value at the second row of the second column is -1.0).

The UV coordinates passed as parameter are respectively the texture coordinates at the top-left, bottom-left and top-right corners. [0.0, 0.0] is the bottom-left hand corner of the texture, and [1.0, 1.0] is the top-right hand corner. If you use OpenGL, you can pass through the values. If you use DirectX or Vulkan, you must do y = 1.0 - y somewhere.

Given an image, this functions returns its width divided by its height.

Does the same as draw_image, but draws a glyph of a text instead.

Returns the height of a line of text in EMs.

This value is usually somewhere around 1.2.

Returns information about a specific glyph.

Returns the kerning between two characters for the given font.

The kerning is an offset to add to the position of a specific character when it follows another specific character. For example when you write To, thanks to kerning the o can slip under the T, which looks nicer than if they were simply next to each other.

A positive value moves the second character further away from the first one, while a negative values moves the second character next to the first one. The value must be a multiple of 1 em. When in doubt, you can simply return 0.0.

Provided Methods

Draws an image that covers the whole surface (from -1.0 to 1.0 both horizontally and vertically), but multiplied by the matrix.

This function should not try to preseve the aspect ratio of the image. This is handled by the caller.

Draws an image that covers the whole surface (from -1.0 to 1.0 both horizontally and vertically), but multiplied by the matrix.

This function should not try to preseve the aspect ratio of the image. This is handled by the caller.

Contrary to draw_image, this library allows one to specify UV coordinates of the four borders. Coordinates [0.0, 0.0] correspond to the bottom-left hand corner of the image, and [1.0, 1.0] correspond to the top-right hand corner.

Implementors