Skip to content
Snippets Groups Projects
Verified Commit e5a732be authored by Bruce Cowan's avatar Bruce Cowan :airplane:
Browse files

Add try filter

parent 9df1bdd6
No related branches found
No related tags found
No related merge requests found
......@@ -23,6 +23,13 @@ template RugbyAppWindow : Adw.ApplicationWindow {
tooltip-text: "Score";
}
ToggleButton filter_toggle {
icon-name: "funnel";
tooltip-text: "Show Try Filter";
toggled => filter_toggle_toggled_cb();
}
[end]
MenuButton {
direction: none;
......@@ -35,32 +42,58 @@ template RugbyAppWindow : Adw.ApplicationWindow {
Adw.Clamp {
maximum-size: 600;
Stack stack {
StackPage {
child: Adw.StatusPage empty_page {
title: "No possibilities";
};
Box {
orientation: vertical;
Revealer {
halign: center;
margin-top: 6;
reveal-child: bind filter_toggle.active;
transition-type: swing_down;
SpinButton tryspin {
adjustment: Adjustment {
step-increment: 1;
lower: 0;
upper: 40;
};
focusable: true;
tooltip-text: "Tries";
value-changed => try_spin_value_changed_cb();
}
}
StackPage {
child: ScrolledWindow list_page {
vexpand: true;
Stack stack {
StackPage {
child: Adw.StatusPage empty_page {
title: "No possibilities";
};
}
ListView listview {
styles ["rich-list"]
StackPage {
child: ScrolledWindow list_page {
vexpand: true;
model: NoSelection {
model: .RugbyListStore {
score: bind scorespin.value;
ListView listview {
styles ["rich-list"]
factory: BuilderListItemFactory {
resource: "/uk/me/bcowan/Rugby/gtk/score-item.ui";
};
model: NoSelection {
model: FilterListModel {
filter: CustomFilter try_filter {};
model: .RugbyListStore list_store {
score: bind scorespin.value;
};
items-changed => list_store_items_changed_cb();
items-changed => list_store_items_changed_cb();
};
};
};
factory: BuilderListItemFactory {
resource: "/uk/me/bcowan/Rugby/gtk/score-item.ui";
};
}
};
}
};
}
}
}
}
......
<?xml version="1.0" encoding="UTF-8"?>
<svg xmlns="http://www.w3.org/2000/svg" height="16px" viewBox="0 0 16 16" width="16px"><path d="m 0 1.007812 h 15 l -6 7 v 6 l -3 2 v -8 z m 0 0" fill="#222222"/></svg>
......@@ -10,5 +10,6 @@
<file preprocess="xml-stripblanks" compressed="true">gtk/prefs.ui</file>
<file preprocess="xml-stripblanks" compressed="true">gtk/score-item.ui</file>
<file preprocess="xml-stripblanks" compressed="true">gtk/window.ui</file>
<file preprocess="xml-stripblanks" compressed="true">icons/scalable/actions/funnel-symbolic.svg</file>
</gresource>
</gresources>
......@@ -18,9 +18,12 @@ struct _RugbyAppWindow
AdwApplicationWindow parent;
GtkWidget *scorespin;
GtkWidget *tryspin;
GtkWidget *stack;
GtkWidget *empty_page;
GtkWidget *list_page;
GtkCustomFilter *try_filter;
};
G_DEFINE_TYPE (RugbyAppWindow, rugby_app_window, ADW_TYPE_APPLICATION_WINDOW)
......@@ -108,6 +111,14 @@ activate_score_changed (G_GNUC_UNUSED GSimpleAction *action,
g_assert_not_reached ();
}
static void
try_spin_value_changed_cb (G_GNUC_UNUSED GtkSpinButton *btn,
gpointer user_data)
{
RugbyAppWindow *self = RUGBY_APP_WINDOW (user_data);
gtk_filter_changed (GTK_FILTER (self->try_filter), GTK_FILTER_CHANGE_DIFFERENT);
}
static void
rugby_app_window_dispose (GObject *object)
{
......@@ -116,6 +127,43 @@ rugby_app_window_dispose (GObject *object)
G_OBJECT_CLASS (rugby_app_window_parent_class)->dispose (object);
}
static gboolean
try_filter_func (gpointer item,
gpointer user_data)
{
RugbyPossibility *possibility = RUGBY_POSSIBILITY (item);
RugbyAppWindow *self = RUGBY_APP_WINDOW (user_data);
int tries, utries;
g_object_get (possibility,
"tries", &tries,
"utries", &utries,
NULL);
if ((tries + utries) == gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (self->tryspin)))
return TRUE;
return FALSE;
}
static void
filter_toggle_toggled_cb (GtkToggleButton *btn,
gpointer user_data)
{
RugbyAppWindow *self = RUGBY_APP_WINDOW (user_data);
if (gtk_toggle_button_get_active (btn))
{
gtk_custom_filter_set_filter_func (self->try_filter, try_filter_func, self, NULL);
gtk_filter_changed (GTK_FILTER (self->try_filter), GTK_FILTER_CHANGE_DIFFERENT);
}
else
{
gtk_custom_filter_set_filter_func (self->try_filter, NULL, NULL, NULL);
}
}
static void
rugby_app_window_init (RugbyAppWindow *self)
{
......@@ -146,10 +194,15 @@ rugby_app_window_class_init (RugbyAppWindowClass *klass)
"/uk/me/bcowan/Rugby/gtk/window.ui");
gtk_widget_class_bind_template_child (widget_class, RugbyAppWindow, scorespin);
gtk_widget_class_bind_template_child (widget_class, RugbyAppWindow, tryspin);
gtk_widget_class_bind_template_child (widget_class, RugbyAppWindow, stack);
gtk_widget_class_bind_template_child (widget_class, RugbyAppWindow, empty_page);
gtk_widget_class_bind_template_child (widget_class, RugbyAppWindow, list_page);
gtk_widget_class_bind_template_child (widget_class, RugbyAppWindow, try_filter);
gtk_widget_class_bind_template_callback (widget_class, filter_toggle_toggled_cb);
gtk_widget_class_bind_template_callback (widget_class, try_spin_value_changed_cb);
gtk_widget_class_bind_template_callback (widget_class, item_tooltip_cb);
gtk_widget_class_bind_template_callback (widget_class, list_store_items_changed_cb);
}
......
......@@ -165,7 +165,7 @@ rugby_list_store_get_property (GObject *object,
switch (prop_id)
{
case PROP_SCORE:
g_value_set_int (value, rugby_list_store_get_score (self));
g_value_set_int (value, self->score);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
......@@ -182,8 +182,15 @@ rugby_list_store_set_property (GObject *object,
switch (prop_id)
{
int score;
case PROP_SCORE:
rugby_list_store_set_score (self, g_value_get_int (value));
score = g_value_get_int (value);
if (score != self->score)
{
self->score = score;
process_data (self);
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_SCORE]);
}
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
......@@ -224,26 +231,3 @@ rugby_list_store_init (RugbyListStore *self)
self->items = g_list_store_new (RUGBY_TYPE_POSSIBILITY);
}
// Public functions
int
rugby_list_store_get_score (RugbyListStore *self)
{
g_assert (RUGBY_IS_LIST_STORE (self));
return self->score;
}
void
rugby_list_store_set_score (RugbyListStore *self,
int score)
{
g_assert (RUGBY_IS_LIST_STORE (self));
if (score != self->score)
{
self->score = score;
process_data (self);
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_SCORE]);
}
}
......@@ -14,8 +14,4 @@ G_BEGIN_DECLS
G_DECLARE_FINAL_TYPE (RugbyListStore, rugby_list_store, RUGBY, LIST_STORE, GObject)
int rugby_list_store_get_score (RugbyListStore *self);
void rugby_list_store_set_score (RugbyListStore *self,
int score);
G_END_DECLS
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment