widgets

package
v1.9.0 Latest Latest
Warning

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

Go to latest
Published: May 26, 2024 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewButton added in v1.8.0

func NewButton(label string, onClicked func()) *gtk.Button

Types

type AlternativeList added in v1.5.0

type AlternativeList struct {
	*List[int]

	Len AlternativeListLen
}
Example
items := []string{"1", "2", "3"}

list := widgets.NewAlternativeList(
	widgets.SelectionMultiple,
	func() int {
		return len(items)
	},
	func(listitem *gtk.ListItem) {
		listitem.SetChild(gtk.NewLabel(""))
	},
	func(listitem *gtk.ListItem, index int) {
		listitem.Child().(*gtk.Label).SetText(items[index])
	},
)

list.OnMultipleSelected = func(indexes []int) {
	for _, i := range indexes {
		fmt.Printf("|%s|", items[i])
	}
	fmt.Println()
}

list.OnSelected = func(index int) {
	fmt.Println(index)
}
Output:

func NewAlternativeList added in v1.5.0

func NewAlternativeList(
	smodel ListSelectionMode,
	lenfunc AlternativeListLen,
	setup FactorySetup,
	bind AlternativeListBind,
) *AlternativeList

It creates an alternative list, which is practically the same as fyne's, that only requires the slice length to work. The only real difference is that the list has to be refreshed manually with each modification of the base slice.

func (*AlternativeList) Refresh added in v1.5.0

func (l *AlternativeList) Refresh()

Refreshes absolutely everything. To be more specific here is the list of what it refreshes:

- Refreshes the selection mode

- Refreshes the factory

- Refreshes the model

I generally discourage its use and prefer to refresh things as they are modified manually and individually.

func (*AlternativeList) RefreshModel added in v1.5.0

func (l *AlternativeList) RefreshModel()

type AlternativeListBind added in v1.5.0

type AlternativeListBind ListBind[int]

type AlternativeListLen added in v1.5.0

type AlternativeListLen func() int
type DropDown[T any] struct {
	*gtk.DropDown

	Items   []T
	Model   *gioutil.ListModel[T]
	Factory *gtk.SignalListItemFactory

	OnChanged func(index int)

	Setup FactorySetup
	Bind  ListBind[T]
}

func NewDropDown

func NewDropDown[T any](
	items []T,
	setup FactorySetup,
	bind ListBind[T],
) *DropDown[T]
func (d *DropDown[T]) Append(v T)
func (d *DropDown[T]) RefreshModel()
func (d *DropDown[T]) Remove(index int)
func (d *DropDown[T]) Splice(pos, rms int, values ...T)

type FactorySetup added in v1.9.0

type FactorySetup func(*gtk.ListItem)

type List

type List[T any] struct {
	*gtk.ListView

	Items []T

	Setup FactorySetup
	Bind  ListBind[T]

	OnSelected         func(index int)
	OnMultipleSelected func(indexes []int)

	Factory *gtk.SignalListItemFactory

	SelectionMode     ListSelectionMode
	SelectionModeller gtk.SelectionModeller
	// https://pkg.go.dev/github.com/diamondburned/gotk4/pkg/core/gioutil#ListModel
	Model *gioutil.ListModel[T]
}
Example
items := []string{"1", "2", "3"}
list := widgets.NewList(
	items,
	widgets.SelectionMultiple,
	func(listitem *gtk.ListItem) {
		listitem.SetChild(gtk.NewLabel(""))
	},
	func(listitem *gtk.ListItem, obj string) {
		listitem.Child().(*gtk.Label).SetText(obj)
	},
)

list.OnMultipleSelected = func(indexes []int) {
	for _, i := range indexes {
		fmt.Printf("|%s|", list.Items[i])
	}
	fmt.Println()
}
list.OnSelected = func(index int) {
	fmt.Println(list.Items[index])
}
Output:

func NewList

func NewList[T any](
	items []T,
	smodel ListSelectionMode,
	setup FactorySetup,
	bind ListBind[T],
) *List[T]

func (*List[T]) Append

func (l *List[T]) Append(item T)

func (*List[T]) MultipleSelected added in v1.3.0

func (l *List[T]) 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 (*List[T]) Refresh added in v1.4.2

func (l *List[T]) Refresh()

Refreshes absolutely everything. To be more specific here is the list of what it refreshes:

- Refreshes List.Items

- Refreshes the selection mode

- Refreshes the factory

- Refreshes the model

I generally discourage its use and prefer to refresh things as they are modified manually and individually.

func (*List[T]) RefreshFactory added in v1.4.2

func (l *List[T]) RefreshFactory()

Can be used when modifying List.Setup and/or List.Bind to redraw the entire list following the new Setup and Bind.

