Documentation
¶
Overview ¶
Package adaptive provides adaptive GTK4 widget components. It's mainly for use in applications that aim to support both mobile and desktop viewports. It is an alternative to libadwaita.
Index ¶
- Constants
- func Init()
- func TransformInitials(in string) string
- type Avatar
- func (i *Avatar) Initials() string
- func (a *Avatar) SetAttributes(attrs *pango.AttrList)
- func (a *Avatar) SetFromFile(file string)
- func (a *Avatar) SetFromPaintable(p gdk.Paintabler)
- func (a *Avatar) SetFromPixbuf(p *gdkpixbuf.Pixbuf)
- func (a *Avatar) SetInitials(initials string)
- func (a *Avatar) SetInitialsTransformer(initialsFn func(string) string)
- func (a *Avatar) SetSizeRequest(size int)
- func (a *Avatar) SizeRequest() int
- type Bin
- type ErrorLabel
- type Fold
- func (f *Fold) FoldThreshold() int
- func (f *Fold) FoldWidth() int
- func (f *Fold) NotifyFolded(fn func(folded bool))
- func (f *Fold) NotifyRevealed(fn func(revealed bool))
- func (f *Fold) QueueResize()
- func (f *Fold) SetChild(child gtk.Widgetter)
- func (f *Fold) SetFoldThreshold(threshold int)
- func (f *Fold) SetFoldWidth(width int)
- func (f *Fold) SetFolded(folded bool)
- func (f *Fold) SetRevealSide(reveal bool)
- func (f *Fold) SetSideChild(child gtk.Widgetter)
- func (f *Fold) SideIsRevealed() bool
- type FoldRevealButton
- type LoadablePage
- type StatusPage
Examples ¶
Constants ¶
const FoldRevealButtonIcon = "open-menu-symbolic"
FoldRevealButtonIcon is the default icon name for a fold reveal button.
Variables ¶
This section is empty.
Functions ¶
func Init ¶
func Init()
Init initializes package adaptive. The caller should call this on application activation.
func TransformInitials ¶
TransformInitials transforms the given input string into initials.
Types ¶
type Avatar ¶
type Avatar struct { *Bin Image *gtk.Image Label *gtk.Label // for initials // contains filtered or unexported fields }
Avatar wraps around an Image and makes it appear round.
Example ¶
testapp.Run("avatar", func(app *gtk.Application) { adaptive.Init() sizes := []int{16, 24, 32, 48, 56, 64} main := gtk.NewBox(gtk.OrientationVertical, 8) main.SetMarginStart(8) main.SetMarginEnd(8) main.SetMarginTop(8) main.SetMarginBottom(8) avatarFns := []func(*adaptive.Avatar){ func(a *adaptive.Avatar) { a.SetInitials("Ferris Argyle") }, func(a *adaptive.Avatar) { a.SetFromPixbuf(testdata.MustAvatarPixbuf()) }, } for _, avatarFn := range avatarFns { box := gtk.NewBox(gtk.OrientationHorizontal, 8) box.SetHExpand(true) box.SetVExpand(true) box.SetHAlign(gtk.AlignCenter) box.SetVAlign(gtk.AlignCenter) for _, size := range sizes { avy := adaptive.NewAvatar(size) avatarFn(avy) box.Append(avy) } main.Append(box) } w := testapp.NewWindow(app, "Avatars", -1, -1) w.SetChild(main) w.Show() })
Output:
func NewAvatar ¶
NewAvatar creates a new round image. If radius is 0, then it will be half the dimensions. If the radius is less than 0, then nothing is rounded.
func (*Avatar) SetAttributes ¶
SetAttributes sets the initial label's Pango attributes.
func (*Avatar) SetFromFile ¶
SetFromFile sets the avatar from the given filename.
func (*Avatar) SetFromPaintable ¶
func (a *Avatar) SetFromPaintable(p gdk.Paintabler)
SetFromPaintable sets the avatar from the given paintable.
func (*Avatar) SetFromPixbuf ¶
func (a *Avatar) SetFromPixbuf(p *gdkpixbuf.Pixbuf)
SetFromPixbuf sets the avatar from the given pixbuf.
func (*Avatar) SetInitials ¶
SetInitials sets the string to be displayed as initials.
func (*Avatar) SetInitialsTransformer ¶
SetInitialsTransformer sets the initials transformer function for the Avatar. The function will be called to get the initials from the set string.
func (*Avatar) SetSizeRequest ¶
SetSizeRequest sets the avatar size.
func (*Avatar) SizeRequest ¶
SizeRequest gets the avatar's size request.
type Bin ¶
type Bin struct { *gtk.Box // contains filtered or unexported fields }
Bin is a widget that holds a single widget.
type ErrorLabel ¶
type ErrorLabel struct { *gtk.Box Short *gtk.ToggleButton ShortLabel *gtk.Label ShortIcon *gtk.Image Reveal *gtk.Revealer Full *gtk.Label RevealedIcon string CollapsedIcon string }
ErrorLabel is a label that displays the short form of an error but allows the user to get the full error from the UI directly.
Example ¶
testapp.Run("error-label", func(app *gtk.Application) { adaptive.Init() err := errors.New("failed to open hello.txt: filesystem error: missing hard drive") status := adaptive.NewErrorLabel(err) status.SetMarginTop(8) status.SetMarginBottom(8) status.SetMarginStart(8) status.SetMarginEnd(8) w := testapp.NewWindow(app, "Error", 150, 250) w.SetChild(status) w.Show() })
Output:
func NewErrorLabel ¶
func NewErrorLabel(err error) *ErrorLabel
NewErrorLabel creates a new error label from the given error. If err is nil, then the function panics.
func NewErrorLabelFull ¶
func NewErrorLabelFull(short, full string) *ErrorLabel
NewErrorLabelFull creates a new error label from two strings.
type Fold ¶
type Fold struct { gtk.Widgetter // contains filtered or unexported fields }
Fold is a component that acts similar to libadwaita's AdwFlap.
Example ¶
package main import ( "fmt" "strconv" "github.com/diamondburned/adaptive" "github.com/diamondburned/adaptive/internal/testapp" "github.com/diamondburned/gotk4/pkg/gtk/v4" ) func main() { testapp.Run("fold", func(app *gtk.Application) { adaptive.Init() stack := newStack() stack.SetHExpand(true) stackside := gtk.NewStackSidebar() stackside.SetStack(stack) fold := adaptive.NewFold(gtk.PosLeft) fold.SetSideChild(stackside) fold.SetChild(stack) foldButton := adaptive.NewFoldRevealButton() foldButton.ConnectFold(fold) h := gtk.NewHeaderBar() h.PackStart(foldButton) w := testapp.NewWindow(app, "Example Sidebar", 450, 300) w.SetChild(fold) w.SetTitlebar(h) w.Show() }) } func newStack() *gtk.Stack { stack := gtk.NewStack() stack.SetTransitionType(gtk.StackTransitionTypeSlideUpDown) for i := 0; i < 5; i++ { istr := strconv.Itoa(i) content := gtk.NewLabel(fmt.Sprintf("You're in stack number %s.", istr)) stack.AddTitled(content, "stack-"+istr, "Stack "+istr) } return stack }
Output:
func (*Fold) FoldThreshold ¶
FoldThreshold returns the fold width.
func (*Fold) FoldWidth ¶
FoldWidth returns the width of the sidebar. It is calculated from the fold threshold.
func (*Fold) NotifyFolded ¶
NotifyFolded subscribes fn to be called if the sidebar is folded or unfolded.
func (*Fold) NotifyRevealed ¶
NotifyRevealed subscribes fn to be called if the sidebar is revealed or not.
func (*Fold) QueueResize ¶
func (f *Fold) QueueResize()
QueueResize should be called when Fold's parent widths are changed.
func (*Fold) SetChild ¶
func (f *Fold) SetChild(child gtk.Widgetter)
SetChild sets the sidebar's main content.
func (*Fold) SetFoldThreshold ¶
SetFoldThreshold sets the width threshold that the sidebar will determine whether or not to fold.
func (*Fold) SetFoldWidth ¶
SetFoldWidth sets the width of the sidebar. The width must be lower than the fold threshold.
func (*Fold) SetRevealSide ¶
SetRevealSide sets whether or not the sidebar is revealed. It does not change if the sidebar isn't currently folded.
func (*Fold) SetSideChild ¶
func (f *Fold) SetSideChild(child gtk.Widgetter)
SetSideChild sets the sidebar's side content.
func (*Fold) SideIsRevealed ¶
SideIsRevealed returns true if the sidebar is revealed. If the sidebar is not folded, then true is returned regardless of what's given into SetRevealSide.
type FoldRevealButton ¶
type FoldRevealButton struct { *gtk.Revealer Button *gtk.ToggleButton }
FoldRevealButton is a button that toggles whether or not the fold's sidebar should be revealed.
func NewFoldRevealButton ¶
func NewFoldRevealButton() *FoldRevealButton
NewFoldRevealButton creates a new fold reveal button. The button is hidden by default until a sidebar is connected to it.
func (*FoldRevealButton) ConnectFold ¶
func (b *FoldRevealButton) ConnectFold(fold *Fold)
ConnectFold connects the current sidebar reveal button to the given sidebar.
func (*FoldRevealButton) SetIconName ¶
func (b *FoldRevealButton) SetIconName(icon string)
SetIconName sets the reveal button's icon name.
type LoadablePage ¶
type LoadablePage struct { *gtk.Stack Spinner *gtk.Spinner ErrorPage *StatusPage // contains filtered or unexported fields }
LoadablePage wraps a child that can be loading at times and error out.
Example ¶
const margin = 8 testapp.Run("loadable-page", func(app *gtk.Application) { adaptive.Init() errorCheck := gtk.NewCheckButtonWithLabel("Erroneous") errorCheck.SetHExpand(true) loadButton := gtk.NewButtonWithLabel("Load") loadButton.SetHExpand(true) child := gtk.NewBox(gtk.OrientationVertical, margin) child.SetMarginTop(margin) child.SetMarginBottom(margin) child.SetMarginStart(margin) child.SetMarginEnd(margin) child.Append(errorCheck) child.Append(loadButton) main := adaptive.NewLoadablePage() main.SetChild(child) loadButton.ConnectClicked(func() { erroneous := errorCheck.Active() main.SetLoading() glib.TimeoutSecondsAdd(5, func() { if erroneous { main.SetError(errors.New("failed to load busy box: checkmark was active")) } else { main.SetChild(child) } }) }) w := testapp.NewWindow(app, "Loadable", 250, -1) w.SetChild(main) w.Show() })
Output:
func NewLoadablePage ¶
func NewLoadablePage() *LoadablePage
NewLoadablePage creates a new LoadablePage widget.
func (*LoadablePage) SetChild ¶
func (p *LoadablePage) SetChild(child gtk.Widgetter)
SetChild sets the main child of the busy box.
func (*LoadablePage) SetError ¶
func (p *LoadablePage) SetError(err error)
SetError shows an error in the busy box.
func (*LoadablePage) SetLoading ¶
func (p *LoadablePage) SetLoading()
SetLoading shows a loading animation in the busy box.
type StatusPage ¶
type StatusPage struct { *gtk.Grid Icon *gtk.Image Title *gtk.Label }
StatusPage is a widget component that contains an icon, a title and a description, which are all optional.
Example ¶
testapp.Run("status-page", func(app *gtk.Application) { adaptive.Init() status := adaptive.NewStatusPage() status.SetIconName("computer-fail-symbolic") status.SetTitle("Uh oh!") status.SetDescriptionText("An oopsie-whoopsie has occured. Please throw your computer out the window.") w := testapp.NewWindow(app, "Status Page", 350, 200) w.SetChild(status) w.Show() })
Output:
func NewStatusPage ¶
func NewStatusPage() *StatusPage
NewStatusPage creates a new empty status page. All its widgets are properly initialized, but they're not added into the box until set.
func (*StatusPage) SetDescription ¶
func (p *StatusPage) SetDescription(desc gtk.Widgetter)
SetDescription ensures the description is in the page and sets its content.
func (*StatusPage) SetDescriptionText ¶
func (p *StatusPage) SetDescriptionText(desc string)
SetDescriptionText calls SetDescription with a new description label. The label is justified to the middle and has a 50 characters wide width cap.
func (*StatusPage) SetIconName ¶
func (p *StatusPage) SetIconName(icon string)
SetIconName ensures the icon is in the page and sets its icon name.
func (*StatusPage) SetTitle ¶
func (p *StatusPage) SetTitle(title string)
SetTitle ensures the title is in the page and sets its content.