WIP: Water level widget

This commit is contained in:
Gergely Polonkai 2018-07-27 13:58:49 +02:00
parent 5fef988c0b
commit 10cbb64f9a
5 changed files with 80 additions and 10 deletions

View File

@ -7,18 +7,13 @@
<object class="GtkHeaderBar" id="header_bar">
<property name="visible">True</property>
<property name="show-close-button">True</property>
<property name="title">Hello, World!</property>
<property name="title">Water Reminder</property>
</object>
</child>
<child>
<object class="GtkLabel" id="label">
<property name="label">Hello, World!</property>
<object class="GwrWaterLevel" id="level">
<property name="visible">True</property>
<attributes>
<attribute name="weight" value="bold"/>
<attribute name="scale" value="2"/>
</attributes>
</object>
</child>
</template>
</interface>
</interface>

60
src/gwr-water-level.c Normal file
View File

@ -0,0 +1,60 @@
#include "gwr-water-level.h"
struct _GwrWaterLevel {
GtkWidget parent_instance;
};
G_DEFINE_TYPE(GwrWaterLevel, gwr_water_level, GTK_TYPE_WIDGET)
static gboolean
gwr_water_level_draw(GtkWidget *widget, cairo_t *cr)
{
GtkStyleContext *context = gtk_widget_get_style_context(widget);
gint width = gtk_widget_get_allocated_width(widget);
gint height = gtk_widget_get_allocated_height(widget);
GdkRGBA color;
gtk_render_background(context, cr, 0, 0, width, height);
gtk_render_frame(context, cr, 0, 0, width, height);
cairo_arc(cr, width / 2.0, height / 2.0, MIN(width, height) / 2.0, 0, 2 * G_PI);
gtk_style_context_get_color(context, gtk_style_context_get_state(context), &color);
gdk_cairo_set_source_rgba(cr, &color);
gdk_cairo_set_source_rgba(cr, &color);
cairo_fill (cr);
return FALSE;
}
static void
gwr_water_level_finalize(GObject *gobject)
{
// Here, you free memory that is associated with your instance.
//
// References to other objects should be freed in dispose instead.
G_OBJECT_CLASS(gwr_water_level_parent_class)->finalize(gobject);
}
static void
gwr_water_level_destroy(GtkWidget *widget)
{
// Here you drop references to other objects.
GTK_WIDGET_CLASS(gwr_water_level_parent_class)->destroy(widget);
}
static void
gwr_water_level_class_init(GwrWaterLevelClass *klass)
{
GObjectClass *gobject_class = G_OBJECT_CLASS(klass);
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS(klass);
gobject_class->finalize = gwr_water_level_finalize;
widget_class->destroy = gwr_water_level_destroy;
widget_class->draw = gwr_water_level_draw;
}
static void
gwr_water_level_init(GwrWaterLevel *self)
{}

13
src/gwr-water-level.h Normal file
View File

@ -0,0 +1,13 @@
#ifndef __GWR_WATER_LEVEL_H__
# define __GWR_WATER_LEVEL_H__
# include <gtk/gtk.h>
G_BEGIN_DECLS
# define GWR_TYPE_WATER_LEVEL (gwr_water_level_get_type())
G_DECLARE_FINAL_TYPE(GwrWaterLevel, gwr_water_level, GWR, WATER_LEVEL, GtkWidget)
G_END_DECLS
#endif /* __GWR_WATER_LEVEL_H__ */

View File

@ -18,6 +18,7 @@
#include "gwr-config.h"
#include "gwr-window.h"
#include "gwr-water-level.h"
struct _GwrWindow
{
@ -25,7 +26,7 @@ struct _GwrWindow
/* Template widgets */
GtkHeaderBar *header_bar;
GtkLabel *label;
GwrWaterLevel *level;
};
G_DEFINE_TYPE (GwrWindow, gwr_window, GTK_TYPE_APPLICATION_WINDOW)
@ -37,7 +38,7 @@ gwr_window_class_init (GwrWindowClass *klass)
gtk_widget_class_set_template_from_resource (widget_class, "/eu/polonkai/gergely/GnomeWaterReminder/gwr-window.ui");
gtk_widget_class_bind_template_child (widget_class, GwrWindow, header_bar);
gtk_widget_class_bind_template_child (widget_class, GwrWindow, label);
gtk_widget_class_bind_template_child (widget_class, GwrWindow, level);
}
static void

View File

@ -2,6 +2,7 @@ gwr_sources = [
gwr_resources,
'main.c',
'gwr-window.c',
'gwr-water-level.c',
]
gwr_deps = [