Commit Graph

30 Commits

Author SHA1 Message Date
Benjamin Otte
bffa5dfddd listview: Fix return_if_fail()s 2022-02-26 20:35:44 +01:00
Matthias Clasen
295d406207 listitemmanager: Add a few assertions
This might help poor static analyzers.
2021-09-17 22:06:21 -04:00
Matthias Clasen
91f7b9663f gtk: Clean up docs syntax
Replace leftover gtk-doc syntax (#Type) with backquotes.
2021-05-22 17:25:26 -04:00
Matthias Clasen
7fe0610b68 introspection: Stop using allow-none
allow-none has been deprecated for a long time
already. Instead use optional and nullable everywhere.
2021-05-20 19:17:49 -04:00
Matthias Clasen
8ba16eb4f1 Documentation fixes
Mostly fixing up indentation of continuation lines,
and other small cleanups.
2021-05-20 19:17:49 -04:00
Matthias Clasen
367dfee36e Fix unused variable warnings
These happen for variables which are only used
in assertions, when assertions are disabled.
2021-04-12 21:22:46 -04:00
Matthias Clasen
6d562b6176 listview: Set accessible roles
Use the LIST and LIST_ITEM roles for GtkListView
and its children. Use the GRID and GRID_CELL roles
for GtkGridView and its children.
2020-10-14 23:34:51 -04:00
Benjamin Otte
de56e892aa listitemmanager: Do a better job on double items
Previously, we would unparent the existing item that we were about
to reuse, and not the duplicate one.

Change that.
2020-07-16 20:43:16 +02:00
Benjamin Otte
5d9dc25115 listitemmanager: Update selections properly
Replace a previous fix with a more correct one: Update the
selected state from the model instead of reusing the old state, the
model might have updated the selected state.
2020-06-08 18:14:24 +02:00
Matthias Clasen
71c29bfcff listitemmanager: Handle selection-changes properly
The selection model will only emit one of items-changed
or selection-changed, so when we handle an items-changed,
we must assume that selection state may have changed for
any of the newly added items.

This fixes lingering selection state in the visible range
if you change the sorting of the colors demo.

Fixes: #2827
2020-06-06 08:36:11 -04:00
Matthias Clasen
69c86ae385 listitemwidget: Add single-click-activate
Add a mode to GtkListItemWidget that activates on
single click and selects on hover. Make
GtkListItemManager set this on its items
when its own 'property' of the same name is set.
2020-05-30 19:26:46 -04:00
Benjamin Otte
b33c56819b listitemfactory: Reorganize vfuncs
Instead of bind/rebind/update/unbind, we now just have update, and the
factories get to interpret that in the way they want.
2020-05-30 19:26:46 -04: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
dd436e8fe6 listitemmanager: Handle NULL factory
Just don't call it and create empty listitems.
2020-05-30 19:26:45 -04:00
Benjamin Otte
443e44853a listview: Pass the CSS name of listitems to the manager
... instead of hardcoding "row".
2020-05-30 19:26:45 -04:00
Benjamin Otte
10b967ae1f listitemfactory: Sanitize APIs
Make sure the APIs follow a predictable path:

setup
  bind
    rebind/update (0-N times)
  unbind
teardown

This is the first step towards providing multiple different factories.
2020-05-30 19:26:45 -04:00
Benjamin Otte
1acfae8df2 listitemmanager: Add trackers
... and replace the anchor tracking with a tracker.

Trackers track an item through the list across changes and ensure that
this item (and potentially siblings before/after it) are always backed
by a GtkListItem and that if the item gets removed a replacement gets
chosen.

This is now used for tracking the anchor but can also be used to add
trackers for the cursor later.
2020-05-30 19:26:45 -04:00
Benjamin Otte
ce489f21fb listitemmanager: Simplify
Remove a bunch of API from the headers that isn't used anymore and then
refactor code to not call it anymore.

In particular, get rid of GtkListItemManagerChange and replace it with a
GHashTable.
2020-05-30 19:26:45 -04:00
Benjamin Otte
dc91782165 listitemmanager: Move list of listitems here
All the listview infrastructure moved with it, so the next step is
moving that back...
2020-05-30 19:26:45 -04:00
Benjamin Otte
057effc5d6 listitem: Add a press gesture to select the item
This is implemented by using actions, which are a neat trick to get to
allow the ListItem to call functions on the ListView without actually
needing to be aware of it.
2020-05-30 19:26:45 -04:00
Benjamin Otte
d8c116f20a listview: Add initial support for displaying selections 2020-05-30 19:26:45 -04:00
Benjamin Otte
b3fb80c608 listview: Add selection properties to ListItem
This just brings the infrastructure into place, we're not using the
properties yet.
2020-05-30 19:26:45 -04:00
Benjamin Otte
5b69fd535d listview: Try to keep the list items in order when scrolling
Instead of just destroying all items and then recreating them (or even
hide()ing and then show()ing them again (or even even repositioning
them in the widget tree)), just try to reust them in the order they are.

This works surprisingly well when scrolling and most/all widgets
just moved.
2020-05-30 19:26:45 -04:00
Benjamin Otte
fbfc7dc690 listitemmanager: Switch from "insert_before" to "insert_after" argumnet
We reorder widgets start to end, so when reusing a list item, we
correctly know the previous sibling for that list item, but not the
next sibling yet. We just know the widget it should ultimately be in
front of.
So we can do a more correct guess of the list item's place in the widget
tree if we think about where to place an item like this.

Actually using this change will come in the next commit.
2020-05-30 19:26:45 -04:00
Benjamin Otte
2ba2a216ca listview: Change anchor handling again
The anchor is now a tuple of { listitem, align }.

Using the actual list item allows keeping the anchor across changes
in position (ie when lists get resorted) while still being able to fall
back to positions (list items store their position) when an item gets
removed.

The align value is in the range [0..1] and defines where in the visible
area to do the alignment.
0.0 means to align the top of the row with the top of the visible area,
1.0 aligns the bottom of the widget with the visible area and 0.5 keeps
the center of the widget at the center of the visible area.
It works conceptually the same as percentages in CSS background-position
(where the background area and the background image's size are matched
the same way) or CSS transform-origin.
2020-05-30 19:26:45 -04:00
Benjamin Otte
fe14181d4e listitem: Add gtk_list_item_get_position()
Also refactor the whole list item management yet again.

Now, list item APIs doesn't have bind/unbind functions anymore, but only
property setters.

The item factory is the only one doing the binding.
As before, the item manager manages when items need to be bound.
2020-05-30 19:26:45 -04:00
Benjamin Otte
ec8684e87d listview: Change change management
Add a GtkListItemManagerChange object that tracks all removed list
rows during an item-changed signal so they can be added back later.
2020-05-30 19:26:45 -04:00
Benjamin Otte
54042029d3 listview: Make the listitemmanager stricter
Require that items created with the manager get destroyed via the
manager.

To that purpose, renamed create_list_item() to acquire_list_item() and
add a matching release_list_item() function.

This way, the manager can in the future keep track of all items and
cache information about them.
2020-05-30 19:26:45 -04:00
Benjamin Otte
e1fa627158 listview: Add GtkListItem
GtkListItem is a generic row widget that is supposed to replace
GtkListBoxRow and GtkFlowBoxChild.
2020-05-30 19:26:45 -04:00
Benjamin Otte
9d5bb875b1 listview: Add GtkListItemManager
It's all stubs for now, but here's the basic ideas about what
this object is supposed to do:

(1) It's supposed to be handling all the child GtkWidgets that are
    used by the listview, so that the listview can concern
    itself with how many items it needs and where to put them.
(2) It's meant to do the caching of widgets that are not (currently)
    used.
(3) It's meant to track items that remain in the model across
    items-changed emissions and just change position.
(2) It's code that can be shared between listview and potential
    other widgets like a GridView.

It's also free to assume that the number of items it's supposed to
manage doesn't grow too much, so it's free to use O(N) algorithms.
2020-05-30 19:26:44 -04:00