Navigation

To complete the navigation bar, we need to also display the filename in the middle of the bar. As you may have noticed, there is no toolbar widget that allows the showing of text, but we can create our own. Every item in a toolbar implements the widget.ToolbarItem interface, so we can create a new type that follows this pattern. By implementing ToolbarObject() (the only function this interface requires), we can return the appropriate label to display:

type toolbarLabel struct {
}

func (t *toolbarLabel) ToolbarObject() fyne.CanvasObject {
return widget.NewLabel("filename")
}

While we are updating the navigation bar, we should create placeholder functions that will handle the button presses for "previous" (left arrow) and "next" (right arrow). An empty parameter list matches the function type for a widget.Button callback, so these are simply as follows:

func previousImage() {}

func nextImage() {}

Lastly, we update the navigation bar creation to use the new toolbarLabel type that we created. By adding a second spacer widget, we are asking the layout to center the label as well as retain the right alignment of the next button:

navBar := widget.NewToolbar(
widget.NewToolbarAction(theme.NavigateBackIcon(), previousImage),
widget.NewToolbarSpacer(),
&toolbarLabel{},
widget.NewToolbarSpacer(),
widget.NewToolbarAction(theme.NavigateNextIcon(), nextImage))

With these changes in place, running the code should result in the following updated navigation bar. We will return to this later to set the correct filename, but for now, we shall move on to the file listing on the left of the interface:

The navigation bar created using customized toolbar components
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.147.84.169