pubdata

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2023 License: BSD-3-Clause Imports: 5 Imported by: 0

Documentation

Overview

package pubdata intended for exporting data structure for other platforms such as mobile, wasm and so on. All of type of exported struct field and function signature should be restricted by the restriction of platform conversion. e.g. mobile type restrinction is found at https://pkg.go.dev/golang.org/x/mobile/cmd/gobind?utm_source=godoc#hdr-Type_restrictions

Index

Constants

View Source
const (
	ContentTypeText       = "text"
	ContentTypeTextButton = "text_button"
	ContentTypeImage      = "image"
)
View Source
const (
	AlignmentNone   = "none"
	AlignmentLeft   = "left"
	AlignmentCenter = "center"
	AlignmentRight  = "right"
)

Variables

This section is empty.

Functions

func AlignmentString

func AlignmentString(align attribute.Alignment) string

Types

type Box

type Box interface {
	RuneWidth() int      // return box's width in runewidth.
	ContentType() string // return box's content type

	BoxDataUnion // BoxDataUnion is interface for getting data depending on box type.
}

Box is abstract content. It holds nomal text, unsplitable text and images and so on. The Box is the smallest element for whole content. The whole content consist with multiple Paragraph-s, which is divided by the hard return (\n). Paragraph consist with multiple Line-s, which is divided by rune width in the maximum width in the view window. The Line consists with multiple Box-s, which is divided by its attributes.

The Box type can be validated by type assertion or ContentType().

type BoxCommon

type BoxCommon struct {
	CommonRuneWidth     int    `json:"rune_width"`
	CommonLineCountHint int    `json:"line_count_hint"`
	CommonContentType   string `json:"content_type"`

	// Implement BoxDataUnion interface.
	BoxDataUnionImpl
}

BoxCommon implements Box interface. Data() should be implemented by the derived types.

func (*BoxCommon) ContentType

func (b *BoxCommon) ContentType() string

func (*BoxCommon) LineCountHint

func (b *BoxCommon) LineCountHint() int

func (*BoxCommon) RuneWidth

func (b *BoxCommon) RuneWidth() int

type BoxDataUnion

type BoxDataUnion interface {
	TextData() *TextData
	TextButtonData() *TextButtonData
	ImageData() *ImageData
}

BoxDataUnion is a union data structure for Box implementers.

type BoxDataUnionImpl

type BoxDataUnionImpl struct{}

BoxDataUnionImpl implements BoxDataUnion interface.

func (BoxDataUnionImpl) ImageData

func (BoxDataUnionImpl) ImageData() *ImageData

func (BoxDataUnionImpl) TextButtonData

func (BoxDataUnionImpl) TextButtonData() *TextButtonData

func (BoxDataUnionImpl) TextData

func (BoxDataUnionImpl) TextData() *TextData

type Boxes

type Boxes struct {
	// contains filtered or unexported fields
}

Boxes is intermediation for []Box, used for gomobile export.

func NewBoxes

func NewBoxes(boxes []Box) Boxes

func (Boxes) Get

func (bs Boxes) Get(i int) Box

Get() returns a Box at index i, like Boxes[i].

func (Boxes) Len

func (bs Boxes) Len() int

Len() returns length of array.

func (Boxes) MarshalJSON

func (bs Boxes) MarshalJSON() ([]byte, error)

Implement json.Mashaller interface. Unmarshal is not considered.

func (*Boxes) UnmarshalJSON

func (bs *Boxes) UnmarshalJSON(b []byte) error

Implement json.Unmarshller interface.

type ImageBox

type ImageBox struct {
	BoxCommon
	BoxData ImageData `json:"data"`
}

ImageBox holds image data.

func (*ImageBox) ImageData

func (t *ImageBox) ImageData() *ImageData

TextButtonData returns *TextButtonData.

type ImageData

type ImageData struct {
	Source          string `json:"source"`
	WidthPx         int    `json:"width_px"`
	HeightPx        int    `json:"height_px"`
	WidthTextScale  int    `json:"width_text_scale"`
	HeightTextScale int    `json:"height_text_scale"`

	Data          []byte         `json:"data"`
	DataFetchType ImageFetchType `json:"data_fetch_type"`
}

ImageData is data for ContentTypeImage.

type ImageFetchType

type ImageFetchType = int

ImageFetchType indicates how image pixels to be included in ImageData.Data. This type is aliases for int since it may be encoded to the json format.

const (
	// ImageFetchNone indicates no image pixel data in ImageData.
	// Client use URI of image to fetch pixels manually.
	ImageFetchNone ImageFetchType = iota
	// ImageFetchRawRGBA indicates image pixels stored in raw RGBA bytes in
	// ImageData.
	ImageFetchRawRGBA
	// ImageFetchEncodedPNG indicates image pixels stored in png encoded bytes in
	// ImageData.
	ImageFetchEncodedPNG
)

type Line

type Line struct {
	Boxes     Boxes `json:"boxes"`
	RuneWidth int   `json:"rune_width"` // rune width for this line, that is sum of one in boxes.
}

Line is a line in view window.

type Lines

type Lines struct {
	// contains filtered or unexported fields
}

Lines is intermediation for []Line, used for gomobile export.

func NewLines

func NewLines(lines []Line) Lines

func (Lines) Get

func (ls Lines) Get(i int) Line

Get() returns a Line at index i, like Lines[i].

func (Lines) Len

func (ls Lines) Len() int

Len() returns length of array.

func (Lines) MarshalJSON

func (ls Lines) MarshalJSON() ([]byte, error)

Implement json.Mashaller interface. Unmarshal is not considered.

func (*Lines) UnmarshalJSON

func (ls *Lines) UnmarshalJSON(b []byte) error

Implement json.Unmarshller interface.

type Paragraph

type Paragraph struct {
	ID        int    `json:"id"`
	Lines     Lines  `json:"lines"`
	Alignment string `json:"alignment"`
	Fixed     bool   `json:"fixed"`
}

Paragraph is a block of content divided by hard return (\n).

type TextBox

type TextBox struct {
	BoxCommon
	BoxData TextData `json:"data"`
}

TextBox represents normal text.

func (*TextBox) TextData

func (t *TextBox) TextData() *TextData

TextData returns *TextData.

type TextButtonBox

type TextButtonBox struct {
	BoxCommon
	BoxData TextButtonData `json:"data"`
}

TextBottonBox holds normal text and emits input command when this box is tapped/clicked on UI.

func (*TextButtonBox) TextButtonData

func (t *TextButtonBox) TextButtonData() *TextButtonData

TextButtonData returns *TextButtonData.

type TextButtonData

type TextButtonData struct {
	TextData
	Command string `json:"command"`
}

TextButtonData is data for ContentTypeTextButton.

type TextData

type TextData struct {
	// text content should not contain hard return.
	Text string `json:"text"`
	// Foreground color represents 32bit RGB used to font face color
	FgColor int `json:"fgcolor"`
	// Background color represents 32bit RGB used to background on text.
	BgColor int `json:"bgcolor"`
}

TextData is data for ContentTypeText.

Jump to

Keyboard shortcuts

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