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, x: f32, y: f32, color: u32, shadow: bool)

Draw a text string at GUI position (x, y). color is 0xAARRGGBB. shadow adds a drop-shadow.

Source

pub fn text_font( &self, text: &str, font: &str, x: f32, y: f32, color: u32, shadow: bool, )

Self::text in the font font ("minecraft:uniform", a resource-pack font id, …; empty or "minecraft:default" = the default font).

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, x1: f32, y1: f32, x2: f32, y2: f32, color: u32)

Fill a rectangle with a flat color (0xAARRGGBB).

Source

pub fn gradient( &self, x1: f32, y1: f32, x2: f32, y2: f32, top: u32, bottom: u32, )

Fill a rectangle with a vertical gradient (top → bottom, 0xAARRGGBB).

Source

pub fn item(&self, id: &str, x: f32, y: f32, size: f32)

Render an item stack (3D block models included) via Minecraft’s item renderer — like inventory slots or Patchouli’s item icons.

  • id: item registry id, e.g. "minecraft:crafting_table"
  • (x, y): screen position in GUI pixels
  • size: on-screen size in GUI pixels (16 = inventory icon size)
Source

pub fn image(&self, source: &str, x: f32, y: f32, w: f32, h: f32)

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

Source

pub fn image_region( &self, source: &str, x: f32, y: f32, w: f32, h: f32, region: [f32; 4], tint: u32, )

Self::image drawing only region ([u, v, w, h] in the image’s own pixels; all zero = the whole image) multiplied by tint (0xAARRGGBB, 0xFFFFFFFF = none). Items and sprites are always drawn whole, and items ignore the tint.

Source

pub fn svg(&self, data: &str, x: f32, y: f32, w: f32, h: f32)

Draws the SVG document data scaled into (x, y, w, h) (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, x: f32, y: f32, scale: f32, color: u32, shadow: bool, )

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

Source

pub fn blocks( &self, blocks: &[((i32, i32, i32), &str)], x: f32, y: f32, w: f32, h: f32, yaw: f32, pitch: f32, )

Draws blocks in 3D, as big as fits in (x, y, w, h) — 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, x: f32, y: f32, w: f32, h: f32, yaw: f32, pitch: f32, )

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

Source

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

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.