[gnome-todo] Introduce GtdStarWidget
- From: Georges Basile Stavracas Neto <gbsneto src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-todo] Introduce GtdStarWidget
- Date: Sat, 2 May 2020 21:28:18 +0000 (UTC)
commit 8f23f330af758a838525cc8b8366b9e602f42d43
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date: Sat May 2 12:15:02 2020 -0300
Introduce GtdStarWidget
A simple star-like widget for important tasks.
src/gnome-todo.h | 1 +
src/meson.build | 4 +
src/theme/Adwaita-widgets.css | 27 +++++
src/theme/Adwaita.css | 1 +
src/todo.gresource.xml | 1 +
src/widgets/gtd-star-widget.c | 193 +++++++++++++++++++++++++++++++++++
src/widgets/gtd-star-widget.h | 37 +++++++
tests/interactive/test-star-widget.c | 53 ++++++++++
tests/meson.build | 7 +-
9 files changed, 322 insertions(+), 2 deletions(-)
---
diff --git a/src/gnome-todo.h b/src/gnome-todo.h
index 3745613..e8203df 100644
--- a/src/gnome-todo.h
+++ b/src/gnome-todo.h
@@ -35,6 +35,7 @@
#include "gtd-panel.h"
#include "gtd-provider.h"
#include "gtd-provider-popover.h"
+#include "gtd-star-widget.h"
#include "gtd-task.h"
#include "gtd-task-list.h"
#include "gtd-task-list-view.h"
diff --git a/src/meson.build b/src/meson.build
index 50b51a7..13ec873 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -61,6 +61,7 @@ headers = enum_headers + files(
'provider/gtd-provider-popover.h',
'task-list-view/gtd-task-list-view.h',
'widgets/gtd-menu-button.h',
+ 'widgets/gtd-star-widget.h',
'gtd-clock.h',
'gtd-object.h',
'gtd-omni-area.h',
@@ -109,6 +110,7 @@ sources += files(
'widgets/gtd-empty-list-widget.c',
'widgets/gtd-menu-button.c',
'widgets/gtd-row-header.c',
+ 'widgets/gtd-star-widget.c',
'gtd-application.c',
'gtd-initial-setup-window.c',
'gtd-clock.c',
@@ -264,6 +266,8 @@ if get_option('introspection')
'task-list-view/gtd-task-list-view.h',
'widgets/gtd-menu-button.c',
'widgets/gtd-menu-button.h',
+ 'widgets/gtd-star-widget.c',
+ 'widgets/gtd-star-widget.h',
'gtd-enums.h',
'gtd-clock.c',
'gtd-clock.h',
diff --git a/src/theme/Adwaita-widgets.css b/src/theme/Adwaita-widgets.css
new file mode 100644
index 0000000..63bf923
--- /dev/null
+++ b/src/theme/Adwaita-widgets.css
@@ -0,0 +1,27 @@
+/* Star Widget */
+
+@keyframes wiggle {
+ 12.5% { transform: rotate(15deg) }
+ 37.5% { transform: rotate(-15deg) }
+ 62.5% { transform: rotate(15deg) }
+ 87.5% { transform: rotate(-15deg) }
+}
+
+star {
+ color: alpha(@theme_fg_color, 0.1);
+ transition: color 400ms;
+}
+
+star:hover {
+ color: alpha(@theme_fg_color, 0.4);
+ transition: color 250ms;
+}
+
+star:checked {
+ color: @theme_selected_bg_color;
+ transition: color 250ms;
+
+ animation-name: wiggle;
+ animation-duration: 400ms;
+ animation-timing-function: linear;
+}
diff --git a/src/theme/Adwaita.css b/src/theme/Adwaita.css
index 9fe611d..938035d 100644
--- a/src/theme/Adwaita.css
+++ b/src/theme/Adwaita.css
@@ -1,6 +1,7 @@
@import url("resource:///org/gnome/todo/theme/Adwaita-omniarea.css");
@import url("resource:///org/gnome/todo/theme/Adwaita-tasklistview.css");
@import url("resource:///org/gnome/todo/theme/Adwaita-taskrow.css");
+@import url("resource:///org/gnome/todo/theme/Adwaita-widgets.css");
.transparent {
background-color: transparent;
diff --git a/src/todo.gresource.xml b/src/todo.gresource.xml
index 0d46b9f..0f69c49 100644
--- a/src/todo.gresource.xml
+++ b/src/todo.gresource.xml
@@ -24,5 +24,6 @@
<file compressed="true">theme/Adwaita-omniarea.css</file>
<file compressed="true">theme/Adwaita-tasklistview.css</file>
<file compressed="true">theme/Adwaita-taskrow.css</file>
+ <file compressed="true">theme/Adwaita-widgets.css</file>
</gresource>
</gresources>
diff --git a/src/widgets/gtd-star-widget.c b/src/widgets/gtd-star-widget.c
new file mode 100644
index 0000000..5dcfc19
--- /dev/null
+++ b/src/widgets/gtd-star-widget.c
@@ -0,0 +1,193 @@
+/* gtd-star-widget.c
+ *
+ * Copyright 2020 Georges Basile Stavracas Neto <georges stavracas gmail com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * SPDX-License-Identifier: GPL-3.0-or-later
+ */
+
+#include "gtd-star-widget.h"
+
+struct _GtdStarWidget
+{
+ GtkWidget parent;
+
+ GtkWidget *filled_star;
+ GtkWidget *empty_star;
+
+ gboolean active;
+};
+
+G_DEFINE_TYPE (GtdStarWidget, gtd_star_widget, GTK_TYPE_WIDGET)
+
+enum
+{
+ PROP_0,
+ PROP_ACTIVE,
+ N_PROPS
+};
+
+static GParamSpec *properties [N_PROPS];
+
+
+/*
+ * Callbacks
+ */
+
+static void
+on_star_widget_clicked_cb (GtkGestureClick *gesture,
+ gint n_press,
+ gdouble x,
+ gdouble y,
+ GtdStarWidget *self)
+{
+ gtd_star_widget_set_active (self, !self->active);
+ gtk_gesture_set_state (GTK_GESTURE (gesture), GTK_EVENT_SEQUENCE_CLAIMED);
+}
+
+
+/*
+ * GObject overrides
+ */
+
+static void
+gtd_star_widget_get_property (GObject *object,
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ GtdStarWidget *self = GTD_STAR_WIDGET (object);
+
+ switch (prop_id)
+ {
+ case PROP_ACTIVE:
+ g_value_set_boolean (value, self->active);
+ break;
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ }
+}
+
+static void
+gtd_star_widget_set_property (GObject *object,
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ GtdStarWidget *self = GTD_STAR_WIDGET (object);
+
+ switch (prop_id)
+ {
+ case PROP_ACTIVE:
+ gtd_star_widget_set_active (self, g_value_get_boolean (value));
+ break;
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ }
+}
+
+static void
+gtd_star_widget_class_init (GtdStarWidgetClass *klass)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+ GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
+
+ object_class->get_property = gtd_star_widget_get_property;
+ object_class->set_property = gtd_star_widget_set_property;
+
+ /**
+ * GtdStarWidget:active:
+ *
+ * Whether the star widget is active or not. When active, the
+ * star appears filled.
+ */
+ properties[PROP_ACTIVE] = g_param_spec_boolean ("active",
+ "Active",
+ "Active",
+ FALSE,
+ G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY |
G_PARAM_STATIC_STRINGS);
+
+ g_object_class_install_properties (object_class, N_PROPS, properties);
+
+ gtk_widget_class_set_layout_manager_type (widget_class, GTK_TYPE_BIN_LAYOUT);
+ gtk_widget_class_set_css_name (widget_class, "star");
+}
+
+static void
+gtd_star_widget_init (GtdStarWidget *self)
+{
+ GtkGesture *click_gesture;
+
+ click_gesture = gtk_gesture_click_new ();
+ gtk_gesture_single_set_touch_only (GTK_GESTURE_SINGLE (click_gesture), FALSE);
+ gtk_gesture_single_set_exclusive (GTK_GESTURE_SINGLE (click_gesture), TRUE);
+ gtk_gesture_single_set_button (GTK_GESTURE_SINGLE (click_gesture), GDK_BUTTON_PRIMARY);
+ gtk_event_controller_set_propagation_phase (GTK_EVENT_CONTROLLER (click_gesture), GTK_PHASE_CAPTURE);
+ g_signal_connect (click_gesture, "pressed", G_CALLBACK (on_star_widget_clicked_cb), self);
+ gtk_widget_add_controller (GTK_WIDGET (self), GTK_EVENT_CONTROLLER (click_gesture));
+
+ gtk_widget_set_cursor_from_name (GTK_WIDGET (self), "default");
+
+ self->empty_star = gtk_image_new_from_icon_name ("non-starred-symbolic");
+ gtk_widget_set_parent (self->empty_star, GTK_WIDGET (self));
+
+ self->filled_star = gtk_image_new_from_icon_name ("starred-symbolic");
+ gtk_widget_set_parent (self->filled_star, GTK_WIDGET (self));
+ gtk_widget_hide (self->filled_star);
+
+ g_object_bind_property (self->filled_star,
+ "visible",
+ self->empty_star,
+ "visible",
+ G_BINDING_INVERT_BOOLEAN | G_BINDING_SYNC_CREATE);
+}
+
+GtkWidget*
+gtd_star_widget_new (void)
+{
+ return g_object_new (GTD_TYPE_STAR_WIDGET, NULL);
+}
+
+gboolean
+gtd_star_widget_get_active (GtdStarWidget *self)
+{
+ g_return_val_if_fail (GTD_IS_STAR_WIDGET (self), FALSE);
+
+ return self->active;
+}
+
+void
+gtd_star_widget_set_active (GtdStarWidget *self,
+ gboolean active)
+{
+ g_return_if_fail (GTD_IS_STAR_WIDGET (self));
+
+ if (self->active == active)
+ return;
+
+ self->active = active;
+ gtk_widget_set_visible (self->filled_star, active);
+
+ if (active)
+ gtk_widget_set_state_flags (GTK_WIDGET (self), GTK_STATE_FLAG_CHECKED, FALSE);
+ else
+ gtk_widget_unset_state_flags (GTK_WIDGET (self), GTK_STATE_FLAG_CHECKED);
+
+ /* TODO: explosion effect */
+
+ g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_ACTIVE]);
+}
diff --git a/src/widgets/gtd-star-widget.h b/src/widgets/gtd-star-widget.h
new file mode 100644
index 0000000..7a103f5
--- /dev/null
+++ b/src/widgets/gtd-star-widget.h
@@ -0,0 +1,37 @@
+/* gtd-star-widget.h
+ *
+ * Copyright 2020 Georges Basile Stavracas Neto <georges stavracas gmail com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * SPDX-License-Identifier: GPL-3.0-or-later
+ */
+
+#pragma once
+
+#include <gtk/gtk.h>
+
+G_BEGIN_DECLS
+
+#define GTD_TYPE_STAR_WIDGET (gtd_star_widget_get_type())
+G_DECLARE_FINAL_TYPE (GtdStarWidget, gtd_star_widget, GTD, STAR_WIDGET, GtkWidget)
+
+GtkWidget* gtd_star_widget_new (void);
+
+gboolean gtd_star_widget_get_active (GtdStarWidget *self);
+
+void gtd_star_widget_set_active (GtdStarWidget *self,
+ gboolean active);
+
+G_END_DECLS
diff --git a/tests/interactive/test-star-widget.c b/tests/interactive/test-star-widget.c
new file mode 100644
index 0000000..f1fb515
--- /dev/null
+++ b/tests/interactive/test-star-widget.c
@@ -0,0 +1,53 @@
+/* test-star-widget.c
+ *
+ * Copyright 2020 Georges Basile Stavracas Neto <georges stavracas gmail com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * SPDX-License-Identifier: GPL-3.0-or-later
+ */
+
+
+#include <gtk/gtk.h>
+
+#include "logging/gtd-log.h"
+#include "widgets/gtd-star-widget.h"
+
+gint
+main (gint argc,
+ gchar *argv[])
+{
+ GtkWidget *start_widget = NULL;
+ GtkWindow *window = NULL;
+
+ g_set_prgname ("test-star-widget");
+ g_set_application_name ("GNOME To Do | Star Widget");
+
+ gtk_init ();
+ gtd_log_init ();
+
+ /* Box */
+ start_widget = gtd_star_widget_new ();
+
+ /* Window */
+ window = GTK_WINDOW (gtk_window_new ());
+ gtk_window_set_default_size (window, 200, 150);
+ gtk_container_add (GTK_CONTAINER (window), start_widget);
+ gtk_window_present (window);
+
+ while (TRUE)
+ g_main_context_iteration (NULL, TRUE);
+
+ return 0;
+}
diff --git a/tests/meson.build b/tests/meson.build
index 6e43993..1b0675f 100644
--- a/tests/meson.build
+++ b/tests/meson.build
@@ -77,6 +77,7 @@ endforeach
interactive_tests = [
'test-colorbutton',
'test-filter-sort',
+ 'test-star-widget',
'test-task-model',
]
@@ -86,12 +87,14 @@ foreach interactive_test : interactive_tests
source = ['interactive/@0@.c'.format(interactive_test)]
- executable(
+ interactive_test_program = executable(
interactive_test_name,
source,
include_directories: tests_incs,
dependencies: gnome_todo_deps,
c_args: cflags,
link_with: tests_libs,
-)
+ )
+
+ test(interactive_test, interactive_test_program, env: static_test_env)
endforeach
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]