publisher

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2024 License: BSD-3-Clause Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MessageTypeTask  MessageType = 0
	MessageAsyncTask             = MessageTypeTask + iota // same as MessageTypeTask
	MessageSyncTask
)

Variables

View Source
var DefaultCachedImageSize = text.DefaultCachedImageSize

DefaultCachedImageSize is used as a number of cached images.

View Source
var ErrMessageLooperClosed = errors.New("MessageLooper is closed")

ErrMEssageLooperClosed indicates API call is failed due to MessageLooper is already closed.

View Source
var ResetColor = text.ResetColor

ResetColor is imported from text.ResetColor so that user need not to import text package explicitly.

Functions

func ColorRGBAToInt32RGB

func ColorRGBAToInt32RGB(c color.RGBA) int32

Color RGBA converts from color.RGBA to int32 type RGB color #0xRRGGBB. NOTE: A is not considered

func ColorRGBAToUInt32RGB

func ColorRGBAToUInt32RGB(c color.RGBA) uint32

Color RGBA converts from color.RGBA to uint32 type RGB color #0xRRGGBB. NOTE: A is not considered

func Int32RGBToColorRGBA

func Int32RGBToColorRGBA(c int32) color.RGBA

Int32ColorToColorRGBA converts from int32 type RGB color #0xRRGGBB to color.RGBA NOTE: A is not considered

func UInt32RGBToColorRGBA

func UInt32RGBToColorRGBA(c uint32) color.RGBA

UInt32ColorToColorRGBA converts from uint32 type RGB color #0xRRGGBB to color.RGBA NOTE: A is not considered

Types

type APIError added in v0.9.0

type APIError struct {
	Name string
	Err  error
}

APIError is an error wrapper with API Name.

func (*APIError) As added in v0.9.0

func (e *APIError) As(target any) bool

func (*APIError) Error added in v0.9.0

func (e *APIError) Error() string

Implement error interface.

func (*APIError) Is added in v0.9.0

func (e *APIError) Is(err error) bool

Implement error interface.

func (*APIError) Unwrap added in v0.9.0

func (e *APIError) Unwrap() error

type Callback

type Callback interface {
	// OnPublish is called when Paragraph is fixed by hard return (\n).
	OnPublish(*pubdata.Paragraph) error
	// OnPublishTemporary is called when Paragraph is NOT fixed yet by hard return(\n),
	// but required to show on UI.
	OnPublishTemporary(*pubdata.Paragraph) error
	// OnRemove is called when game thread requests to remove (N-1)-paragraphs which have been fixed
	// by calling OnPublish and also temporal Paragraph by calling OnPublishTemporary, thus to remove N-paragraphs.
	OnRemove(nParagraph int) error
	// OnRemoveAll is called when game thread requests to remove all paragraphs which have been fixed
	// by calling OnPublish and also temporal Paragraph by calling OnPublishTemporary.
	OnRemoveAll() error
}

Callback defines callback interface. If callee somehow no longer handles the callback, return error to notify its status to the caller.

type CallbackDefault

type CallbackDefault struct {
	OnPublishFunc          func(*pubdata.Paragraph) error
	OnPublishTemporaryFunc func(*pubdata.Paragraph) error
	OnRemoveFunc           func(nParagraph int) error
	OnRemoveAllFunc        func() error
}

CallbackDefault implements Callback interface. User can only set override interface functions to its fields. Otherwise the functions not set fields are called to do nothing.

func (*CallbackDefault) OnPublish

func (cb *CallbackDefault) OnPublish(p *pubdata.Paragraph) error

OnPublish is called when Paragraph is fixed by hard return (\n).

func (*CallbackDefault) OnPublishTemporary

func (cb *CallbackDefault) OnPublishTemporary(p *pubdata.Paragraph) error

OnPublishTemporary is called when Paragraph is NOT fixed yet by hard return(\n), but required to show on UI.

func (*CallbackDefault) OnRemove

func (cb *CallbackDefault) OnRemove(nParagraph int) error

OnRemove is called when game thread requests to remove (N-1)-paragraphs which have been fixed by calling OnPublish and also temporal Paragraph by calling OnPublishTemporary, thus to remove N-paragraphs.

func (*CallbackDefault) OnRemoveAll

func (cb *CallbackDefault) OnRemoveAll() error

OnRemoveAll is called when game thread requests to remove all paragraphs which have been fixed by calling OnPublish and also temporal Paragraph by calling OnPublishTemporary.

type Editor

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

Editor edits just one Paragraph It only appends new content into Frame's last.

It is constructed by Frame.Editor(), not NewEditor() or Editor{}

Multiple Editors do not share their states.

func NewEditor

func NewEditor(ctx context.Context, opts ...EditorOptions) *Editor

func (*Editor) ClearLine

func (e *Editor) ClearLine(nline int) error

Clear lines specified number.

func (*Editor) ClearLineAll

func (e *Editor) ClearLineAll() error

Clear all lines containing historys.

func (*Editor) Close

func (e *Editor) Close() error

Close closes editor APIs. After calling this, any editor's API return error which is errors.Is(ErrMessageLooperClosed). This API waits until all of pending tasks are done.

func (*Editor) CurrentRuneWidth

func (e *Editor) CurrentRuneWidth() (int, error)

current rune width in the editting line.

func (*Editor) GetAlignment

