Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: 4be0341011
Fetching contributors…

Cannot retrieve contributors at this time

file 40 lines (30 sloc) 1.046 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
using Gtk;

public class PanelClock : Label {

    private const int MARGIN = 10;
    private Pango.Layout pango;

public PanelClock () {
        pango = new Pango.Layout (get_pango_context ());
        pango.set_alignment (Pango.Alignment.CENTER);
Timeout.add (1000 * 30, update);
        update ();

}

private bool update () {
char bufferClock[100];
Time t = Time.local (time_t ());
t.strftime (bufferClock, _("%a, %e %b %Y %H:%M"));

        StyleContext style = get_style_context ();
        pango.set_font_description (style.get_font (get_state_flags ()));
        pango.set_markup ((string) bufferClock, -1);

        int text_w, text_h;
        pango.get_pixel_size (out text_w, out text_h);

        set_size_request (text_w + MARGIN, text_h);
        queue_draw ();
return true;
}

public override bool draw (Cairo.Context cr) {
        StyleContext style = get_style_context ();
        style.set_state (get_state_flags ());
        Gtk.render_layout (style, cr, MARGIN/2, 0, pango);
        return true;
    }

}
Something went wrong with that request. Please try again.