diff --git a/docs-src/application-lifecycle.md b/docs-src/application-lifecycle.md index 1e7c0329..abc2b6fb 100644 --- a/docs-src/application-lifecycle.md +++ b/docs-src/application-lifecycle.md @@ -1,5 +1,5 @@ ## main thread -The main function, and therefore the main loop, +The `main` function, and therefore the main loop, should run on the main thread. ```go @@ -11,7 +11,7 @@ func init() { ``` ## initialisation -Call `gtk.Init` (or `gtk.InitChack`) before calling +Call `gtk.Init` (or `gtk.InitCheck`) before calling any other gtk functions. Typically the program's command-line arguments will be passed to `gtk.Init`. @@ -32,12 +32,14 @@ If an application has only one window, then it might terminate when the window is closed. ```go +// Connect to the window's "destroy" signal. window.Widget().ConnectDestroy(func() { gtk.MainQuit() }) ``` -This may be written more succinctly, like this. +As the callback's signature matches that of `gtk.MainQuit`, +this may be written more succinctly like this. ```go window.Widget().ConnectDestroy(gtk.MainQuit) diff --git a/docs-src/build-tags.md b/docs-src/build-tags.md index aaadd6eb..edf9db23 100644 --- a/docs-src/build-tags.md +++ b/docs-src/build-tags.md @@ -1,7 +1,7 @@ gobbi uses Go [build tags](https://golang.org/pkg/go/build/#hdr-Build_Constraints) to allow targetting of specific library versions. -This means that when using Go build tools +This means that when using Go tools (such as `go build` and `go run`) to build a gobbi application, use of the `-tags` flag will usually be necessary. @@ -26,6 +26,13 @@ is only available from gtk 3.10 onwards. So to use it, a tag specifying 3.10 (or a later version) is required. + +A tag such as `gtk_3.10` is formed of three parts. + +- the library name, `gtk` +- an underscore, `_` +- the minimum library version, `3.10` + ```bash go build -tags gtk_3.10 my_app.go ``` @@ -55,6 +62,7 @@ The relevant setting is `Go: Build Tags`. ### goland In the `Settings...` dialog, the relevant setting can be found under + - Go - - Vendoring & Build Tags - - Custom tags + - Vendoring & Build Tags + - Custom tags diff --git a/docs-src/casting.md b/docs-src/casting.md index 563c606c..bea2a9a2 100644 --- a/docs-src/casting.md +++ b/docs-src/casting.md @@ -1,6 +1,6 @@ Gtk classes derive in a hierarchy from the GObject class. -In gobbi's implementation of GOBject's classes, +In gobbi's implementation of GObject's classes, each class does not directly extend (or embed in Go terms) its ancestor classes. @@ -21,7 +21,7 @@ label := gtk.LabelNew("a label") window.Add(label) // <-- ERROR ``` -`gtk.Window` does not directly have a `Add` method. +`gtk.Window` does not directly have an `Add` method. The `Add` method is a member of `gtk.Container`, which is an ancestor of `gtk.Window`. @@ -50,7 +50,7 @@ widget2 := gtk.WindowNew().Widget() # downcasting Downcasting operates in the other direction, -from a class to a derived class, +from a class to a derived class. Downcasting is less common that upcasting. It is potentially quite dangerous, in that it makes diff --git a/docs-src/getting-started.md b/docs-src/getting-started.md index c532be3d..47c703b9 100644 --- a/docs-src/getting-started.md +++ b/docs-src/getting-started.md @@ -4,7 +4,7 @@ * debian/ubuntu packages - `libatk1.0-dev libcairo2-dev libglib2.0-dev libgtk-3-dev libpango1.0-dev` - * note that dev libraries are required because pkg-config + * note that dev versions of the libraries are required because pkg-config and headers are necessary * C compiler, and a linker * required because of the use of cgo @@ -17,12 +17,15 @@ * `./gobbi example simple_window` * Be patient. The first `go build` or `go run` will take quite a while, - perhaps a few minutes. - Subsequent builds of applications will be a *lot* quicker - as cached gobbi packages will be used by the Go commands. + perhaps a minute. + Subsequent builds of applications will be a lot quicker + as cached gobbi packages will be used by the Go tools. Run `./gobbi examples` for a list of the available examples. +(The gobbi script supports other commands, +but they are only needed for development of gobbi itself.) + ## use in an application Using gobbi in an application in no different to using most other libraries. @@ -38,6 +41,11 @@ Then import a package such as gtk. import "github.com/pekim/gobbi/lib/gtk" ``` +[Application lifecycle](application-lifecycle.html) +describes the minimal apis needed to build +an application that will create a window. + + ## build tags It will often be necessary to build gobbi applications with [build tags](../build-tags). diff --git a/docs-src/goroutines.md b/docs-src/goroutines.md index acd3f622..ed6a75dd 100644 --- a/docs-src/goroutines.md +++ b/docs-src/goroutines.md @@ -1,6 +1,6 @@ All calls to gtk functions should be performed on the main thread. -To perform such a call from a goroutine, +To perform such calls from a goroutine, use `glib.IdleAdd` to schedule invocation of a callback function on the main thread. diff --git a/docs-src/gvalue.md b/docs-src/gvalue.md index 3583065d..46a15e8e 100644 --- a/docs-src/gvalue.md +++ b/docs-src/gvalue.md @@ -1,4 +1,5 @@ -The gobject library's `GValue` type is represented by +The gobject library's `GValue` type is represented +in gobbi by `gobject.Value`. See the [list](https://github.com/pekim/gobbi/blob/master/example/list/main.go) diff --git a/docs-src/signal-handling.md b/docs-src/signal-handling.md index f270b536..344fc843 100644 --- a/docs-src/signal-handling.md +++ b/docs-src/signal-handling.md @@ -10,16 +10,21 @@ information. ```go button := gtk.ButtonNewWithLabel("a button") + +// enable emitting of motion events button.Widget().SetEvents(int32(gdk.GDK_POINTER_MOTION_MASK)) + button.Widget().ConnectMotionNotifyEvent( func(event *gdk.EventMotion) bool { fmt.Println(event.Y, event.Y) return false - }) + } +) ``` -Remember that it may be necessary to upcast to access the -desired connect method. +Remember that it may be necessary to +[upcast](casting.html) +to access the desired connect method. ## disconnecting All of the `Connect...` methods return a handler id. @@ -36,16 +41,18 @@ The id may be used later to disconnect the handler. ``` ## notify signal for a single property -`ConnectNotifyProperty` connects the callback +`ConnectNotifyProperty` connects a callback to the `notify` signal for a specific property of an Object. -For example, to connect to the notify signal -for the "title" property of a window. +This is an example of connecting to the notify signal +for a window's +[title property](https://developer.gnome.org/gtk3/stable/GtkWindow.html#GtkWindow--title). ```go window := gtk.WindowNew(...) + // connect to the "notify::title" signal window.Object().ConnectNotifyProperty( "title", func(pspec *gobject.ParamSpec, ) { @@ -53,9 +60,6 @@ for the "title" property of a window. }) ``` -In that example it is the `notify::title` signal -that is being connected to. - The returned value represents the connection, and may be passed to `DisconnectNotify` to remove it. diff --git a/docs-src/variadic-functions.md b/docs-src/variadic-functions.md index e1a3c7d4..c080712f 100644 --- a/docs-src/variadic-functions.md +++ b/docs-src/variadic-functions.md @@ -15,10 +15,13 @@ This is because `fmt.Sprint` is used to format a string before passing it as the last argument to the wrapped C function. -A much simplified representation of such a function might -help to make this clearer. +A much simplified representation of such a +gobbi function might help to make this clearer. ```go -func SomeRepresentativeFunction( +package gtk + +// a gobbi function +func SomeFormatFunction( a string, b int, format string, args ...interface{}, ) { @@ -28,7 +31,17 @@ func SomeRepresentativeFunction( formattedString := fmt.Sprintf(format, args...) c_formattedString := C.String(formattedString) - C.some_representative_function(c_a, c_b, c_formattedString) + C.some_format_function(c_a, c_b, c_formattedString) +} + +// ----------------------------- // + +// some application code +func aFunction () { + gtk.SomeFormatFunction( + "a string", 123, + "the %s is %d", "answer", 42, + ) } ``` @@ -38,7 +51,7 @@ because it would be impractical to automatically generate code that would support them. ### array functions -In some cases there is another function that accepts an array +In some cases there is an alternative function that accepts an array as the final argument instead. For example [gtk_list_store_new](https://developer.gnome.org/gtk3/stable/GtkListStore.html#gtk-list-store-new) @@ -47,7 +60,7 @@ is not supported, but is supported as [gtk.ListStoreNewv](https://godoc.org/github.com/pekim/gobbi/lib/gtk#ListStoreNewv). ### multiple functions -There are other variadac functions that do not have an array +There are other variadac functions that may not have an array equivalent version, but their functionality can be achieved through a combination of functions. diff --git a/docs/api.html b/docs/api.html index d4f6f579..784c7bd6 100644 --- a/docs/api.html +++ b/docs/api.html @@ -42,9 +42,6 @@
  • Goroutines
  • -
  • - gobject.Value -
  • Casting
  • @@ -54,6 +51,9 @@
  • Variadic functions
  • +
  • + gobject.Value +
  • Reference counting
  • diff --git a/docs/application-lifecycle.html b/docs/application-lifecycle.html index 00db8cfb..4ebf23ca 100644 --- a/docs/application-lifecycle.html +++ b/docs/application-lifecycle.html @@ -42,9 +42,6 @@
  • Goroutines
  • -
  • - gobject.Value -
  • Casting
  • @@ -54,6 +51,9 @@
  • Variadic functions
  • +
  • + gobject.Value +
  • Reference counting
  • @@ -68,7 +68,7 @@

    Application lifecycle

    main thread

    -

    The main function, and therefore the main loop, +

    The main function, and therefore the main loop, should run on the main thread.

    func init() {
    @@ -80,7 +80,7 @@ 

    main thread

    initialisation

    -

    Call gtk.Init (or gtk.InitChack) before calling +

    Call gtk.Init (or gtk.InitCheck) before calling any other gtk functions. Typically the program’s command-line arguments will be passed to gtk.Init.

    @@ -100,12 +100,14 @@

    termination

    If an application has only one window, then it might terminate when the window is closed.

    -
    window.Widget().ConnectDestroy(func() {
    +
    // Connect to the window's "destroy" signal.
    +window.Widget().ConnectDestroy(func() {
         gtk.MainQuit()
     })
     
    -

    This may be written more succinctly, like this.

    +

    As the callback’s signature matches that of gtk.MainQuit, +this may be written more succinctly like this.

    window.Widget().ConnectDestroy(gtk.MainQuit)
     
    diff --git a/docs/build-tags.html b/docs/build-tags.html index 676e8f49..269546ec 100644 --- a/docs/build-tags.html +++ b/docs/build-tags.html @@ -42,9 +42,6 @@
  • Goroutines
  • -
  • - gobject.Value -
  • Casting
  • @@ -54,6 +51,9 @@
  • Variadic functions
  • +
  • + gobject.Value +
  • Reference counting
  • @@ -69,7 +69,7 @@

    Build tags

    gobbi uses Go build tags to allow targetting of specific library versions. -This means that when using Go build tools +This means that when using Go tools (such as go build and go run) to build a gobbi application, use of the -tags flag will usually be necessary.

    @@ -96,6 +96,14 @@

    tags targetting versions

    So to use it, a tag specifying 3.10 (or a later version) is required.

    +

    A tag such as gtk_3.10 is formed of three parts.

    + +
      +
    • the library name, gtk
    • +
    • an underscore, _
    • +
    • the minimum library version, 3.10
    • +
    +
    go build -tags gtk_3.10 my_app.go
     
    @@ -126,10 +134,19 @@

    vs code

    goland

    In the Settings... dialog, the relevant setting can -be found under -- Go - - Vendoring & Build Tags - - Custom tags

    +be found under

    + +
      +
    • Go + +
        +
      • Vendoring & Build Tags + +
          +
        • Custom tags
        • +
      • +
    • +
    diff --git a/docs/casting.html b/docs/casting.html index 963b477b..f24a59f2 100644 --- a/docs/casting.html +++ b/docs/casting.html @@ -42,9 +42,6 @@
  • Goroutines
  • -
  • - gobject.Value -
  • Casting
  • @@ -54,6 +51,9 @@
  • Variadic functions
  • +
  • + gobject.Value +
  • Reference counting
  • @@ -68,7 +68,7 @@

    Casting

    Gtk classes derive in a hierarchy from the GObject class.

    -

    In gobbi’s implementation of GOBject’s classes, +

    In gobbi’s implementation of GObject’s classes, each class does not directly extend (or embed in Go terms) its ancestor classes. @@ -89,7 +89,7 @@

    upcasting

    window.Add(label) // <-- ERROR
    -

    gtk.Window does not directly have a Add method. +

    gtk.Window does not directly have an Add method. The Add method is a member of gtk.Container, which is an ancestor of gtk.Window.

    @@ -118,7 +118,7 @@

    upcasting

    downcasting

    Downcasting operates in the other direction, -from a class to a derived class,

    +from a class to a derived class.

    Downcasting is less common that upcasting. It is potentially quite dangerous, in that it makes diff --git a/docs/getting-started.html b/docs/getting-started.html index 1ef8d248..f63859c7 100644 --- a/docs/getting-started.html +++ b/docs/getting-started.html @@ -42,9 +42,6 @@

  • Goroutines
  • -
  • - gobject.Value -
  • Casting
  • @@ -54,6 +51,9 @@
  • Variadic functions
  • +
  • + gobject.Value +
  • Reference counting
  • @@ -76,7 +76,7 @@

    pre-requisites

  • debian/ubuntu packages - libatk1.0-dev libcairo2-dev libglib2.0-dev libgtk-3-dev libpango1.0-dev
  • -
  • note that dev libraries are required because pkg-config +
  • note that dev versions of the libraries are required because pkg-config and headers are necessary
  • C compiler, and a linker @@ -98,14 +98,17 @@

    running examples

    • Be patient. The first go build or go run will take quite a while, -perhaps a few minutes. -Subsequent builds of applications will be a lot quicker -as cached gobbi packages will be used by the Go commands.
    • +perhaps a minute. +Subsequent builds of applications will be a lot quicker +as cached gobbi packages will be used by the Go tools.
  • Run ./gobbi examples for a list of the available examples.

    +

    (The gobbi script supports other commands, +but they are only needed for development of gobbi itself.)

    +

    use in an application

    Using gobbi in an application in no different to using @@ -122,6 +125,10 @@

    use in an application

    import "github.com/pekim/gobbi/lib/gtk"
     
    +

    Application lifecycle +describes the minimal apis needed to build +an application that will create a window.

    +

    build tags

    It will often be necessary to build gobbi applications diff --git a/docs/goroutines.html b/docs/goroutines.html index 9a0c2d52..2369f310 100644 --- a/docs/goroutines.html +++ b/docs/goroutines.html @@ -42,9 +42,6 @@

  • Goroutines
  • -
  • - gobject.Value -
  • Casting
  • @@ -54,6 +51,9 @@
  • Variadic functions
  • +
  • + gobject.Value +
  • Reference counting
  • @@ -68,7 +68,7 @@

    Goroutines

    All calls to gtk functions should be performed on the main thread. -To perform such a call from a goroutine, +To perform such calls from a goroutine, use glib.IdleAdd to schedule invocation of a callback function on the main thread.

    diff --git a/docs/gvalue.html b/docs/gvalue.html index 57010ca5..25f6831e 100644 --- a/docs/gvalue.html +++ b/docs/gvalue.html @@ -42,9 +42,6 @@
  • Goroutines
  • -
  • - gobject.Value -
  • Casting
  • @@ -54,6 +51,9 @@
  • Variadic functions
  • +
  • + gobject.Value +
  • Reference counting
  • @@ -66,7 +66,8 @@

    gobject.Value

    -

    The gobject library’s GValue type is represented by +

    The gobject library’s GValue type is represented +in gobbi by gobject.Value.

    See the list diff --git a/docs/index.html b/docs/index.html index 8a027897..ec1feb81 100644 --- a/docs/index.html +++ b/docs/index.html @@ -42,9 +42,6 @@

  • Goroutines
  • -
  • - gobject.Value -
  • Casting
  • @@ -54,6 +51,9 @@
  • Variadic functions
  • +
  • + gobject.Value +
  • Reference counting
  • diff --git a/docs/reference-counting.html b/docs/reference-counting.html index a375f8ae..6b85939b 100644 --- a/docs/reference-counting.html +++ b/docs/reference-counting.html @@ -42,9 +42,6 @@
  • Goroutines
  • -
  • - gobject.Value -
  • Casting
  • @@ -54,6 +51,9 @@
  • Variadic functions
  • +
  • + gobject.Value +
  • Reference counting
  • diff --git a/docs/signal-handling.html b/docs/signal-handling.html index 00a0cc33..14769ca1 100644 --- a/docs/signal-handling.html +++ b/docs/signal-handling.html @@ -42,9 +42,6 @@
  • Goroutines
  • -
  • - gobject.Value -
  • Casting
  • @@ -54,6 +51,9 @@
  • Variadic functions
  • +
  • + gobject.Value +
  • Reference counting
  • @@ -78,16 +78,21 @@

    connecting

    information.

    button := gtk.ButtonNewWithLabel("a button")
    +
    +// enable emitting of motion events
     button.Widget().SetEvents(int32(gdk.GDK_POINTER_MOTION_MASK))
    +
     button.Widget().ConnectMotionNotifyEvent(
         func(event *gdk.EventMotion) bool {
             fmt.Println(event.Y, event.Y)
             return false
    -    })
    +    }
    +)
     
    -

    Remember that it may be necessary to upcast to access the -desired connect method.

    +

    Remember that it may be necessary to +upcast +to access the desired connect method.

    disconnecting

    @@ -105,15 +110,17 @@

    disconnecting

    notify signal for a single property

    -

    ConnectNotifyProperty connects the callback +

    ConnectNotifyProperty connects a callback to the notify signal for a specific property of an Object.

    -

    For example, to connect to the notify signal -for the “title” property of a window.

    +

    This is an example of connecting to the notify signal +for a window’s +title property.

        window := gtk.WindowNew(...)
     
    +    // connect to the "notify::title" signal
         window.Object().ConnectNotifyProperty(
             "title", func(pspec *gobject.ParamSpec,
         ) {
    @@ -121,9 +128,6 @@ 

    notify signal for a single property

    })
    -

    In that example it is the notify::title signal -that is being connected to.

    -

    The returned value represents the connection, and may be passed to DisconnectNotify to remove it.

    diff --git a/docs/style.css b/docs/style.css index 5c26ad9a..994100ec 100644 --- a/docs/style.css +++ b/docs/style.css @@ -8,7 +8,7 @@ body { flex-direction: column; font-family: "Helvetica Neue Light", "HelveticaNeue-Light", "Helvetica Neue", Calibri, Helvetica, Arial, sans-serif; - font-size: 18px; + font-size: 16px; line-height: 1.5; } @@ -84,7 +84,7 @@ nav ol li { } .content { - max-width: 50em; + max-width: 45em; margin-left: 15em; padding-left: 2em; diff --git a/docs/variadic-functions.html b/docs/variadic-functions.html index 75b8b66e..5edd8025 100644 --- a/docs/variadic-functions.html +++ b/docs/variadic-functions.html @@ -42,9 +42,6 @@
  • Goroutines
  • -
  • - gobject.Value -
  • Casting
  • @@ -54,6 +51,9 @@
  • Variadic functions
  • +
  • + gobject.Value +
  • Reference counting
  • @@ -84,10 +84,13 @@

    format functions

    before passing it as the last argument to the wrapped C function.

    -

    A much simplified representation of such a function might -help to make this clearer.

    +

    A much simplified representation of such a +gobbi function might help to make this clearer.

    + +
    package gtk
     
    -
    func SomeRepresentativeFunction(
    +// a gobbi function
    +func SomeFormatFunction(
     	a string, b int,
     	format string, args ...interface{},
     ) {
    @@ -97,7 +100,17 @@ 

    format functions

    formattedString := fmt.Sprintf(format, args...) c_formattedString := C.String(formattedString) - C.some_representative_function(c_a, c_b, c_formattedString) + C.some_format_function(c_a, c_b, c_formattedString) +} + +// ----------------------------- // + +// some application code +func aFunction () { + gtk.SomeFormatFunction( + "a string", 123, + "the %s is %d", "answer", 42, + ) }
    @@ -109,7 +122,7 @@

    unsupported variadic functions

    array functions

    -

    In some cases there is another function that accepts an array +

    In some cases there is an alternative function that accepts an array as the final argument instead. For example gtk_list_store_new @@ -119,7 +132,7 @@

    array functions

    multiple functions

    -

    There are other variadac functions that do not have an array +

    There are other variadac functions that may not have an array equivalent version, but their functionality can be achieved through a combination of functions.

    diff --git a/internal/cmd/docs/main.go b/internal/cmd/docs/main.go index 51d6b9d7..e63046d3 100644 --- a/internal/cmd/docs/main.go +++ b/internal/cmd/docs/main.go @@ -23,10 +23,10 @@ var pages = []Page{ Page{File: "application-lifecycle", Title: "Application lifecycle"}, Page{File: "build-tags", Title: "Build tags"}, Page{File: "goroutines", Title: "Goroutines"}, - Page{File: "gvalue", Title: "gobject.Value"}, Page{File: "casting", Title: "Casting"}, Page{File: "signal-handling", Title: "Signal handling"}, Page{File: "variadic-functions", Title: "Variadic functions"}, + Page{File: "gvalue", Title: "gobject.Value"}, Page{File: "reference-counting", Title: "Reference counting"}, Page{File: "api", Title: "API docs"}, }