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, x: f32, y: f32, color: u32, shadow: bool)
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.
Sourcepub fn text_font(
&self,
text: &str,
font: &str,
x: f32,
y: f32,
color: u32,
shadow: bool,
)
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).
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 rect(&self, x1: f32, y1: f32, x2: f32, y2: f32, color: u32)
pub fn rect(&self, x1: f32, y1: f32, x2: f32, y2: f32, color: u32)
Fill a rectangle with a flat color (0xAARRGGBB).
Sourcepub fn gradient(
&self,
x1: f32,
y1: f32,
x2: f32,
y2: f32,
top: u32,
bottom: u32,
)
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).
Sourcepub fn mc_texture(
&self,
id: &str,
x: f32,
y: f32,
u0: f32,
v0: f32,
w: f32,
h: f32,
tw: f32,
th: f32,
)
pub fn mc_texture( &self, id: &str, x: f32, y: f32, u0: f32, v0: f32, w: f32, h: f32, tw: f32, th: f32, )
Blit a region from a Minecraft texture identified by namespace + path.
id: e.g."minecraft:textures/gui/icons.png"(x, y): screen position(u0, v0): top-left UV in texels(w, h): region size in pixels(tw, th): full texture size in pixels
Sourcepub fn item(&self, id: &str, x: f32, y: f32, size: f32)
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 pixelssize: on-screen size in GUI pixels (16 = inventory icon size)
Sourcepub fn image(&self, source: &str, x: f32, y: f32, w: f32, h: f32)
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; prefer this over Self::mc_texture.
Sourcepub fn image_region(
&self,
source: &str,
x: f32,
y: f32,
w: f32,
h: f32,
region: [f32; 4],
tint: u32,
)
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.
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.