Skip to content

Commit

Permalink
Add an example of subclassing a gtk widget.
Browse files Browse the repository at this point in the history
Half-baked subclass example.

Remove unneeded types from derived class example.

Move drawing in to a receiver method.

Split derived class and instance across two files.

Use a struct instead of dodgy pointer maths.

Add another virtual function override to example.

Add colour to the example derived widget.

Add more comments explaining subclassing example.

Add some documentation around subclassing.

Reference custom-drawing example from subclassing example.
  • Loading branch information
pekim committed Jun 15, 2019
1 parent 26544a2 commit 575b341
Show file tree
Hide file tree
Showing 20 changed files with 458 additions and 0 deletions.
44 changes: 44 additions & 0 deletions docs-src/subclassing.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
There is no direct support in gobbi for subclassing
GObject derived classes
or for implementing interfaces.
Following exploration and the production of a
proof of concept for class derivation,
it became apparent that an awful lots of work
would have to be put it for a fairly small reward.
Lots more generation code would have to be written,
and many tens of thousands of new lines of code
would be generated.
And even then there would likely be many
cases not covered.

Deriving classes, implementing interfaces,
and implementing virtual functions are
unlikely to be particularly common activities
in gobbi based applications.
So for now at least adding support to make this
easy has been put to one side.

## example
Instead of providing direct support in gobbi, a
[subclassing](https://github.com/pekim/gobbi/blob/master/example/subclass-drawingarea)
example is provided.
This illustrates how the DrawingAreas widget
can be subclassed, some virtual functions implemented.

## pre-requisites
For the most part using gobbi does not require
a detailed knowledge C or gobject.
With some familiarity with Go, Gtk and perhaps
a passing knowledge of cgo,
it should be possible to write an application
with gobbi.

However subclassing and the implementation of
virtual functions will require a bit
more knowledge.

- comfort with Go
- familiarity with C
- familiarity with cgo
- an understanding of the [gobject base class](https://developer.gnome.org/gobject/stable/chapter-gobject.html)

3 changes: 3 additions & 0 deletions docs/api.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions docs/application-lifecycle.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions docs/build-tags.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions docs/casting.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions docs/getting-started.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions docs/goroutines.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions docs/gvalue.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions docs/index.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions docs/reference-counting.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions docs/signal-handling.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

123 changes: 123 additions & 0 deletions docs/subclassing.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions docs/variadic-functions.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 25 additions & 0 deletions example/subclass-drawingarea/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# subclassing example

This example demonstrates an approach for
subclassing a gtk widget.
A subclass of GtkDrawingArea is registered,
and two virtual functions are implemented.

The `draw` virtual function calls a Go function
that marshals the arguments in to Go objects,
and calls another function to draw in a cairo context.
The same result could have been achieved by
connecting to the `draw` signal instead,
(The [custom-drawing](https://github.com/pekim/gobbi/blob/master/example/custom-drawing/main.go)
example uses that approach.)
however the point of this example is to
illustrate class derivation and
the overriding of virtual functions.

The `adjust_size_request` virtual function's
implementation is trivial,
and is implemented entirely in C.

For more background about subclassing with gobbi see
[subclassing](https://pekim.github.io/gobbi/subclassing)
in the documentation.
Loading

0 comments on commit 575b341

Please sign in to comment.