Commit Graph

41 Commits

Author SHA1 Message Date
Björn Daase
6315cd977c *: Fix spelling mistakes found by codespell 2020-08-21 15:29:34 +02:00
Matthias Clasen
ccb9dcc86b singleselection: Make constructor transfer full
This is for consistency with other wrapping list constructors.
We want them all to be transfer full, allow-none.

Update all callers.
2020-07-26 18:04:40 -04:00
Benjamin Otte
dc1dbe6158 listbase: Make rubberbanding a threshold drag 2020-06-26 07:13:32 +02:00
Benjamin Otte
30488e60e2 listbase: Only compute the modifiers when releasing the rubberband
... and do the right things:

nothing:    selection = rubberband
ctrl:       selection = selection OR rubberband
shift:      selection = selection AND (NOT rubberband)
ctrl+shift: selection = selection XOR rubberband
            (not sure this one makes sense, but toggling is fun)
2020-06-26 07:13:32 +02:00
Benjamin Otte
a5949960bc listbase: Compute rubberband region on-demand
Instead of storing the active items as we go, compute the affected items
whenever the rubberband changes and in particular when the rubberband
ends.
That way, the rubberband is guaranteed to select a rectangle even
after scrolling very far.

This is achieved by having a get_items_in_rect() vfunc that selects all
the items in the rubberbanded rectangle and returns them as a bitset.
2020-06-26 07:13:32 +02:00
Benjamin Otte
7c52e03815 listbase: Flip autoscroll deltas if adjustments are flipped
Fixes autoscroll on RTL languages.
2020-06-26 07:13:32 +02:00
Benjamin Otte
724c9361f3 listbase: Allocate gridview items properly on RTL
We need to flip the items.
2020-06-26 07:13:32 +02:00
Benjamin Otte
64aa281c97 listbase: Allocate rubberband according to list coords
The rubberband is now handled on the list coordinate system.

When starting the rubberband, we track the item under the pointer and
follow it when it is moving.
This may lead to the rubberband start position changing position and
while this may be confusing, it alerts users to the fact that something
crazy is going on.
2020-06-26 07:13:32 +02:00
Benjamin Otte
c2b0330c56 listbase: Move a common function from the children into GtkListBase
We want to use it for the rubberband later.
2020-06-26 07:13:32 +02:00
Benjamin Otte
de4803bb21 listbase: Don't do extra work
Scrolling causes a queue_resize() which will update the rubberband in
size_allocate() and queue a draw.
2020-06-26 07:13:32 +02:00
Benjamin Otte
a38c423ddb listbase: Port rubberband to gtk_selection_model_set_selection() 2020-06-26 07:13:32 +02:00
Matthias Clasen
02b293b59c listbase: Don't use adjustments for autoscrolling
Don't consult the adjustments when determining
scroll deltas. It isn't necessary.
2020-06-19 15:26:10 -04:00
Matthias Clasen
c659a231d6 listbase: Increase the autoscroll threshold
With autoscroll during DND, we stop when you hit the edge
of the widget, so a larger threshold makes sense to avoid
hitting the edge by accident.
2020-06-19 15:26:10 -04:00
Matthias Clasen
4e56581222 listbase: Autoscroll during DND
Use a drop motion controller to autoscroll while
a drag operation is hovering over the list.
2020-06-19 15:26:10 -04:00
Matthias Clasen
e8ba16d9c2 listbase: separate autoscroll from rubberband
Break out an update_autoscroll() function that can
be used for other things than rubberbanding. It will
be used for autoscroll during DND in the future.
2020-06-19 15:26:10 -04:00
Benjamin Otte
ff3b03c5e2 listbase: Fix copy/paste error
This could lead to "flickering" scroll behavior when scrolling
horizontally.
2020-06-19 15:51:52 +02:00
Benjamin Otte
541aaa2392 selectionmodel: Add unselect_rest argument to select_callback
This is not just about consistency with other functions.

It is about avoiding reentrancy problems.

GtkListBase first doing an unselect_all() will then force the
SelectionModel to consider a state where all items are unselected
(and potentially deciding to autoselect one) and then cause a
"selection-changed" emission that unselects all items and potentially
updates all the list item widgets in the GtkListBase to the unselected
state.

After this, GtkListBase selects new items, but to the SelectionModel and
the list item widgets this looks like an enitrely new operation and
there is no way to associate it with the previous state, so the
SelectionModel cannot undo any previous actions it took when
unselecting.
And all listitem widgets will now think they were just selected and
start running animations about selecting.
2020-06-08 19:06:56 +02:00
Matthias Clasen
c0fe1a7ffe listbase: Make up/down arrows work
We were missing a binding for up/down without modifiers.
2020-06-06 12:33:12 -04:00
Matthias Clasen
facfff0022 listbase: Fix an off-by-one error
We were accidentally cutting off the set one-too-early,
which showed up as single clicks not selecting an item
anymore.
2020-06-06 00:15:50 -04:00
Matthias Clasen
f8b4083f47 listbase: Fix a problem with rubberbands
When I changed things to only collect the set
in the stop() function, I overlooked that this
has the side-effect of only handling items which
are backed by a widget at the time stop() is called.
If we make a big rubberband and autoscroll down too
far, we loose the items that go out the visible range
at the top. Fix that by maintaining the set as we go.
2020-06-05 23:18:00 -04:00
Emmanuele Bassi
6e52ef96a4 Move orientable style classes into GtkWidget
It feels slightly wrong to have GtkOrientable operate on widgets, but at
least what happens when an orientable widget changes orientation should
be part of GtkWidget.

