Namespaces

The Go-GTK project contains a number of namespaces used to organize the code and make it easier for developers to find what they're looking for. These sub-projects or packages reflect the naming within the main GTK+ project, so those familiar with this can skip this section. Most of the examples so far used just gtk, which is clearly the main package to use for building a user interface but, as we saw before, glib may be important too (for things not specifically about widgets).

Let's look at what each namespace covers and see where it might be useful in application development:

gdk

GDK stands for GIMP Drawing Kit; it's a low-level component of GTK+ that handles the details of rendering on each platform that is supported. This provides an abstraction of the operating system details, therefore allowing other areas of GTK+ to be platform agnostic. This package will be useful if your application needs to draw any custom elements.

gdkpixbuf

Pixbuf refers to an in-memory buffer containing pixel data for rendering images. This package provides some convenience functions for managing images that can be loaded into a Go-GTK application. Of note is the gdkpixbuf.NewPixbufFromData function, which, combined with the make_inline_pixbuf tool, allows the loading of images embedded in the application.

gio

gio represents an input/output abstraction for GTK+ applications. It provides access to local and remote files with a consistent API.

glib

glib is the supporting library for all GTK+ features and applications. It implements the object-oriented system as well as various data structures and utilities. As the Go language defines many of these natively, the glib package within Go-GTK is responsible for translating from Go to glib (C) structures. This is where thread management and message passing are handled, but most of these features are hidden by the higher-level functions of the library.

gtk

The main namespace for widgets in the GTK+ library. As we've already seen, it presents a cross-platform toolkit for creating graphical applications, which is made possible by the other packages listed here.

pango

Pango is a font rendering library, which provides high-quality text glyphs for GTK+ applications. It's unlikely that you would need to call any of these APIs directly; it is mainly used internally for rendering text within GTK+.

 

Having looked at the main packages within Go-GTK (and seen that an application will probably only need to use gtk, glib, and gdk), we will see how this comes together in a larger application.

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

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