Trait DrawContext
pub trait DrawContext {
Show 19 methods
// Provided methods
fn size(&self) -> [f32; 2] { ... }
fn item_model(
&mut self,
item: ItemKey,
model: &str,
at: [f32; 2],
size: f32,
) -> bool { ... }
fn quad(&mut self, points: [[f32; 2]; 4], argb: u32) { ... }
fn fill(&mut self, rect: [f32; 4], argb: u32) { ... }
fn sprite(
&mut self,
name: &str,
src: [f32; 4],
dst: [f32; 4],
tint: Option<u32>,
) -> bool { ... }
fn item(&mut self, item: ItemKey, at: [f32; 2], size: f32) -> bool { ... }
fn text(&mut self, text: &str, at: [f32; 2], argb: u32, shadow: bool) { ... }
fn item_stack(&mut self, stack: &ItemStack, at: [f32; 2], size: f32) -> bool { ... }
fn gui_paint(&mut self, draws: &[GuiDraw]) -> Result<(), TextFormError> { ... }
fn gui_nine_slice(&mut self, sprite: &str, rect: [f32; 4], color: u32) { ... }
fn gui_tooltip(
&mut self,
lines: &[Text],
at: [f32; 2],
) -> Result<(), TextFormError> { ... }
fn text_width(&self, text: &str) -> f32 { ... }
fn fluid(&mut self, fluid: &str, at: [f32; 2], size: f32) { ... }
fn draw_scene(
&mut self,
rect: [f32; 4],
blocks: &[SceneBlock],
view: SceneView,
) { ... }
fn draw_menu_background(&mut self, rect: [f32; 4], in_world: bool) { ... }
fn tiled_sprite(
&mut self,
sprite: &str,
rect: [f32; 4],
size: f32,
argb: u32,
) -> bool { ... }
fn gui_draw_item_with(
&mut self,
stack: &ItemStack,
at: [f32; 2],
text: Option<&str>,
) { ... }
fn widget_button(
&mut self,
rect: [f32; 4],
label: &Text,
active: bool,
highlighted: bool,
) -> Result<(), TextFormError> { ... }
fn widget_text_field(&mut self, field: &TextFieldView) -> TextFieldLayout { ... }
}Expand description
What the HUD, screen and tooltip hooks draw with, in GUI pixels: one per hook call.
Provided Methods§
fn item_model(
&mut self,
item: ItemKey,
model: &str,
at: [f32; 2],
size: f32,
) -> bool
fn item_model( &mut self, item: ItemKey, model: &str, at: [f32; 2], size: f32, ) -> bool
Item item’s icon drawn with model model (minecraft:paper as
mymod:wheel_icon, an item_model of a content mod’s), as native_item
draws one; false for an unknown item.
fn quad(&mut self, points: [[f32; 2]; 4], argb: u32)
fn quad(&mut self, points: [[f32; 2]; 4], argb: u32)
A quad of corners points (in order round it) in GUI pixels, argb:
a wedge, a slanted bar, what native_fill’s rectangles can’t draw.
fn fill(&mut self, rect: [f32; 4], argb: u32)
fn fill(&mut self, rect: [f32; 4], argb: u32)
A rectangle in GUI pixels, argb (0x78000000 is the extras’ box).
fn sprite(
&mut self,
name: &str,
src: [f32; 4],
dst: [f32; 4],
tint: Option<u32>,
) -> bool
fn sprite( &mut self, name: &str, src: [f32; 4], dst: [f32; 4], tint: Option<u32>, ) -> bool
Part src ([x, y, w, h] in the sprite’s own pixels) of sprite
name (vanilla’s gui/..., or a content mod’s GUI texture
mymod:gui/...), drawn stretched into dst ([x, y, w, h] in GUI
pixels), every texel multiplied by tint (0xAARRGGBB, a fluid’s colour)
when there is one. False when there is no such sprite.
fn item(&mut self, item: ItemKey, at: [f32; 2], size: f32) -> bool
fn item(&mut self, item: ItemKey, at: [f32; 2], size: f32) -> bool
Item item’s icon (mymod:machine) with its top left at at,
size GUI pixels square (16 in a slot); false for an unknown item.
fn text(&mut self, text: &str, at: [f32; 2], argb: u32, shadow: bool)
fn text(&mut self, text: &str, at: [f32; 2], argb: u32, shadow: bool)
A line of text at (x, y) in GUI pixels, in argb as vanilla’s GuiGraphics takes it
(0xFFFFFFFF is opaque white). Fully transparent text draws nothing, as vanilla’s.
fn item_stack(&mut self, stack: &ItemStack, at: [f32; 2], size: f32) -> bool
fn item_stack(&mut self, stack: &ItemStack, at: [f32; 2], size: f32) -> bool
Stack drawing does not enforce resident count or damage maxima. Unknown
item identities or unrepresentable component payloads still refuse drawing.
Draw a stack and its slot decorations, except the count, at at,
size GUI pixels square. False when nothing was drawn: an unknown item
or an empty stack (air, or a count of 0, as ItemStack.isEmpty).
fn gui_paint(&mut self, draws: &[GuiDraw]) -> Result<(), TextFormError>
fn gui_paint(&mut self, draws: &[GuiDraw]) -> Result<(), TextFormError>
Paint GUI extraction calls through this window’s atlas, including player faces. Refuses text deeper than 512 component nodes before applying any changes.
fn gui_nine_slice(&mut self, sprite: &str, rect: [f32; 4], color: u32)
fn gui_nine_slice(&mut self, sprite: &str, rect: [f32; 4], color: u32)
Vanilla’s nine-slice widget rendering. color is ARGB, as fill uses.
fn gui_tooltip(
&mut self,
lines: &[Text],
at: [f32; 2],
) -> Result<(), TextFormError>
fn gui_tooltip( &mut self, lines: &[Text], at: [f32; 2], ) -> Result<(), TextFormError>
A vanilla tooltip at the cursor, in GUI pixels. Refuses text deeper than 512 component nodes before applying any changes.
fn text_width(&self, text: &str) -> f32
fn text_width(&self, text: &str) -> f32
The width of text in GUI pixels, as native_text draws it on draw (Font.width).
fn fluid(&mut self, fluid: &str, at: [f32; 2], size: f32)
fn fluid(&mut self, fluid: &str, at: [f32; 2], size: f32)
Fluid fluid (minecraft:water, mymod:oil) drawn as a square with its top left at at, size
GUI pixels wide (16 in a slot): the sprite its look names (data/<mod>/horizon/fluid/<name>.json)
tinted with its colour, else a flat square of the colour, which vanilla water and lava have. What a
recipe viewer draws for a fluid stack; the slot and the amount are the mod’s.
fn draw_scene(&mut self, rect: [f32; 4], blocks: &[SceneBlock], view: SceneView)
fn draw_scene(&mut self, rect: [f32; 4], blocks: &[SceneBlock], view: SceneView)
Draws blocks, a scene of block states at positions of its own (not
the world’s), into the box rect (x0, y0, x1, y1, GUI pixels) of a
screen’s batch, seen as view says: Create’s Ponder scenes. Each
block is drawn with its model, full bright and shaded by face, a face
against a solid neighbour in the scene left out; a block with an
entity (a mod’s) is drawn by native_block_entity_submit as in the
world too, its spin parts turning with the game time. What lies
outside the box is cut off, and the scene has a depth of its own, so
it never covers the screen’s other drawing or is covered by it but in
the order drawn. Draw it from a screen’s drawing hook
(native_screen_draw). A client’s call; nothing is drawn on a server.
API @API:scenes_in_screens@.
Screen.renderMenuBackground: draws the tiled menu background (32x32) across rect
([x, y, w, h] in GUI pixels). If in_world is true, uses the dark translucent
texture (gui/inworld_menu_background); otherwise uses the opaque dirt-like
texture (gui/menu_background). API @API:screen_transparent_background@.
fn tiled_sprite(
&mut self,
sprite: &str,
rect: [f32; 4],
size: f32,
argb: u32,
) -> bool
fn tiled_sprite( &mut self, sprite: &str, rect: [f32; 4], size: f32, argb: u32, ) -> bool
Repeats sprite sprite across rect ([x, y, w, h] in GUI pixels) with each tile
sized size GUI pixels square, tinted by argb. False when the sprite is not in the HUD atlas.
API @API:screen_transparent_background@.
fn gui_draw_item_with(
&mut self,
stack: &ItemStack,
at: [f32; 2],
text: Option<&str>,
)
fn gui_draw_item_with( &mut self, stack: &ItemStack, at: [f32; 2], text: Option<&str>, )
Draw an item stack with custom count/decoration text (or None) at at in GUI units.
Uses the same nonresident stack encoding as item_stack, not write validation.
A button as the game’s screens draw one (AbstractButton): label centred on the
widget/button sprite (button_highlighted when highlighted, button_disabled and
grey when not active), scrolling when it doesn’t fit, and recorded for the narrator and
a controller’s focus. rect is [x, y, w, h] in GUI pixels. What
crate::client::widgets::Widgets draws its buttons with.
Refuses text deeper than 512 component nodes before applying any changes.
fn widget_text_field(&mut self, field: &TextFieldView) -> TextFieldLayout
fn widget_text_field(&mut self, field: &TextFieldView) -> TextFieldLayout
A text field as the game’s screens draw one (EditBox): its text from the first
character field.scroll shows, scrolled on to keep the cursor in view, the selection
highlighted, the caret, the suggestion, the widget/text_field sprite when bordered, and
a record for the narrator and a controller’s focus. Answers the scroll it drew with and
the x of each shown character boundary, for the next press. What
crate::client::widgets::Widgets draws its fields with.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".