This will allow to add more state changes without accessing widget state
from the outside of gtkwidget.c.
2020-06-05 20:35:09 +01:00
Matthias Clasen
eeb2d2cc38 listbase: Redo rubberbanding
Make it so that the selection is only updated in the end.
2020-06-05 00:51:35 -04:00
Matthias Clasen
fa37225a42 Merge branch 'columnview-rubberbanding' into 'master'
columnview: Implement rubberbanding

See merge request GNOME/gtk!2008
2020-06-03 21:46:13 +00:00
Matthias Clasen
b3a97cb755 listbase: Simplify rubberbanding
The new approach is:
 - plain: clear and start a new selection
 - extend: add to the existing selection
 - modify: subtract from the existing selection
2020-06-03 13:32:57 -04:00
Matthias Clasen
a9273e1c73 listbase: Split off rubberband data 2020-06-03 13:32:57 -04:00
Matthias Clasen
14d11ebcab listbase: Use a widget for the rubberband
We no longer need to juggle manual css nodes. Just create
a widget for the rubberband, and update its allocation
as we rubberband.
2020-06-03 13:32:57 -04:00
Matthias Clasen
7dc458d925 Add autoscroll
This is an expected feature with rubberband selection:
as you get close to the edge while doing rubberband
selection, the list scrolls to extend your selection.
2020-06-03 13:32:57 -04:00
Matthias Clasen
a0f04bdcf3 listbase: Add rubberband selection
Implement the typical rubberband selection, including
autoscroll. This is only useful with multiselection,
and not very compatible with single-click-activate.
Therefore, it is not enabled by default, and needs
to be turned on explicitly.
2020-06-03 13:32:57 -04:00
Benjamin Otte
a60c866a12 listbase: Don't grab_focus() when moving focus
We want to call gtk_widget_child_focus() to have Tab focus the right
widget.
2020-06-03 18:12:49 +02:00
Benjamin Otte
aa38fc712f listbase: Fix leak
We were leaking the temporary tracker here.
2020-06-03 17:49:04 +02:00
Benjamin Otte
30f09ea10b listitem: Make this a GObject
This splits GtkListItem into 2 parts:

1. GtkListItem
   This is purely a GObject with public API for developers who want to
   populate lists. There is no chance to cause conflict with GtkWidget
   properties that the list implementation assumed control over and
   defines a clear boundary.
2. GtkListItemWidget
   The widget part of the listitem. This is not only fully in control of
   the list machinery, the machinery can also use different widget
   implementations for different list widgets like I inted to for
   GtkColumnView.
2020-05-30 19:26:46 -04:00
Benjamin Otte
f4eb026c86 wip: Add GtkCoverFlow
The widget mostly works out of the box, but some tweaking may be
necessary (in particular in the theme) and the gtk-demo changes might
require removing before this is production-ready.
2020-05-30 19:26:46 -04:00
Benjamin Otte
e46fa81927 listbase: Take over anchor handling
With that, pretty much all code but allocating the widgets is gone from
the gridview and listview.
2020-05-30 19:26:46 -04:00
Benjamin Otte
33c6b428f7 listbase: Add vfuncs to convert positions to/from coordinates
... and use that to implement PageUp/PageDown.

With that, all keyboard handling has been moved to GtkListBase.
2020-05-30 19:26:46 -04:00
Benjamin Otte
12331e3376 listbase: Move focus moving keybindings here
The focus tracker is not yet moved because that depends on scroll_to()
support and we don't have that yet.
Whoops.
So we use a hack.
2020-05-30 19:26:46 -04:00
Benjamin Otte
dd5e6d47db Remove gtk_selection_model_user_select_item() again
This reverts commit 6a164ab306dad9096bde736c907494c71086d3c4.

The function was awkward and we now have only one caller again, so we
can fold it back into it.
2020-05-30 19:26:46 -04:00
Benjamin Otte
2541037ec2 listbase: Move orientable implementation here 2020-05-30 19:26:46 -04:00
Benjamin Otte
9d6aa7d88e listbase: Move selection handling here 2020-05-30 19:26:46 -04:00
Benjamin Otte
0bd16308d6 listbase: Move item manager here
Nothing really changes, because both ListView and GridView still keep
self->item_manager around, but it's set up to point at the base's item
manager.

This way we can slowly move things to GtkListBase that need the item
manager (like trackers).
2020-05-30 19:26:46 -04:00
Benjamin Otte
0011ce949c listbase: Move GtkScrollable implementation
Shared code between GtkGridView and GtkListView.
2020-05-30 19:26:46 -04:00
Benjamin Otte
cc987b31ae Add GtkListBase
This is a base item for GTK's list widgets so they can share some (read:
hopefully a lot of) code.
2020-05-30 19:26:46 -04:00