Skip to content

IGuiTexture

Since 2.2.1

IGuiTexture is the base interface for all drawable textures in LDLib2. Every style property that accepts visual appearance (e.g. background, focus-overlay, mark-background) takes an IGuiTexture.

All registered texture implementations are part of the ldlib2:gui_texture registry and can be serialised, edited in the UI editor, and used in LSS.


Built-in Constants

ConstantDescription
IGuiTexture.EMPTYNo-op — draws nothing. Use this to remove a texture without passing null.
IGuiTexture.MISSING_TEXTURERenders the vanilla missing-texture checkerboard. Used as a fallback when a resource cannot be resolved.

TransformTexture

Most concrete texture types extend the abstract TransformTexture, which wraps a Transform2D applied to every draw call. All TransformTexture subclasses inherit these fluent methods:

MethodDescription
rotate(float degree)Rotates around the texture centre by degree degrees.
scale(float scale)Scales uniformly around the centre.
scale(float width, float height)Scales independently on each axis.
transform(float xOffset, float yOffset)Translates by the given offset in GUI pixels.
setColor(int argb)Tints the texture. Exact effect depends on subtype.
java
IGuiTexture tex = SpriteTexture.of("mymod:textures/gui/icon.png")
    .rotate(45f)
    .scale(0.8f)
    .setColor(0x80FFFFFF); // 50 % opacity white tint

Interface Methods

MethodReturnsDescription
setColor(int)IGuiTextureTints the texture. No-op on the interface; overridden by concrete types.
rotate(float)IGuiTextureRotates the texture. No-op on the interface; overridden by TransformTexture.
scale(float)IGuiTextureScales the texture. No-op on the interface; overridden by TransformTexture.
transform(int, int)IGuiTextureTranslates the texture. No-op on the interface; overridden by TransformTexture.
getRawTexture()IGuiTextureReturns the underlying texture, unwrapping any proxy (e.g. DynamicTexture).
copy()IGuiTextureCreates a deep copy via the codec.
interpolate(IGuiTexture, float)IGuiTextureBlends this texture with another. lerp = 0 is this, lerp = 1 is other. Natively supported by ColorRectTexture, RectTexture, SDFRectTexture, and ColorBorderTexture.

Static Factory Helpers

java
// Layer multiple textures (drawn in order)
IGuiTexture layered = IGuiTexture.group(background, overlay);

// Lazy / dynamic texture resolved every frame
IGuiTexture dynamic = IGuiTexture.dynamic(() -> currentTexture);

Registered Texture Types

Registry nameClassLSS functionDescription
color_rect_textureColorRectTexturecolor(#RGBA) or hex literalSolid-fill rectangle.
color_border_textureColorBorderTextureborder(size, #RGBA)Border-only rectangle (no fill).
sdf_rect_textureSDFRectTexturerect(color, radius?, stroke?, borderColor?)GPU SDF rounded rect with optional stroke.
rect_textureRectTextureCPU-rendered rounded rect (no shader required).
sprite_textureSpriteTexturesprite(path, ...)PNG image with optional 9-slice and wrap mode.
vanilla_sprite_textureVanillaSpriteTexturevanilla-sprite(id)Registered vanilla GUI atlas sprite.
text_textureTextTextureRendered text with scrolling modes.
animation_textureAnimationTextureSprite-sheet frame animation.
item_stack_textureItemStackTextureOne or more ItemStacks cycling every 20 ticks.
fluid_stack_textureFluidStackTextureOne or more fluids cycling every 20 ticks.
group_textureGuiTextureGroupgroup(...)Ordered stack of textures drawn together.
shader_textureShaderTextureshader(location)Custom GLSL shader with automatic GUI uniforms.
ui_resource_textureUIResourceTexturebuiltin(name) / file(...)References a texture saved in the editor resource system.

LSS Reference

Textures are used as values in LSS properties. See Texture in LSS for the complete syntax including rect(), sprite(), group(), and transform chains.

css
button {
    background: rect(#3a3a3a, 4);
    hover-background: rect(#4a4a4a, 4, 1, #FFFFFF66);
}

Released under the MIT License.