Skip to main content

Draw2D

Struct Draw2D 

Source
pub struct Draw2D<'ctx>(/* private fields */);
Expand description

2D drawing helpers, valid only within on_hud_render.

Obtain via GfxContext::draw2d.

Implementations§

Source§

impl<'ctx> Draw2D<'ctx>

Source

pub fn text(&self, text: &str, at: Vec2, color: Color, shadow: bool)

Draws text at GUI position at, a drop shadow under it if shadow.

Source

pub fn text_font( &self, text: &str, font: &str, at: Vec2, color: Color, shadow: bool, )

Self::text in the font font (empty: the default one).

Source

pub fn text_width(&self, text: &str, font: &str) -> f32

Width in GUI pixels of text in font (empty = default), measured by the host’s text renderer.

Source

pub fn rect(&self, r: Rect, color: Color)

Fills r with a flat colour.

Source

pub fn gradient(&self, r: Rect, top: Color, bottom: Color)

Fills r with a vertical gradient, top to bottom.

Source

pub fn item(&self, id: &str, at: Vec2, size: f32)

Renders an item stack (3D block models included) via Minecraft’s item renderer — like inventory slots or Patchouli’s item icons: item id (minecraft:crafting_table) at at, size GUI pixels big (16 = an inventory icon).

Source

pub fn image(&self, source: &str, r: Rect)

Draws the image source — a Yog image source such as "item:apple", "block:stone", "sprite:button" or "mymod:gui/logo" (see crate::image) — scaled into r. The host resolves it for its Minecraft version.

Source

pub fn image_region( &self, source: &str, r: Rect, region: Option<Rect>, tint: Color, )

Self::image drawing only region of it (in the image’s own pixels; None = all of it) multiplied by tint (white = none). Items and sprites are always drawn whole, and items ignore the tint.

Source

pub fn svg(&self, data: &str, r: Rect)

Draws the SVG document data scaled into r (sharp at any GUI scale: the host rasterizes it at the screen’s resolution). An .svg file is an image source like any other — mymod:gui/logo.svg — for Self::image.

Source

pub fn text_scaled( &self, text: &str, font: &str, at: Vec2, scale: f32, color: Color, shadow: bool, )

Self::text_font scale times its size (1 = the font’s own).

Source

pub fn blocks( &self, blocks: &[((i32, i32, i32), &str)], r: Rect, yaw: f32, pitch: f32, )

Draws blocks in 3D, as big as fits in r — a multiblock structure, a block on display: each is ((x, y, z), state) with a full block state (minecraft:furnace[facing=north]), turned yaw degrees about the vertical and tilted pitch degrees toward the viewer (30 looks down on it like Patchouli does).

Source

pub fn entity(&self, entity: &str, r: Rect, yaw: f32, pitch: f32)

Draws a living entity of type entity (minecraft:zombie, mymod:wisp) standing in r, as big as fits, turned yaw degrees (0 = facing the viewer) and tilted pitch degrees.

Source

pub fn image_size(&self, source: &str) -> Option<Vec2>

Natural size in GUI pixels of the image source (None if the host can’t resolve it).

Auto Trait Implementations§

§

impl<'ctx> Freeze for Draw2D<'ctx>

§

impl<'ctx> RefUnwindSafe for Draw2D<'ctx>

§

impl<'ctx> Send for Draw2D<'ctx>

§

impl<'ctx> Sync for Draw2D<'ctx>

§

impl<'ctx> Unpin for Draw2D<'ctx>

§

impl<'ctx> UnsafeUnpin for Draw2D<'ctx>

§

impl<'ctx> UnwindSafe for Draw2D<'ctx>

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> ArchivePointee for T

Source§

type ArchivedMetadata = ()

The archived version of the pointer metadata for this type.
Source§

fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata, ) -> <T as Pointee>::Metadata

Converts some archived metadata to the pointer metadata for itself.
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> 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> LayoutRaw for T

Source§

fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>

Returns the layout of the type.
Source§

impl<T, N1, N2> Niching<NichedOption<T, N1>> for N2
where T: SharedNiching<N1, N2>, N1: Niching<T>, N2: Niching<T>,

Source§

unsafe fn is_niched(niched: *const NichedOption<T, N1>) -> bool

Returns whether the given value has been niched. Read more
Source§

fn resolve_niched(out: Place<NichedOption<T, N1>>)

Writes data to out indicating that a T is niched.
Source§

impl<T> Pointee for T

Source§

type Metadata = ()

The metadata type for pointers and references to this type.
Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.