ninepatch

package
v0.0.0-...-69d9917 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 14, 2023 License: MIT, Unlicense Imports: 10 Imported by: 0

Documentation

Overview

Package ninepatch implements 9-Patch image rendering in Gio. https://developer.android.com/guide/topics/graphics/drawables#nine-patch

Index

Constants

View Source
const DefaultScale = 1 / float32(160.0/72.0)

DefaultScale is a standard 72 DPI. Inverse of `widget.Image`, shrink as the screen becomes _less_ dense.

Variables

This section is empty.

Functions

This section is empty.

Types

type C

type C = layout.Context

type D

type D = layout.Dimensions

type Grid

type Grid struct {
	// Size specifies the total dimensions including static and stretch regions.
	Size image.Point
	// X1 is the distance in pixels before the stretchable region along the X axis.
	// X2 is the distance in pixels after the stretchable region along the X axis.
	X1, X2 int
	// Y1 is the distance in pixels before the stretchable region along the Y axis.
	// Y2 is the distance in pixels after the stretchable region along the Y axis.
	Y1, Y2 int
}

Grid describes the stretchable regions of a 9-Patch as 3x3 grid divided by 4 lines.

func (Grid) Static

func (g Grid) Static() image.Point

Static returns the statically known dimensions (the corners).

func (Grid) Stretch

func (g Grid) Stretch() image.Point

Stretch returns the stretch dimensions (the space between the corners).

type NinePatch

type NinePatch struct {
	// Image is the backing image of the 9-Patch.
	image.Image
	// Grid describes the stretchable regions of the 9-Patch.
	Grid Grid
	// Inset describes content insets defined by the black lines on the bottom
	// and right of the 9-Patch image.
	Content PxInset
	// contains filtered or unexported fields
}

NinePatch can lay out a 9-Patch image as the background for another widget.

Note: create a new instance per 9-Patch image. Changing the image.Image after the first layout will have no effect because the paint.ImageOp is cached.

func DecodeNinePatch

func DecodeNinePatch(src image.Image) NinePatch

DecodeNinePatch from source image.

Note: Any colored pixel around the border will be considered a 9-Patch marker.

func (NinePatch) Layout

func (n NinePatch) Layout(gtx C, w layout.Widget) D

Layout the provided widget with the NinePatch as a background.

type Patch

type Patch struct {
	Offset image.Point
	Size   image.Point
}

Patch describes the position and size of single patch in a 9-Patch image.

type PxInset

type PxInset struct {
	Top, Bottom, Left, Right int
}

PxInset describes an inset in pixels.

func (PxInset) ToDp

func (p PxInset) ToDp(m unit.Metric) layout.Inset

type Region

type Region struct {
	// Source is the patch relative to the source image.
	Source Patch
	// Stretched is the patch relative to the layout.
	Stretched Patch
}

Region describes how to lay out a particular patch of a 9-Patch image.

func (Region) Layout

func (r Region) Layout(gtx C, src paint.ImageOp) D

Layout the patch of the provided ImageOp described by the Region, scaling as needed.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL