Preface

The development of graphical user interfaces has a long history, resulting in a complicated landscape today. There are many different ways to build applications, each with their own benefits and drawbacks. In this modern world, with so many different devices in our everyday lives, it can seem impossible to reach an entire audience without building many different apps or GUIs. The technologies required are often platform-specific, and many of the technologies that exist have evolved across decades, leaving a legacy that can slow down new developers and experienced teams alike.

In the same way that the Go programming language was designed to make software development easier across all operating systems, the Fyne toolkit aims to empower graphical app creation in a platform-agnostic manner. This definitive guide to building applications with the Fyne toolkit aims to assist software engineers of any experience level in learning the APIs and processes involved. From your first line of Fyne code through to deploying an application to global marketplaces, the samples and screenshots will guide you on each step of the journey.

Who this book is for

This book is written both for Go developers who are interested in building native graphical applications and for those with platform-specific GUI experience looking for a cross-platform solution. Some knowledge of building Go applications is assumed, but not essential. The book opens with a history of the GUI for anyone who is not familiar, and then introduces the Fyne project and its vision and ambition to solve many of the challenges faced by developers of native applications across desktop and mobile devices.

With the help of code snippets and worked examples, developers of every level should be successful in building their first Fyne apps. As well as running these apps on your computers and mobile devices, you will also be taken through the preparation and upload process to deploy to app stores and marketplaces.

What this book covers

Chapter 1, A Brief History of GUI Toolkits and Cross-Platform Development, contains a short reminder of the history behind graphical applications and how the toolkits used to develop them have evolved over time. We look at the different approaches to cross-platform development and why it is important. By the end of this chapter, you will be familiar with the benefits and challenges of GUI toolkits in approaching cross-platform app development.

Chapter 2, The Future According to Fyne, introduces the Fyne toolkit and its approach to supporting all operating systems, with a Material Design-inspired user interface look and feel. In this chapter, we will explore the vision of the Fyne toolkit and how it builds on the Go language to create an easy-to-use, cross-platform GUI toolkit. After reading this chapter, you will see how Fyne aims to solve the challenges outlined in the first chapter of the book and how it aims to shape app development in the future.

Chapter 3, Window, Canvas, and Drawing, introduces the main APIs behind the rendering layer of the Fyne toolkit. We will see how to draw objects and how to combine them using containers to create more complex output. This chapter also covers the APIs required to load an application and manage its windows. We complete this chapter with an example that uses graphic elements and animations to create a simple cross-platform game.

Chapter 4, Layout and File Handling, expands on the manual placement of elements in the previous chapter. We will examine the standard layouts that are provided and how they are combined to form complex user interface structures, as well as how to build our own. Also covered is the filesystem abstraction, which provides standard file access for traditional filesystems and the more complex mobile data sharing methodologies. We will apply all this knowledge to create an image browsing app at the end of the chapter.

Chapter 5, Widget Library and Themes, introduces the largest package within the Fyne toolkit – its widget library. In this chapter, we will explore the main widgets available and how to use them in constructing an application GUI. We will see how their standardized look and feel can be influenced through theme selection and how user preferences, such as light or dark modes, are rendered using the built-in theme. This chapter is completed with a step-by-step creation of a task management app using many of the widgets explored earlier.

Chapter 6, Data Binding and Storage, explores APIs that help to efficiently manage data and storage within a Fyne app. We will see how the widgets seen in the previous chapter can be bound to data elements and thereby avoid much of the code that was necessary to set up and manage their contents. Also demonstrated is how applications can manage user preferences and how they can connect through data binding directly to widget values. The concepts in this chapter are applied through the creation of a health app that helps to track your water consumption.

Chapter 7, Building Custom Widgets and Themes, demonstrates how applications with bespoke requirements can build on the solid foundations explored in the previous chapters. We will examine the various ways in which developers can customize and extend existing widgets, or build completely bespoke components. We will also see how custom themes can be loaded to give apps more brand identity or add custom fonts and icons. Using these features, we will build an instant messenger user interface that displays a distinct style and custom widgets.

Chapter 8, Project Structure and Best Practices, builds on the best practices that are well documented for the Go language. We will see how to organize projects to keep the code clean and facilitate easier maintenance as they grow. We will also explore how unit testing and test-driven development are possible and encouraged when building GUIs with Fyne. Additionally, on the rare occasion where platform-specific code may be required, we see how an app can adjust its behavior for different target platforms.

Chapter 9, Bundling Resources and Preparing for Release, explains how packaging up a graphical application is more complex than a simple binary that would be accessed from the command line. In this chapter, we see what metadata is required to allow a Fyne app to blend in with other desktop and mobile applications. We also step through the process for bundling apps so that they can be shared and installed, as end users would expect of a platform native application.

Chapter 10, Distribution – App Stores and Beyond, confronts the final challenge of cross-platform application development – distribution. We will see how applications are prepared for public release and packaged with extra data and code signing required by many app stores. We wrap up the book by stepping through the upload process for Apple, Google, and Microsoft stores, along with distribution to Unix systems.

Appendix A, Developer Tool Installation, contains platform-specific steps for managing software required by other chapters. This chapter will assist new developers to install the compilers and tools required to build the examples in this book.

Appendix B, Installation of Mobile Build Tools, provides documentation for setting up the additional tools that will be required to build Fyne apps for mobile devices. Android and iOS builds can be created locally after following these steps. Alternatively developers could choose to use fyne-cross, covered in Appendix C, Cross-Compiling.

Appendix C, Cross-Compiling, outlines the platform specific installation and configuration that is required to set up the building of different operating systems. Following these steps, developers will be able to compile their Fyne apps for different platforms using just one computer. It also shows how to set up the Fyne cross compiling solution fyne-cross for developers that don't want to manage the tools in detail themselves.

To get the most out of this book

A basic knowledge of the Go language is assumed throughout this book. If you are not yet familiar with the syntax or concepts, consider running through the online tutorial before you begin reading (tour.golang.org).

To run the examples, you will need at least version 1.12 of Go installed, as well as a C compiler for your computer (required by the Fyne library code). If either of these are not installed, you can find detailed steps in Appendix A, Developer Tool Installation. We will step through the process of installing the Fyne library and its supporting tools as they are required throughout the book:

To develop applications, you will need a Windows, macOS, or Linux computer with the development tools described previously. To test applications on mobile devices, you will also need the Android SDK and/or Xcode (for iOS/iPadOS) environment installed. For more information, refer to Appendix B, Installation of Mobile Build Tools. For the further testing of mobile builds, it is advisable to have a suitable mobile device available.

To derive additional benefits from this book, it would be ideal if you have in mind an app project you are aiming to build. Doing so will help to practice the example code in different settings to better understand the widget and API capabilities. Additionally, this will mean that the app store upload process at the end of this book will result in a published version of your application!

If you are using the digital version of this book, we advise you to access the code via the GitHub repository (link available in the next section). Doing so will help you avoid any potential errors related to the copying and pasting of code.

Download the example code files

You can download the example code files for this book from GitHub at https://github.com/PacktPublishing/Building-Cross-Platform-GUI-Applications-with-Fyne. In case there's an update to the code, it will be updated on the existing GitHub repository.

We also have other code bundles from our rich catalog of books and videos available at https://github.com/PacktPublishing/. Check them out!

Download the color images

We also provide a PDF file that has color images of the screenshots/diagrams used in this book. You can download it here: https://static.packt-cdn.com/downloads/9781800563162_ColorImages.pdf

Conventions used

There are a number of text conventions used throughout this book.

Code in text: Indicates code words in text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles. Here is an example: “Using method-based updates, SetText() and SetIcon() calls will refresh the widget, possibly triggering the preceding issue.”

A block of code is set as follows:

const (

serverKeyDevelopment = "DEVELOPMENT_KEY"

serverKeyProduction = "PRODUCTION_KEY"

)

Any command-line input or output is written as follows:

$ fyne release -appVersion 1.0 -appBuild 1 -certificate "CertificateName" -profile "ProfileName"

When a command relates to files or data within the GitHub repository (linked above and at the top of each chapter), the command prompt will start with the directory name, as follows:

Chapter03/window$ go run main.go

Bold: Indicates a new term, an important word, or words that you see on screen. For example, words in menus or dialog boxes appear in the text like this. Here is an example: “You can also find the Settings panel in the Settings menu within fyne_demo.”

Tips or important notes

Appear like this.

Get in touch

Feedback from our readers is always welcome.

General feedback: If you have questions about any aspect of this book, mention the book title in the subject of your message and email us at [email protected].

Errata: Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you have found a mistake in this book, we would be grateful if you would report this to us. Please visit www.packtpub.com/support/errata, selecting your book, clicking on the Errata Submission Form link, and entering the details.

Piracy: If you come across any illegal copies of our works in any form on the internet, we would be grateful if you would provide us with the location address or website name. Please contact us at [email protected] with a link to the material.

If you are interested in becoming an author: If there is a topic that you have expertise in, and you are interested in either writing or contributing to a book, please visit authors.packtpub.com.

Reviews

Please leave a review. Once you have read and used this book, why not leave a review on the site that you purchased it from? Potential readers can then see and use your unbiased opinion to make purchase decisions, we at Packt can understand what you think about our products, and our authors can see your feedback on their book. Thank you!

For more information about Packt, please visit packt.com.

..................Content has been hidden....................

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