gioutil

package
v0.0.0-...-aefa52a Latest Latest
Warning

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

Go to latest
Published: Apr 5, 2024 License: MPL-2.0, ISC Imports: 13 Imported by: 0

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

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

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/brotholo/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

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

NewListModel creates a new list model.

func (*ListModel[T]) AllItems

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

AllItems returns an iterator over all values in the list.

func (*ListModel[T]) Append

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

Append appends a value to the list.

func (*ListModel[T]) Item

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

Item returns the value at the given index.

func (*ListModel[T]) NItems

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

NItems returns the number of items in the list.

func (*ListModel[T]) RangeItems

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

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

Remove removes the value at the given index.

func (*ListModel[T]) Splice

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

type ListModelType[T any] struct{}

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

func NewListModelType

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

NewListModelType creates a new list model type.

func (ListModelType[T]) New

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

New creates a new list model of type T.

func (ListModelType[T]) ObjectValue

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