Skip to content
This repository has been archived by the owner on Aug 13, 2019. It is now read-only.

added basic support of GtkCssProvider #26

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

solusipse
Copy link

Simple example of gradient background:

package main

import (
    "github.com/conformal/gotk3/gtk"
    "github.com/conformal/gotk3/gdk"
    "log"
)

func main() {
    // Initialize GTK without parsing any command line arguments.
    gtk.Init(nil)

    // Create a new toplevel window, set its title, and connect it to the
    // "destroy" signal to exit the GTK main loop when it is destroyed.
    win, err := gtk.WindowNew(gtk.WINDOW_TOPLEVEL)
    if err != nil {
        log.Fatal("Unable to create window:", err)
    }
    win.SetTitle("Simple Example")
    win.Connect("destroy", func() {
        gtk.MainQuit()
    })

    // Create a new label widget to show in the window.
    l, err := gtk.LabelNew("Hello, gotk3!")
    if err != nil {
        log.Fatal("Unable to create label:", err)
    }

    // Add the label to the window.
    win.Add(l)

    // Set the default window size.
    win.SetDefaultSize(800, 600)

    provider, _ := gtk.NewCssProvider()
    display, _ := gdk.DisplayGetDefault()
    screen, _ := display.GetDefaultScreen()

    provider.AddToScreen(screen)
    provider.LoadFromData(" GtkWindow {background: -gtk-gradient (linear,0 0,0 1,color-stop(0, #333),color-stop(0.2, #666))}")

    // Recursively show all widgets contained in this window.
    win.ShowAll()

    // Begin executing the GTK main loop.  This blocks until
    // gtk.MainQuit() is run. 
    gtk.Main()
}

@jrick
Copy link
Member

jrick commented Dec 11, 2013

I merged these changes against the latest master branch, but found that there were several issues with the code so they haven't been committed to the master branch yet. See http://sprunge.us/FajA for a diff.

Besides just the generic improvements (adding comments, etc.) I also changed CssProvider to embed a *glib.Object, rather than saving the *C.GtkCssProvider itself. Additionally, some of the wrappers that optionally take GErrors now also return a Go error created from the GError's message if they were set. Finally, I removed your AddToScreen wrapper for now. I believe we want to use GInterfaces here. See some of the other gotk3 objects that interfaces are implemented for (such as ComboBox, Grid, ListStore, etc.).

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants