[gnome-calendar/ui-rewrite] event-widget: make more CSS compliant
- From: Erick Pérez Castellanos <erickpc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-calendar/ui-rewrite] event-widget: make more CSS compliant
- Date: Wed, 29 Oct 2014 13:42:20 +0000 (UTC)
commit ca6cad2ed300ba3194d8c9f89f935fe22fed1e1a
Author: Erick Pérez Castellanos <erick red gmail com>
Date: Tue Oct 28 23:06:54 2014 -0400
event-widget: make more CSS compliant
There are some other changes:
1. Renamed widget class to "event-widget" to avoid collisions
2. Added contrasting event title coloring
3. Use gtk_render functions
data/theme/gtk-styles.css | 23 +++++++++++++++--
src/gcal-event-widget.c | 60 ++++++++++++++++++++++++++++++---------------
2 files changed, 60 insertions(+), 23 deletions(-)
---
diff --git a/data/theme/gtk-styles.css b/data/theme/gtk-styles.css
index 7467266..99b4dd3 100644
--- a/data/theme/gtk-styles.css
+++ b/data/theme/gtk-styles.css
@@ -36,15 +36,32 @@
font: bold;
}
-.event {
- border: darker(@borders) 1px solid;
+.event-widget {
border-radius: 2px;
margin-top: 3px;
margin-left: 6px;
margin-bottom: 3px;
margin-right: 6px;
padding: 4px;
- font: 9;
+ font: 10;
+}
+
+GcalEventWidget.color-dark {
+ color: white;
+ outline-color: rgba(0, 0, 0, 0.3);
+}
+
+GcalEventWidget.color-dark:backdrop {
+ color: rgba(255, 255, 255, 0.3);
+}
+
+GcalEventWidget.color-light {
+ color: black;
+ outline-color: rgba(255, 255, 255, 0.5);
+}
+
+GcalEventWidget.color-light:backdrop {
+ color: rgba(0, 0, 0, 0.3);
}
.event-details .frame {
diff --git a/src/gcal-event-widget.c b/src/gcal-event-widget.c
index 0da49c5..ceee7e0 100644
--- a/src/gcal-event-widget.c
+++ b/src/gcal-event-widget.c
@@ -20,6 +20,8 @@
#include "gcal-event-widget.h"
#include "gcal-utils.h"
+#define INTENSITY(r, g, b) ((r) * 0.30 + (g) * 0.59 + (b) * 0.11)
+
typedef struct
{
/* properties */
@@ -216,7 +218,7 @@ gcal_event_widget_init(GcalEventWidget *self)
gtk_style_context_add_class (
gtk_widget_get_style_context (GTK_WIDGET (self)),
- "event");
+ "event-widget");
}
static void
@@ -257,15 +259,39 @@ gcal_event_widget_set_property (GObject *object,
priv->summary = g_value_dup_string (value);
return;
case PROP_COLOR:
- if (priv->color != NULL)
- gdk_rgba_free (priv->color);
-
- priv->color = g_value_dup_boxed (value);
- gtk_widget_override_background_color (
- GTK_WIDGET (object),
- gtk_widget_get_state_flags (GTK_WIDGET (object)),
- priv->color);
- return;
+ {
+ GtkStyleContext *context;
+
+ context = gtk_widget_get_style_context (GTK_WIDGET (object));
+
+ if (priv->color != NULL)
+ gdk_rgba_free (priv->color);
+
+ priv->color = g_value_dup_boxed (value);
+
+ if (priv->color == NULL)
+ return;
+
+ gtk_widget_override_background_color (
+ GTK_WIDGET (object),
+ gtk_widget_get_state_flags (GTK_WIDGET (object)),
+ priv->color);
+
+ if (INTENSITY (priv->color->red,
+ priv->color->green,
+ priv->color->blue) > 0.5)
+ {
+ gtk_style_context_remove_class (context, "color-dark");
+ gtk_style_context_add_class (context, "color-light");
+ }
+ else
+ {
+ gtk_style_context_remove_class (context, "color-light");
+ gtk_style_context_add_class (context, "color-dark");
+ }
+
+ return;
+ }
case PROP_DTSTART:
if (priv->dt_start != NULL)
g_free (priv->dt_start);
@@ -538,7 +564,6 @@ gcal_event_widget_draw (GtkWidget *widget,
PangoLayout *layout;
PangoRectangle logical_rect;
PangoFontDescription *font_desc;
- GdkRGBA fg_color;
priv = gcal_event_widget_get_instance_private (GCAL_EVENT_WIDGET (widget));
context = gtk_widget_get_style_context (widget);
@@ -546,7 +571,6 @@ gcal_event_widget_draw (GtkWidget *widget,
gtk_style_context_get_padding (context, state, &padding);
gtk_style_context_get_margin (context, state, &margin);
- gtk_style_context_get_color (context, state, &fg_color);
x = margin.left;
y = margin.top;
@@ -577,14 +601,10 @@ gcal_event_widget_draw (GtkWidget *widget,
pango_layout_set_width (layout, (width - (padding.left + padding.right + left_gap) ) * PANGO_SCALE);
}
- cairo_set_source_rgba (cr,
- fg_color.red,
- fg_color.green,
- fg_color.blue,
- fg_color.alpha);
- cairo_move_to (cr, x + padding.left + left_gap, y + padding.top);
- pango_cairo_show_layout (cr, layout);
-
+ gtk_render_layout (context, cr,
+ x + padding.left + left_gap,
+ y + padding.top,
+ layout);
/* render icon */
if (priv->has_reminders)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]