func (e *Editor) GetAlignment() (align attribute.Alignment, err error)

func (*Editor) GetColor

func (e *Editor) GetColor() (color uint32, err error)

func (*Editor) LineCount

func (e *Editor) LineCount() (int, error)

line count as it increases at outputting new line.

func (*Editor) MeasureImageSize

func (e *Editor) MeasureImageSize(file string, widthInRW, heightInLC int) (retW, retH int, err error)

Measure Image size in text scale, width in rune-width and height in line-count. This is useful when PrintImage will call with either widthInRW or heightInLC is zero, the drawn image size shall be auto determined but client want to know determined size before calling PrintImage.

func (*Editor) NewPage

func (e *Editor) NewPage() error

skip current lines to display none. TODO: is it needed?

func (*Editor) Print

func (e *Editor) Print(s string) error

Print text to screen. It should implement moving to next line by "\n".

func (*Editor) PrintButton

func (e *Editor) PrintButton(caption string, command string) error

Print Clickable button text. it shows caption on screen and emits command when it is selected. It is no separatable in wrapping text.

func (*Editor) PrintImage

func (e *Editor) PrintImage(file string, widthInRW, heightInLC int) error

Print image from file path. Image is exceptional case, which may draw image region exceed over 1 line.

func (*Editor) PrintLabel

func (e *Editor) PrintLabel(s string) error

Print label text to screen. It should not be separated in wrapping text.

func (*Editor) PrintLine

func (e *Editor) PrintLine(sym string) error

Print Line using sym. given sym #, output line is: ############...

func (*Editor) PrintSpace added in v0.9.0

func (e *Editor) PrintSpace(widthInRW int) error

Print Space in output area. widthInRW is blank space width in runewidth, should be > 0.

func (*Editor) ResetColor

func (e *Editor) ResetColor() error

func (*Editor) SetAlignment

func (e *Editor) SetAlignment(align attribute.Alignment) error

Set and Get Alignment

func (*Editor) SetCallback

func (e *Editor) SetCallback(cb Callback) error

SetCallback set callback interface. This is goroutine safe, But some events do not call callback until reflation latency.

func (*Editor) SetColor

func (e *Editor) SetColor(color uint32) error

Set and Get Color using 0xRRGGBB for 24bit color

func (*Editor) SetTextUnitPx

func (e *Editor) SetTextUnitPx(textUnitPx fixed.Point26_6) error

SetTextUnitPx sets text unit size in px. The text unit size means pixel region of drawn half character on UI. This setting affects calculation of image size in Editor.

func (*Editor) SetViewSize

func (e *Editor) SetViewSize(viewLineCount, viewLineRuneWidth int) error

func (*Editor) Sync

func (e *Editor) Sync() error

Sync flushes any pending output result, PrintXXX or ClearLine, at UI implementor. It can also use rate limitting for PrintXXX functions.

func (*Editor) WindowLineCount

func (e *Editor) WindowLineCount() (int, error)

line count to fill the window height.

func (*Editor) WindowRuneWidth

func (e *Editor) WindowRuneWidth() (int, error)

rune width to fill the window width.

type EditorOptions

type EditorOptions struct {
	// ImageFetchType indicates how does image pixels fetched by Editor.
	ImageFetchType pubdata.ImageFetchType
}

type ImageBytesLoader

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

ImageBytesLoader loads image byte contents with different image fetch methods. It caches returned image bytes.

func NewImageBytesLoader

func NewImageBytesLoader(
	cacheSize int,
	fontSingleWidthPx, fontHeightPx fixed.Int26_6,
	fetchType pubdata.ImageFetchType,
) *ImageBytesLoader

func (*ImageBytesLoader) LoadBytes

func (loader *ImageBytesLoader) LoadBytes(src string, widthInRW, heightInLC int) ImageFetchResult

type ImageFetchResult

type ImageFetchResult struct {
	Bytes     []byte
	TsSize    text.TextScaleSize
	PxSize    image.Point
	FetchType pubdata.ImageFetchType
}

ImageFetchResult is a result of ImageBytesLoader::LoadBytes() It contains image bytes, text-scale image size, px-scale image size and fetched type of bytes.

type Message

type Message struct {
	ID   MessageID
	Type MessageType
	Task func()
}

Message is task primitive executed in a event loop. Only Task should be set, others are optional.

type MessageID

type MessageID uint64

MessageID indicates a unique ID for the Message. This is used by SyncTask to identify which task is waited for its done.

const (
	DefaultMessageID MessageID = 0
)

type MessageLooper

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

MessageLooper executes Message tasks in its event loop.

func NewMessageLooper

func NewMessageLooper(ctx context.Context) *MessageLooper

NewMessageLooper create new MessageLooper instance and start event loop internally. So new instance can be used immediately for Send() message.

func (*MessageLooper) Close

func (looper *MessageLooper) Close()

Close quits internal event loop. It is goroutine safe.

func (*MessageLooper) Send

func (looper *MessageLooper) Send(ctx context.Context, msg *Message) error

func (*MessageLooper) WaitDone

func (looper *MessageLooper) WaitDone(ctx context.Context, id MessageID) error

type MessageType

type MessageType uint8

MesssageType indicates how does the message be handled.

Directories

Path Synopsis
Package mock_publisher is a generated GoMock package.
Package mock_publisher is a generated GoMock package.

Jump to

Keyboard shortcuts

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