Containment and overlays
Some widgets exist to hold other content. Cards, accordions and carousels group it in place. Sheets, pop-ups, menus and tooltips float above the rest of the window for a moment. A swipe area reports swipes across what it holds. Inner windows are small windows inside your app’s window, which the user drags, resizes and closes.

Which one to use
| You want | Use |
|---|---|
| A titled box around related content | Card |
| Sections the user expands one at a time | Accordion |
| A row of items the user steps through one at a time | Carousel |
| Content the user swipes left, right, up or down, such as a card to keep or skip | SwipeArea |
| Extra actions or content sliding up from the bottom | BottomSheet |
| Supplementary details beside the main content | SideSheet |
| Any content floating above the window | PopUp |
| Several movable, resizable windows inside the app’s window | container.InnerWindow in a container.MultipleWindows |
| A right-click menu on a widget | ContextMenu |
| A menu opened from a button | ShowPopUpMenuAtRelativePosition |
| A short hint on hover | SetToolTipText, or Tooltip for non-widget content |
For a dialog with a title and buttons, such as a confirmation, use the
dialog package.
Card
Card shows a
Title, a Subtitle, optional Content below them and an optional Image
above them. Any of these can be left empty.
order := widget.NewCard("Order #1042", "Shipped yesterday",
widget.NewButton("Track parcel", func() {}))
plan := widget.NewCard("Pro plan", "Billed yearly", widget.NewLabel("All features included"))
plan.Style = widget.CardStyleOutlinedStyle is one of the three MD3 card variants: CardStyleElevated (the
default, with a shadow), CardStyleFilled (a filled surface, no shadow) and
CardStyleOutlined (a border, no shadow). SetTitle, SetSubTitle,
SetContent and SetImage change a card that is already shown.
Accordion
Accordion
stacks items, each a title that expands to show its Detail when tapped.
faq := widget.NewAccordion(
widget.NewAccordionItem("How do I reset my password?",
widget.NewLabel("Use the link on the sign-in page.")),
widget.NewAccordionItem("Can I export my data?",
widget.NewLabel("Yes, from Settings > Export.")),
)
faq.MultiOpen = true
faq.Open(0)By default opening one item closes the others. Set MultiOpen to let several
stay open. Open(i), Close(i), OpenAll() and CloseAll() work from
code; without MultiOpen, OpenAll opens only the first item. Append,
Prepend, Remove and RemoveIndex change the items.
Carousel
Carousel
shows one item at a time, with previous and next buttons beside it and a row
of dots below that marks the current item. The user can also swipe
sideways: the current item follows the finger and the next one slides in
beside it.
var slides []core.CanvasObject
for i := 1; i <= 4; i++ {
slides = append(slides, widget.NewCard(fmt.Sprintf("Slide %d", i), "", nil))
}
carousel := widget.NewCarousel(slides...)
carousel.OnChanged = func(i int) {
w.SetTitle(fmt.Sprintf("Containment: slide %d", i+1))
}When the user lets go, the carousel moves to the next item if the swipe went more than a fifth of its width or was a quick flick. Otherwise it goes back to the current item. Past the first or last item the drag meets resistance and always goes back. In a right-to-left layout the order, buttons and swipe direction are mirrored.
CurrentItem is the index shown and OnChanged receives it after each move.
Next() and Previous() move from code.
SwipeArea
SwipeArea
holds one object and tells you when the user swipes across it. A swipe is a
drag that goes far enough and mostly along one axis. OnSwiped receives the
direction the finger moved: SwipeLeft, SwipeRight, SwipeUp or
SwipeDown. Taps still reach the content.
pages := widget.NewLabel("Swipe left or right")
area := widget.NewSwipeArea(pages, func(d widget.SwipeDirection) {
status.SetText(fmt.Sprint("Swiped ", d))
})Set Follow to make the content a card that moves with the finger and tilts
a little as it goes:
names := []string{"Ada", "Grace", "Linus", "Margaret"}
next := 0
card := widget.NewCard(names[0], "Swipe right to keep, left to skip", nil)
deck := widget.NewSwipeArea(card, func(d widget.SwipeDirection) {
status.SetText(fmt.Sprintf("%s: %s", names[next], d))
// The card is back in place: show the next item on it.
next = (next + 1) % len(names)
card.SetTitle(names[next])
})
deck.Follow = true
deck.Directions = map[widget.SwipeDirection]widget.SwipeCardMode{
widget.SwipeUp: widget.SwipeIgnore,
widget.SwipeDown: widget.SwipeIgnore,
}
deck.OnSwipeProgress = func(d widget.SwipeDirection, p float32) {
if p > 0 {
status.SetText(fmt.Sprintf("%s %.0f%%", d, p*100))
}
}- A release a fifth of the way across, or a flick, throws the card off that
side.
OnSwipedruns and the content is back in place, ready for the next item. A shorter drag springs it back. OnSwipeProgressreports how close the card is to a swipe, from 0 at rest to 1 where a release would swipe. Use it to show a hint as the card leaves.Directionssets what a swipe does in each direction.SwipeThrow(the default for any direction not in the map) throws the card.SwipeStaylets the card follow the finger but springs it back, and runsOnSwipedas it starts back.SwipeIgnorekeeps the card still in that direction and never runsOnSwipedfor it.
With animations off in the app settings, the card moves at once.
Bottom and side sheets
showShare := widget.NewButton("Share…", func() {
sheet := widget.NewBottomSheet(nil)
sheet.Modal = true
sheet.Content = container.NewVBox(
widget.NewLabel("Share to"),
widget.NewButton("Copy link", func() { sheet.Hide() }),
widget.NewButton("Cancel", func() { sheet.Hide() }),
)
sheet.Show(w.Canvas())
})BottomSheet
slides up from the bottom edge of the canvas you pass to Show. It is at
most 640 units wide and centred. Hide() closes it.
showDetails := widget.NewButton("Details", func() {
widget.ShowSideSheet(container.NewVBox(
widget.NewLabel("Size: 2.4 MB"),
widget.NewLabel("Modified: today"),
), w.Canvas())
})SideSheet
opens at the right side of the canvas. ShowBottomSheet and ShowSideSheet
create and show a sheet in one call.
Sheets are not modal by default, so a tap outside closes them. Set Modal
before Show to dim the window and block it until your code calls Hide.
Escape closes either kind.
PopUp
PopUp
floats any content above a canvas, with padding and a shadow. Sheets and
dialogs are built on it.
var pop *widget.PopUp
pop = widget.NewModalPopUp(container.NewVBox(
widget.NewLabel("Are you still there?"),
widget.NewButton("Yes", func() { pop.Hide() }),
), w.Canvas())
showPop := widget.NewButton("Pop-up", func() { pop.Show() })NewPopUpandNewModalPopUpcreate a pop-up without showing it. Show it withShow(),ShowAtPosition(pos)orShowAtRelativePosition(pos, obj), and close it withHide().ShowPopUp,ShowModalPopUp,ShowPopUpAtPositionandShowPopUpAtRelativePositioncreate and show one in a single call.- A normal pop-up closes when the user taps outside it. A modal one covers the window with a dimmed overlay, ignores taps outside, and stays until your code hides it. Escape closes both.
- Set
OnDismissedto run your own close logic whenever the user dismisses the pop-up: Escape, a tap or right-click outside a normal pop-up, or the screen reader’s dismiss action. When it is set, it replaces the plain hide, so your function must callHide()itself. CallingHide()from code does not run it.
Inner windows
container.InnerWindow
draws a window inside your app’s window: a title bar with close, minimise and
maximise buttons, your content below it, and a corner handle at the bottom
right for resizing. Put inner windows in a
container.MultipleWindows,
which lets the user move them around.

notes := container.NewInnerWindow("Notes", widget.NewMultiLineEntry())
notes.Icon = theme.DocumentIcon()
notes.Move(geo.NewPos(20, 20))
notes.Resize(geo.NewSize(300, 220))
info := container.NewInnerWindow("About", widget.NewLabel("Drag a title bar to move a window,\nand its bottom-right corner to resize it."))
info.Move(geo.NewPos(260, 140))
desk := container.NewMultipleWindows(notes, info)MultipleWindows gives each window its behaviour:
- dragging the title bar moves the window;
- dragging the bottom-right corner resizes it, never below its minimum size;
- tapping the title bar brings the window to the front.
It does this by setting each window’s OnDragged, OnResized and
OnTappedBar, so any functions you set there yourself are replaced. A window
outside a MultipleWindows does not move by itself: set those three to move,
resize and restack it as you like.
MultipleWindows does not place windows for you. Each one starts at the
position you give it with Move, at its minimum size unless you call
Resize. Add puts another window on top of the others. You can also change
the Windows slice and call Refresh; the last window in it is drawn on top.
Window buttons
The close button hides the window. To ask first, set CloseIntercept. Your
function then runs instead, and calls Close when the window should go:
notes.CloseIntercept = func() {
dialog.ShowConfirm("Close notes?", "Unsaved text will be lost.", func(ok bool) {
if ok {
notes.Close()
}
}, w)
}Minimise and maximise do nothing on their own. Each button works only once
you set its function, OnMinimized or OnMaximized; until then, it is shown
disabled on desktop and hidden on phones and tablets. Your function decides
what the button does. SetMaximized only swaps the maximise icon for a
restore icon, so resize the window yourself:
var maximised bool
var restorePos geo.Position
var restoreSize geo.Size
notes.OnMaximized = func() {
if maximised {
notes.Move(restorePos)
notes.Resize(restoreSize)
} else {
restorePos, restoreSize = notes.Position(), notes.Size()
notes.Move(geo.NewPos(0, 0))
notes.Resize(desk.Size())
}
maximised = !maximised
notes.SetMaximized(maximised) // swaps the maximise icon for restore
}Icon adds an icon to the title bar. It is drawn disabled unless you set
OnTappedIcon. SetTitle changes the title, and SetPadded(false) removes
the padding around your content.
The buttons sit at the left of the title bar on macOS, and at the right on
Windows, Linux and BSD. Set Alignment to widget.ButtonAlignLeading or
widget.ButtonAlignTrailing to choose for every platform.
Disabling an inner window
Disable() stops the user from closing, moving or resizing the window. It
also disables every widget inside it that can be disabled, and blocks and
dims the rest, as described in
Disabled widgets. Your code can still
call Close, SetContent and SetMaximized.
Menus
file := widget.NewContextMenu(widget.NewLabel("report.pdf"),
bellui.NewMenuItem("Open", func() { status.SetText("Open") }),
bellui.NewMenuItem("Rename", func() { status.SetText("Rename") }),
bellui.NewMenuItemSeparator(),
bellui.NewMenuItem("Delete", func() { status.SetText("Delete") }),
)ContextMenu
wraps any object and shows a menu of
bellui.MenuItems
on right-click (a secondary tap). Taps, hovers and drags still reach the
wrapped object. NewContextMenuWithMenu takes a ready-made *bellui.Menu
instead of items.
To open a menu from a button, pass a *bellui.Menu to
ShowPopUpMenuAtRelativePosition, with a position relative to the button:
sortMenu := bellui.NewMenu("",
bellui.NewMenuItem("By name", func() { status.SetText("Sort by name") }),
bellui.NewMenuItem("By date", func() { status.SetText("Sort by date") }),
)
var sort *widget.Button
sort = widget.NewButtonWithIcon("Sort", theme.MenuDropDownIcon(), func() {
widget.ShowPopUpMenuAtRelativePosition(sortMenu, w.Canvas(),
geo.NewPos(0, sort.Size().Height), sort)
})ShowPopUpMenuAtPosition takes an absolute position instead, and
NewPopUpMenu creates a menu you can show again and again.
Tooltips
Every widget has SetToolTipText. On desktop, the text appears in a small
bubble after the pointer rests on the widget for a moment, and disappears
when it leaves. An empty string removes the tooltip.
refresh := widget.NewIconButton(theme.ViewRefreshIcon(), func() { status.SetText("Refreshed") })
refresh.SetToolTipText("Reload the list")
info := widget.NewTooltip(widget.NewIcon(theme.InfoIcon()), "Files are kept for 30 days")Tooltip
does the same as a wrapper, which is useful for content that is not a widget,
such as a canvas object.