Documentation ¶
Overview ¶
Package gioutil provides wrappers around certain GIO classes to be more Go idiomatic.
Index ¶
- func InputCloser(ctx context.Context, input gio.InputStreamer) io.Closer
- func NewInputStream(r io.Reader) *gio.InputStream
- func NewOutputStream(w io.Writer) *gio.OutputStream
- func ObjectValue[T any](obj glib.Objector) T
- func OutputCloser(ctx context.Context, output gio.OutputStreamer) io.Closer
- func PixbufLoaderWriter(l *gdkpixbuf.PixbufLoader) io.WriteCloser
- func ReadCloser(r io.Reader, c io.Closer) io.ReadCloser
- func Seeker(ctx context.Context, s gio.Seekabler) io.Seeker
- type ListModel
- func (l *ListModel[T]) AllItems() func(yield func(T) bool)
- func (l *ListModel[T]) Append(v T)
- func (l *ListModel[T]) Item(index int) T
- func (l *ListModel[T]) NItems() int
- func (l *ListModel[T]) RangeItems(i, j int) func(yield func(T) bool)
- func (l *ListModel[T]) Remove(index int)
- func (l *ListModel[T]) Splice(position, removals int, values ...T)
- type ListModelType
- type StreamReader
- type StreamWriter
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func InputCloser ¶
InputCloser wraps an InputStreamer and returns an io.Closer.
func NewInputStream ¶
NewInputStream creates a new InputStream for the given io.Reader. If r implements io.Closer, then it is automatically called if needed.
func NewOutputStream ¶
NewOutputStream creates a new OutputStream for the given io.Reader. If r implements io.Closer, then it is automatically called if needed.
func ObjectValue ¶
ObjectValue returns the value of the given object. The object must originate from a ListModel.
func OutputCloser ¶
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 ¶
ReadCloser combines the reader and closer together.
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 (*ListModel[T]) Append ¶
func (l *ListModel[T]) Append(v T)
Append appends a value to the list.
func (*ListModel[T]) RangeItems ¶
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.
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.
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) Flush ¶
func (w *StreamWriter) Flush() error
Flush flushes the writer. See gio.OutputStreamer.Flush.