Example
items := []string{"1", "2", "3"}
list := widgets.NewList(
	items,
	widgets.SelectionMultiple,
	func(listitem *gtk.ListItem) {
		listitem.SetChild(gtk.NewLabel(""))
	},
	func(listitem *gtk.ListItem, obj string) {
		listitem.Child().(*gtk.Label).SetText(obj)
	},
)

list.Setup = func(li *gtk.ListItem) {
	li.SetChild(gtk.NewText())
}
list.Bind = func(li *gtk.ListItem, s string) {
	li.Child().(*gtk.Text).SetText(s)
}
list.RefreshFactory()
Output:

func (*List[T]) RefreshItems

func (l *List[T]) RefreshItems()

Regenerates the List.Items based on the model.

func (*List[T]) RefreshModel added in v1.6.1

func (l *List[T]) RefreshModel()

func (*List[T]) RefreshSelectionModeller added in v1.4.1

func (l *List[T]) RefreshSelectionModeller()

func (*List[T]) Remove

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

func (*List[T]) Select added in v1.8.0

func (l *List[T]) 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 (*List[T]) SelectAll added in v1.8.0

func (l *List[T]) 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 (*List[T]) SelectMultiple added in v1.8.0

func (l *List[T]) 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 (*List[T]) SelectRange added in v1.8.0

func (l *List[T]) SelectRange(pos, nItems int, unSelectRest bool)

Requests to select a range of items.

func (*List[T]) Selected

func (l *List[T]) 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 (*List[T]) SetItems

func (l *List[T]) SetItems(items []T)

Re-generate the list with the items provided.

func (*List[T]) SetSelectionModeller

func (l *List[T]) SetSelectionModeller(mode ListSelectionMode)

func (*List[T]) Splice

func (l *List[T]) Splice(pos, rms int, values ...T)

func (*List[T]) Unselect added in v1.8.0

func (l *List[T]) Unselect(index int)

Requests to unselect an item.

func (*List[T]) UnselectAll added in v1.8.0

func (l *List[T]) UnselectAll()

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

func (*List[T]) UnselectRange added in v1.8.0

func (l *List[T]) UnselectRange(pos, nItems int)

Requests to unselect a range of items.

type ListBind added in v1.5.0

type ListBind[T any] func(*gtk.ListItem, T)

type ListSelectionMode

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

type PointerDropDown added in v1.9.0

type PointerDropDown[T any] struct {
	*DropDown[T]

	Items *[]T
}

func NewPointerDropDown added in v1.9.0

func NewPointerDropDown[T any](
	items *[]T,
	setup FactorySetup,
	bind ListBind[T],
) *PointerDropDown[T]

func (*PointerDropDown[T]) Append added in v1.9.0

func (d *PointerDropDown[T]) Append(v T)

func (*PointerDropDown[T]) RefreshModel added in v1.9.0

func (d *PointerDropDown[T]) RefreshModel()

func (*PointerDropDown[T]) Remove added in v1.9.0

func (d *PointerDropDown[T]) Remove(index int)

func (*PointerDropDown[T]) Splice added in v1.9.0

func (d *PointerDropDown[T]) Splice(pos, rms int, values ...T)

type PointerList added in v1.7.0

type PointerList[T any] struct {
	*List[T]

	Items *[]T
}

func NewPointerList added in v1.7.0

func NewPointerList[T any](
	items *[]T,
	smodel ListSelectionMode,
	setup FactorySetup,
	bind ListBind[T],
) *PointerList[T]

func (*PointerList[T]) Append added in v1.7.0

func (l *PointerList[T]) Append(item T)

func (*PointerList[T]) RefreshItems added in v1.7.0

func (l *PointerList[T]) RefreshItems()

func (*PointerList[T]) RefreshModel added in v1.7.0

func (l *PointerList[T]) RefreshModel()

func (*PointerList[T]) Remove added in v1.7.0

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

func (*PointerList[T]) SetItems added in v1.7.0

func (l *PointerList[T]) SetItems(items *[]T)

Re-generate the list with the items provided.

func (*PointerList[T]) Splice added in v1.7.0

func (l *PointerList[T]) Splice(pos, nRemovals int, additions ...T)

type StringList deprecated added in v1.6.1

type StringList struct {
	*List[string]
}

Deprecated: Replace it with CustomList[string]. Since version 1.6.1 this struct is renamed from List to StringList.

func NewStringList deprecated added in v1.6.1

func NewStringList(
	items []string,
	smodel ListSelectionMode,
	setup FactorySetup,
	bind ListBind[string],
) *StringList

Creates a new list that keeps the self.Items[] updated with that of the UI.

Deprecated: Replace it with NewCustomList[string] As of version 1.6.0 this is simply a wrapper for CustomList[string], so it is recommended to simply change it to this type. There should be no further incompatibility with respect to this migration, so it should not be a problem.

Jump to

Keyboard shortcuts

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