gtools

package
v1.16.0 Latest Latest
Warning

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

Go to latest
Published: Oct 19, 2024 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Append

func Append(parent Appender, widgets ...gtk.Widgetter)

func FetchObjects

func FetchObjects(str any, builder string)

What this function does is to obtain the tags of the provided structure and with the content of the tag call gtk.Builder.GetObject and assign it to its corresponding field, if the field has no tag it will be skipped and if it is another sub struct it will continue until it reaches the end.

Example
gtk.Init()

const xml = `<?xml version="1.0" encoding="UTF-8"?>
<interface>
  <requires lib="gtk" version="4.0"/>
  <object class="GtkWindow" id="window">
    <property name="title">Hello World</property>
  </object>
</interface>`

type ui struct {
	Window *gtk.Window `gtk:"window"`
}

w := new(ui)
gtools.FetchObjects(w, xml)

fmt.Println(w.Window.Title()) // Hello World
Output:

func NewFactoryBind

func NewFactoryBind(f func(listitem ListItem, pos int)) func(*glib.Object)

func NewFactorySetup

func NewFactorySetup(f func(listitem ListItem)) func(*glib.Object)

func NewListModel

func NewListModel[T any](items ...T) *gioutil.ListModel[T]

func ToWidgetter

func ToWidgetter[T gtk.Widgetter](items []T) []gtk.Widgetter

Converts the slice of the gtk.Widgetter types to a slice of gtk.Widgetter.

Types

type Appender

type Appender interface {
	glib.Objector
	Append(gtk.Widgetter)
}

It is simply an interface of a glib.Objector that has the append method.

type Factory

type Factory[T any] struct {
	// contains filtered or unexported fields
}

func NewFactory

func NewFactory[T any](
	model Modeller[T],
	setup FactorySetup,
	bind FactoryBind[T],
) *Factory[T]

func (*Factory[T]) Bind

func (f *Factory[T]) Bind() FactoryBind[T]

func (*Factory[T]) Modeller

func (f *Factory[T]) Modeller() Modeller[T]

func (*Factory[T]) SetBind

func (f *Factory[T]) SetBind(b FactoryBind[T])

func (*Factory[T]) SetModeller

func (f *Factory[T]) SetModeller(m Modeller[T])

func (*Factory[T]) SetSetup

func (f *Factory[T]) SetSetup(s FactorySetup)

func (*Factory[T]) SetSignalListItemFactory added in v1.15.1

func (f *Factory[T]) SetSignalListItemFactory(fac *gtk.SignalListItemFactory)

func (*Factory[T]) Setup

func (f *Factory[T]) Setup() FactorySetup

func (*Factory[T]) SignalListItemFactory added in v1.15.1

func (f *Factory[T]) SignalListItemFactory() *gtk.SignalListItemFactory

type FactoryBind

type FactoryBind[T any] func(ListItem, T)

type FactorySetup

type FactorySetup func(ListItem)

type Factoryer

type Factoryer[T any] interface {
	SetSignalListItemFactory(*gtk.SignalListItemFactory)
	SignalListItemFactory() *gtk.SignalListItemFactory

	Modeller() Modeller[T]
	SetModeller(Modeller[T])

	SetSetup(FactorySetup)
	Setup() FactorySetup

	SetBind(FactoryBind[T])
	Bind() FactoryBind[T]
}

type ListItem

type ListItem interface {
	glib.Objector

	AccessibleDescription() string
	AccessibleLabel() string
	Activatable() bool
	Child() gtk.Widgetter
	Focusable() bool
	Item() *glib.Object
	Position() uint
	Selectable() bool
	Selected() bool

	SetAccessibleDescription(description string)
	SetAccessibleLabel(label string)
	SetActivatable(activatable bool)
	SetChild(child gtk.Widgetter)
	SetFocusable(focusable bool)
	SetSelectable(selectable bool)
}

type ListSelectionMode

type ListSelectionMode int
const (
	SelectionNone ListSelectionMode = iota
	SelectionSingle
	SelectionMultiple
)

type Model

type Model[T any] struct {
	// contains filtered or unexported fields
}

func NewModel

func NewModel[T any](items ...T) *Model[T]

func (*Model[T]) Append

func (m *Model[T]) Append(items ...T)

func (*Model[T]) At

func (m *Model[T]) At(index int) T

func (*Model[T]) Len

func (m *Model[T]) Len() int

func (*Model[T]) ListModel

func (m *Model[T]) ListModel() *gioutil.ListModel[T]

func (*Model[T]) Range

func (m *Model[T]) Range(f func(i int, v T) bool)

func (*Model[T]) RefreshItems

func (m *Model[T]) RefreshItems()

Regenerates the List.Items based on the model.

func (*Model[T]) RefreshModel

func (m *Model[T]) RefreshModel()

func (*Model[T]) Remove

func (m *Model[T]) Remove(index int)

func (*Model[T]) S

func (m *Model[T]) S() []T

func (*Model[T]) SetItems

func (m *Model[T]) SetItems(items []T)

Re-generate the list with the items provided.

func (*Model[T]) Splice

func (m *Model[T]) Splice(pos, rms int, values ...T)

type ModelVar

type ModelVar[T any] struct {
	// contains filtered or unexported fields
}

func NewModelVar

func NewModelVar[T any](items *[]T) *ModelVar[T]

func (*ModelVar[T]) Append

func (m *ModelVar[T]) Append(items ...T)

func (*ModelVar[T]) At

func (m *ModelVar[T]) At(i int) T

func (*ModelVar[T]) Len

func (m *ModelVar[T]) Len() int

func (*ModelVar[T]) ListModel

func (m *ModelVar[T]) ListModel() *gioutil.ListModel[T]

func (*ModelVar[T]) Ptr

func (m *ModelVar[T]) Ptr() *[]T

func (*ModelVar[T]) Range

func (m *ModelVar[T]) Range(f func(int, T) bool)

func (*ModelVar[T]) RefreshItems

func (m *ModelVar[T]) RefreshItems()

func (*ModelVar[T]) RefreshModel

func (m *ModelVar[T]) RefreshModel()

func (*ModelVar[T]) Remove

func (m *ModelVar[T]) Remove(i int)

func (*ModelVar[T]) S

func (m *ModelVar[T]) S() []T

func (*ModelVar[T]) SetItems

func (m *ModelVar[T]) SetItems(items []T)

func (*ModelVar[T]) Splice

func (m *ModelVar[T]) Splice(pos, rms int, appends ...T)

type Modeller

type Modeller[T any] interface {
	ListModel() *gioutil.ListModel[T]
	S() []T
	Len() int
	SetItems([]T)
	Remove(int)
	Append(...T)
	Splice(int, int, ...T)
	RefreshModel()
	RefreshItems()
	At(int) T
	Range(func(int, T) bool)
}

type Selection

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

func NewSelection

func NewSelection(mode ListSelectionMode, model gio.ListModeller) *Selection

func (*Selection) Autoselect

func (s *Selection) Autoselect() bool

If the assigned ListModeller is not compatible with this setting it will simply do nothing. This setting is only compatible with SelectionSingle.

func (*Selection) CanUnselect

func (s *Selection) CanUnselect() bool

func (*Selection) ConnectMultipleSelected

func (s *Selection) ConnectMultipleSelected(f func([]int))

func (*Selection) ConnectSelected

func (s *Selection) ConnectSelected(f func(int))

func (*Selection) ListModeller

func (s *Selection) ListModeller() gio.ListModeller

func (*Selection) MultipleSelected

func (s *Selection) MultipleSelected() []int

This method iterates over each element in the list and returns the selected ones. It only does something if the ListModel is a MultipleSelection, otherwise it simply returns an empty list.

func (*Selection) Select

func (s *Selection) Select(index int)

The Select method behaves as expected when applied to a SingleSelection SelectionModel. It selects the item at the specified index. However, when applied to a MultipleSelection, it behaves differently. Instead of selecting only the item at the specified index, it deselects all other items and selects only the one at that index.

In the case of NoSelection, it simply does nothing.

func (*Selection) SelectAll

func (s *Selection) SelectAll()

With SelectionNone and SelectionSingle it does nothing, and with SelectionMultiple, it does what it promises, i.e., select all items in the list.

func (*Selection) SelectMultiple

func (s *Selection) SelectMultiple(indexes ...int)

This method only does something when the ListModel is of the MultiSelection type, and it requires you to pass the indexes that it will select. If any of the indexes cannot be converted to uint, it will simply iterate to the next element. However, if any of the indexes are not in the list, it will throw an error, i.e. it will crash.

If an element is already selected, deselects it.

func (*Selection) SelectRange

func (s *Selection) SelectRange(pos, nItems int, unSelectRest bool)

Requests to select a range of items.

func (*Selection) Selected

func (s *Selection) Selected() int

Returns the index of the selected item, or -1 if its index is null or the selection model does not allow it.

func (*Selection) SelectionMode

func (s *Selection) SelectionMode() ListSelectionMode

func (*Selection) SelectionModeller

func (s *Selection) SelectionModeller() gtk.SelectionModeller

func (*Selection) SetAutoselect

func (s *Selection) SetAutoselect(b bool)

If the assigned ListModeller is not compatible with this setting it will simply do nothing. This setting is only compatible with SelectionSingle.

func (*Selection) SetCanUnselect

func (s *Selection) SetCanUnselect(b bool)

func (*Selection) SetListModeller

func (s *Selection) SetListModeller(m gio.ListModeller)

func (*Selection) SetSelectionMode

func (s *Selection) SetSelectionMode(mode ListSelectionMode)

func (*Selection) SetSelectionModeller

func (s *Selection) SetSelectionModeller(m gtk.SelectionModeller)

func (*Selection) Unselect

func (s *Selection) Unselect(index int)

Requests to unselect an item.

func (*Selection) UnselectAll

func (s *Selection) UnselectAll()

With SelectionSingle and SelectionMultiple it deselects the only element that can be selected, with SelectionNone it does nothing.

func (*Selection) UnselectRange

func (s *Selection) UnselectRange(pos, nItems int)

Requests to unselect a range of items.

type Selectioner

type Selectioner interface {
	ListModeller() gio.ListModeller
	SetListModeller(gio.ListModeller)

	Autoselect() bool
	SetAutoselect(bool)

	CanUnselect() bool
	SetCanUnselect(bool)

	SelectionModeller() gtk.SelectionModeller
	SetSelectionModeller(gtk.SelectionModeller)

	SelectionMode() ListSelectionMode
	SetSelectionMode(ListSelectionMode)

	ConnectSelected(func(int))
	ConnectMultipleSelected(func([]int))

	SelectRange(int, int, bool)
	SelectAll()
	Select(int)
	SelectMultiple(...int)

	UnselectAll()
	UnselectRange(int, int)
	Unselect(int)

	Selected() int
	MultipleSelected() []int
}

type SetModelFactoryer

type SetModelFactoryer interface {
	gtk.Widgetter
	SetModel(gtk.SelectionModeller)
	SetFactory(*gtk.ListItemFactory)
}

Jump to

Keyboard shortcuts

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