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>
impl<'ctx> Draw2D<'ctx>
Sourcepub fn text(&self, text: &str, at: Vec2, color: Color, shadow: bool)
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.
Sourcepub fn text_font(
&self,
text: &str,
font: &str,
at: Vec2,
color: Color,
shadow: bool,
)
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).
Sourcepub fn text_width(&self, text: &str, font: &str) -> f32
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.
Sourcepub fn gradient(&self, r: Rect, top: Color, bottom: Color)
pub fn gradient(&self, r: Rect, top: Color, bottom: Color)
Fills r with a vertical gradient, top to bottom.
Sourcepub fn item(&self, id: &str, at: Vec2, size: f32)
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).
Sourcepub fn image(&self, source: &str, r: Rect)
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.
Sourcepub fn image_region(
&self,
source: &str,
r: Rect,
region: Option<Rect>,
tint: Color,
)
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.
Sourcepub fn svg(&self, data: &str, r: Rect)
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.
Sourcepub fn text_scaled(
&self,
text: &str,
font: &str,
at: Vec2,
scale: f32,
color: Color,
shadow: bool,
)
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).
Sourcepub fn blocks(
&self,
blocks: &[((i32, i32, i32), &str)],
r: Rect,
yaw: f32,
pitch: f32,
)
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).
Sourcepub fn entity(&self, entity: &str, r: Rect, yaw: f32, pitch: f32)
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.
Sourcepub fn image_size(&self, source: &str) -> Option<Vec2>
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> ArchivePointee for T
impl<T> ArchivePointee for T
Source§type ArchivedMetadata = ()
type ArchivedMetadata = ()
Source§fn pointer_metadata(
_: &<T as ArchivePointee>::ArchivedMetadata,
) -> <T as Pointee>::Metadata
fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata, ) -> <T as Pointee>::Metadata
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> LayoutRaw for T
impl<T> LayoutRaw for T
Source§fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>
fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>
Source§impl<T, N1, N2> Niching<NichedOption<T, N1>> for N2
impl<T, N1, N2> Niching<NichedOption<T, N1>> for N2
Source§unsafe fn is_niched(niched: *const NichedOption<T, N1>) -> bool
unsafe fn is_niched(niched: *const NichedOption<T, N1>) -> bool
Source§fn resolve_niched(out: Place<NichedOption<T, N1>>)
fn resolve_niched(out: Place<NichedOption<T, N1>>)
out indicating that a T is niched.