[egg-list-box/flow-box-enhancements] Fix keynav in vertical orientation
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [egg-list-box/flow-box-enhancements] Fix keynav in vertical orientation
- Date: Sat, 28 Sep 2013 21:17:22 +0000 (UTC)
commit 69af804dfb50f122e3afd6c246194f168c78262b
Author: Matthias Clasen <mclasen redhat com>
Date: Sat Sep 28 17:15:24 2013 -0400
Fix keynav in vertical orientation
We need to flip things around so directional navigation works
as expected. To make Page Up/Down work, we need to also keep
the hadjustment around, which requires new API.
TODO | 8 +----
egg-flow-box.c | 69 ++++++++++++++++++++++++++++++++++++++++--------------
egg-flow-box.h | 4 ++-
test-flow-box.c | 10 ++++---
4 files changed, 62 insertions(+), 29 deletions(-)
---
diff --git a/TODO b/TODO
index a1754e6..f82c2f4 100644
--- a/TODO
+++ b/TODO
@@ -7,12 +7,6 @@ size allocation a bit trickier, but may not be that hard.
EggFlowBoxChild doesn't seem to support width-for-height mode, which is
what flowbox uses in vertical mode. This probably needs to be added.
-egg_flow_box_set_adjustment() - since grids have horizontal scrolling
-too, this should probably be called set_vadjustment(). I don't think
-we need set_hadjustment() though, since gtk_scrolled_window_add()
-properly calls gtk_container_set_focus_hadjustment() and we don't need
-the hadjustment in the keynav.
-
fit_aligned_item_requests() - maybe this should do a binary search
instead? Remembering last value as a start.
@@ -20,4 +14,6 @@ Do we want to have support for something like the headers in
gnome-control-center? I.e. mark some children as row-spanning? (plus
you'd make it insensitive to avoid selection)
+Selection vs filtering - unselect when filtered out ?
+
Rubberband selection.
diff --git a/egg-flow-box.c b/egg-flow-box.c
index 5352b54..f2b4423 100644
--- a/egg-flow-box.c
+++ b/egg-flow-box.c
@@ -131,7 +131,8 @@ struct _EggFlowBoxPrivate {
GtkSelectionMode selection_mode;
- GtkAdjustment *adjustment;
+ GtkAdjustment *hadjustment;
+ GtkAdjustment *vadjustment;
gboolean activate_on_single_click;
guint16 min_children_per_line;
@@ -517,18 +518,31 @@ egg_flow_box_child_get_index (EggFlowBoxChild *child)
}
void
-egg_flow_box_set_adjustment (EggFlowBox *box,
- GtkAdjustment *adjustment)
+egg_flow_box_set_hadjustment (EggFlowBox *box,
+ GtkAdjustment *adjustment)
{
EggFlowBoxPrivate *priv = box->priv;
g_return_if_fail (box != NULL);
g_object_ref (adjustment);
- g_clear_object (&priv->adjustment);
- priv->adjustment = adjustment;
- gtk_container_set_focus_vadjustment (GTK_CONTAINER (box),
- adjustment);
+ g_clear_object (&priv->hadjustment);
+ priv->hadjustment = adjustment;
+ gtk_container_set_focus_hadjustment (GTK_CONTAINER (box), adjustment);
+}
+
+void
+egg_flow_box_set_vadjustment (EggFlowBox *box,
+ GtkAdjustment *adjustment)
+{
+ EggFlowBoxPrivate *priv = box->priv;
+
+ g_return_if_fail (box != NULL);
+
+ g_object_ref (adjustment);
+ g_clear_object (&priv->vadjustment);
+ priv->vadjustment = adjustment;
+ gtk_container_set_focus_vadjustment (GTK_CONTAINER (box), adjustment);
}
/**
@@ -3028,11 +3042,29 @@ egg_flow_box_move_cursor (EggFlowBox *box,
GtkAllocation allocation;
gint page_size;
GSequenceIter *iter;
- gint start_y;
- gint end_y;
+ gint start;
+ gint end;
+ GtkAdjustment *adjustment;
+ gboolean vertical;
+
+ vertical = priv->orientation == GTK_ORIENTATION_VERTICAL;
get_current_selection_modifiers (GTK_WIDGET (box), &modify_selection, &extend_selection);
+ if (vertical)
+ {
+ switch (step)
+ {
+ case GTK_MOVEMENT_VISUAL_POSITIONS:
+ step = GTK_MOVEMENT_DISPLAY_LINES;
+ break;
+ case GTK_MOVEMENT_DISPLAY_LINES:
+ step = GTK_MOVEMENT_VISUAL_POSITIONS;
+ break;
+ default: ;
+ }
+ }
+
child = NULL;
switch (step)
{
@@ -3093,15 +3125,16 @@ egg_flow_box_move_cursor (EggFlowBox *box,
case GTK_MOVEMENT_PAGES:
page_size = 100;
- if (priv->adjustment != NULL)
- page_size = gtk_adjustment_get_page_increment (priv->adjustment);
+ adjustment = vertical ? priv->hadjustment : priv->vadjustment;
+ if (adjustment)
+ page_size = gtk_adjustment_get_page_increment (adjustment);
if (priv->cursor_child != NULL)
{
gtk_widget_get_allocation (GTK_WIDGET (priv->cursor_child), &allocation);
child_priv = egg_flow_box_child_get_instance_private (priv->cursor_child);
- start_y = allocation.y;
- end_y = start_y;
+ start = vertical ? allocation.x : allocation.y;
+ end = start;
iter = child_priv->iter;
child = priv->cursor_child;
@@ -3123,7 +3156,7 @@ egg_flow_box_move_cursor (EggFlowBox *box,
if (i % priv->cur_children_per_line == 0)
{
gtk_widget_get_allocation (GTK_WIDGET (prev), &allocation);
- if (allocation.y < start_y - page_size)
+ if ((vertical ? allocation.x : allocation.y) < start - page_size)
break;
}
@@ -3148,7 +3181,7 @@ egg_flow_box_move_cursor (EggFlowBox *box,
if (i % priv->cur_children_per_line == 0)
{
gtk_widget_get_allocation (GTK_WIDGET (next), &allocation);
- if (allocation.y > start_y + page_size)
+ if ((vertical ? allocation.x : allocation.y) > start + page_size)
break;
}
@@ -3157,7 +3190,7 @@ egg_flow_box_move_cursor (EggFlowBox *box,
}
}
gtk_widget_get_allocation (GTK_WIDGET (child), &allocation);
- end_y = allocation.y;
+ end = vertical ? allocation.x : allocation.y;
}
break;
@@ -3282,7 +3315,8 @@ egg_flow_box_finalize (GObject *obj)
priv->sort_destroy (priv->sort_data);
g_sequence_free (priv->children);
- g_clear_object (&priv->adjustment);
+ g_clear_object (&priv->hadjustment);
+ g_clear_object (&priv->vadjustment);
G_OBJECT_CLASS (egg_flow_box_parent_class)->finalize (obj);
}
@@ -3922,4 +3956,3 @@ egg_flow_box_get_child_at_index (EggFlowBox *box,
return NULL;
}
-
diff --git a/egg-flow-box.h b/egg-flow-box.h
index 7899085..e489b7c 100644
--- a/egg-flow-box.h
+++ b/egg-flow-box.h
@@ -173,7 +173,9 @@ void egg_flow_box_unselect_all (EggFlowBox
GtkSelectionMode egg_flow_box_get_selection_mode (EggFlowBox *box);
void egg_flow_box_set_selection_mode (EggFlowBox *box,
GtkSelectionMode mode);
-void egg_flow_box_set_adjustment (EggFlowBox *box,
+void egg_flow_box_set_hadjustment (EggFlowBox *box,
+ GtkAdjustment *adjustment);
+void egg_flow_box_set_vadjustment (EggFlowBox *box,
GtkAdjustment *adjustment);
typedef gboolean (*EggFlowBoxFilterFunc) (EggFlowBoxChild *child,
diff --git a/test-flow-box.c b/test-flow-box.c
index 21129b0..8045629 100644
--- a/test-flow-box.c
+++ b/test-flow-box.c
@@ -73,7 +73,7 @@ populate_flowbox_focus (EggFlowBox *flowbox)
gint i;
gboolean sensitive;
- for (i = 0; i < 10; i++)
+ for (i = 0; i < 200; i++)
{
sensitive = TRUE;
frame = gtk_frame_new (NULL);
@@ -103,7 +103,7 @@ populate_flowbox_focus (EggFlowBox *flowbox)
gtk_container_add (GTK_CONTAINER (box), widget);
- if (i == 4)
+ if (i % 5 == 0)
gtk_container_add (GTK_CONTAINER (box), gtk_switch_new ());
gtk_widget_show_all (frame);
@@ -438,8 +438,10 @@ create_window (void)
gtk_widget_show (flowbox);
gtk_container_add (GTK_CONTAINER (swindow), flowbox);
- egg_flow_box_set_adjustment (EGG_FLOW_BOX (flowbox),
- gtk_scrolled_window_get_vadjustment (GTK_SCROLLED_WINDOW (swindow)));
+ egg_flow_box_set_hadjustment (EGG_FLOW_BOX (flowbox),
+ gtk_scrolled_window_get_hadjustment (GTK_SCROLLED_WINDOW (swindow)));
+ egg_flow_box_set_vadjustment (EGG_FLOW_BOX (flowbox),
+ gtk_scrolled_window_get_vadjustment (GTK_SCROLLED_WINDOW (swindow)));
g_signal_connect (flowbox, "child-activated", G_CALLBACK (on_child_activated), NULL);
g_signal_connect (flowbox, "selected-children-changed", G_CALLBACK (on_selected_children_changed), NULL);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]