gioutil

package
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Feb 13, 2024 License: MPL-2.0, ISC Imports: 13 Imported by: 8

Documentation

Overview

Package gioutil provides wrappers around certain GIO classes to be more Go idiomatic.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func InputCloser

func InputCloser(ctx context.Context, input gio.InputStreamer) io.Closer

InputCloser wraps an InputStreamer and returns an io.Closer.

func NewInputStream

func NewInputStream(r io.Reader) *gio.InputStream

NewInputStream creates a new InputStream for the given io.Reader. If r implements io.Closer, then it is automatically called if needed.

func NewOutputStream

func NewOutputStream(w io.Writer) *gio.OutputStream

NewOutputStream creates a new OutputStream for the given io.Reader. If r implements io.Closer, then it is automatically called if needed.

func ObjectValue added in v0.2.0

func ObjectValue[T any](obj glib.Objector) T

ObjectValue returns the value of the given object. The object must originate from a ListModel.

func OutputCloser

func OutputCloser(ctx context.Context, output gio.OutputStreamer) io.Closer

OutputCloser wraps an OutputStreamer and returns an io.Closer.

func PixbufLoaderWriter

func PixbufLoaderWriter(l *gdkpixbuf.PixbufLoader) io.WriteCloser

PixbufLoaderWriter wraps a PixbufLoader to satsify io.WriteCloser.

func ReadCloser

func ReadCloser(r io.Reader, c io.Closer) io.ReadCloser

ReadCloser combines the reader and closer together.

func Seeker

func Seeker(ctx context.Context, s gio.Seekabler) io.Seeker

Seeker wraps around a gio.Seekable.

Types

type ListModel added in v0.2.0

type ListModel[T any] struct {
	*gio.ListModel
}

ListModel is a wrapper around an internal ListModel that allows any Go value to be used as a list item. Internally, it uses core/gbox to store the values in a global registry for later retrieval.

Example
package main

import (
	"fmt"

	"github.com/diamondburned/gotk4/pkg/core/gioutil"
)

type Person struct {
	Name string
	Age  int
}

func (p Person) String() string {
	return fmt.Sprintf("%s: %d", p.Name, p.Age)
}

var peopleListModel = gioutil.NewListModelType[Person]()

func main() {
	list := peopleListModel.New()
	list.Append(Person{"Alice", 20})
	list.Append(Person{"Bob", 30})
	list.Append(Person{"Charlie", 40})

	// AllItems() can be iterated over if rangefunc is supported.
	all := list.AllItems()
	all(func(p Person) bool {
		fmt.Println(p)
		return true
	})

}
Output:

Alice: 20
Bob: 30
Charlie: 40

func NewListModel added in v0.2.0

func NewListModel[T any]() *ListModel[T]

NewListModel creates a new list model.

func (*ListModel[T]) AllItems added in v0.2.0

func (l *ListModel[T]) AllItems() func(yield func(T) bool)

AllItems returns an iterator over all values in the list.

func (*ListModel[T]) Append added in v0.2.0

func (l *ListModel[T]) Append(v T)

Append appends a value to the list.

func (*ListModel[T]) Item added in v0.2.0

func (l *ListModel[T]) Item(index int) T

Item returns the value at the given index.

func (*ListModel[T]) NItems added in v0.2.0

func (l *ListModel[T]) NItems() int

NItems returns the number of items in the list.

func (*ListModel[T]) RangeItems added in v0.2.0

func (l *ListModel[T]) RangeItems(i, j int) func(yield func(T) bool)

RangeItems returns an iterator over the values in the given range. If j is greater than the length of the list, it will be clamped to that.

func (*ListModel[T]) Remove added in v0.2.0

func (l *ListModel[T]) Remove(index int)

Remove removes the value at the given index.

func (*ListModel[T]) Splice added in v0.2.0

func (l *ListModel[T]) Splice(position, removals int, values ...T)

Splice removes the values in the given range and replaces them with the given values.

type ListModelType added in v0.2.0

type ListModelType[T any] struct{}

ListModelType is a type-safe wrapper around ListModel and ObjectValue. For an example, see ListModel's example.

func NewListModelType added in v0.2.1

func NewListModelType[T any]() ListModelType[T]

NewListModelType creates a new list model type.

func (ListModelType[T]) New added in v0.2.0

func (t ListModelType[T]) New() *ListModel[T]

New creates a new list model of type T.

func (ListModelType[T]) ObjectValue added in v0.2.0

func (t ListModelType[T]) ObjectValue(obj glib.Objector) T

ObjectValue returns the value of the given object as type T. The object must originate from a ListModel.

type StreamReader

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

StreamReader wraps around a gio.InputStreamer.

func Reader

func Reader(ctx context.Context, s gio.InputStreamer) *StreamReader

Reader wraps a gio.InputStreamer to provide an io.ReadCloser. The given context allows the caller to cancel all ongoing operations done on the new ReadCloser.

func (*StreamReader) Close

func (r *StreamReader) Close() error

Close implements io.Closer.

func (*StreamReader) Read

func (r *StreamReader) Read(b []byte) (int, error)

Read implements io.Reader.

type StreamWriter

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

StreamWriter wraps around a gio.OutputStreamer.

func Writer

func Writer(ctx context.Context, s gio.OutputStreamer) *StreamWriter

Writer wraps a gio.OutputStreamer to provide an io.WriteCloser with flushing capability.

func (*StreamWriter) Close

func (w *StreamWriter) Close() error

Close implements io.Closer.

func (*StreamWriter) Flush

func (w *StreamWriter) Flush() error

Flush flushes the writer. See gio.OutputStreamer.Flush.

func (*StreamWriter) ReadFrom

func (w *StreamWriter) ReadFrom(r io.Reader) (int64, error)

ReadFrom implements io.ReaderFrom. It has a fast path for gio.InputStreamers wrapped using gioutil.Reader.

func (*StreamWriter) Write

func (w *StreamWriter) Write(b []byte) (int, error)

Write implements io.Writer.

Jump to

Keyboard shortcuts

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