Commit Graph

59796 Commits

Author SHA1 Message Date
Benjamin Otte
3f2f7bf074 listitemfactory: Add a factory for ui files
Reuse <template> magic to initialize GtkListItems. This feels
amazingly hacky, but it also amazingly worked on the first try.
2019-12-13 06:11:56 +01:00
Benjamin Otte
8b67057c19 listitemfactory: Split implementation out
.. into gtkfunctionslistitemfactory.c

Now we can add a different implmenetation.
2019-12-13 06:11:56 +01:00
Benjamin Otte
e5a5f2bd90 listitemfactory: vfuncify
No functional changes other than a new indirection.
2019-12-13 06:11:56 +01:00
Benjamin Otte
aea62f9f77 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.
2019-12-13 06:11:56 +01:00
Benjamin Otte
b22acbcff6 listview: Add gtk_list_view_set_show_separators()
Do the same thing that GtkListBox does in commit
0249bd4f8a
2019-12-13 06:11:56 +01:00
Benjamin Otte
dfbcc9c50d 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.
2019-12-13 06:11:56 +01:00
Benjamin Otte
c1e1e0e683 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.
2019-12-13 06:11:56 +01:00
Benjamin Otte
bfb3da854d gridview: Implement GtkScrollable
We can now scroll all the nothing we display.

We also clip it properly.
2019-12-13 06:11:56 +01:00
Benjamin Otte
b077952901 listitemmanager: Move list of listitems here
All the listview infrastructure moved with it, so the next step is
moving that back...
2019-12-13 06:11:56 +01:00
Benjamin Otte
f1b300324e wayland: Remove function declaration for nonexisting function 2019-12-13 06:11:56 +01:00
Benjamin Otte
6a32109aed gridview: Add API for setting number of columns
The API isn't used yet.
2019-12-13 06:11:56 +01:00
Benjamin Otte
bd5562fe89 gtk: Add a GtkGridView skeleton 2019-12-13 06:11:56 +01:00
Benjamin Otte
0556f13532 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.
2019-12-13 06:10:08 +01:00
Benjamin Otte
34e6840d0a listview: Add initial support for displaying selections 2019-12-13 06:10:08 +01:00
Benjamin Otte
922991a3d7 listview: Reset listitems' CSS animations when rebinding
This way, newly displayed rows don't play an unselect animation (text
fading in) when they are unselected, but the row was previously used for
a selected item.
2019-12-13 06:10:08 +01:00
Benjamin Otte
37e4a0eca9 listview: Add selection properties to ListItem
This just brings the infrastructure into place, we're not using the
properties yet.
2019-12-13 06:10:08 +01:00
Benjamin Otte
345a18b1a1 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.
2019-12-13 06:10:08 +01:00
Benjamin Otte
6a3a936c4e listlistmodel: Add gtk_list_list_model_item_moved()
Use it to fix a case that just said g_warning ("oops").

Apparently I had forgotten the case where a container moved a child
in the widget tree.
2019-12-13 06:10:08 +01:00
Benjamin Otte
4e98bd33a5 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.
2019-12-13 06:10:08 +01:00
Benjamin Otte
2d89a8380f testlistview: Create widgets only once
Previously, we were recreating all widgets every time the list item was
rebound, which caused a lot of extra work every time we scrolled.

Now we keep the widgets around and only set their properties again when
the item changes.
2019-12-13 06:10:08 +01:00
Benjamin Otte
d3be13875d testlistview: Show the row number
Always show the current row. This is mostly useful for debugging, not
for beauty.
2019-12-13 06:10:08 +01:00
Benjamin Otte
40b8b9742e listview: Only allocate necesary rows
This is the big one.

The listview only allocates 200 rows around the visible row now.
Everything else is kept in ListRow instances with row->widget == NULL.

For rows without a widget, we assign the median height of the child
widgets as the row's height and then do all calculations as if there
were widgets that had requested that height (like setting adjustment
values or reacting to adjustment value changes).

When the view is scrolled, we bind the 200 rows to the new visible area,
so that the part of the listview that can be seen is always allocated.
2019-12-13 06:10:08 +01:00
Benjamin Otte
c06fee7460 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.
2019-12-13 06:10:08 +01:00
Benjamin Otte
7d152619bc listview: Change how binding is done
We now don't let the functions create widgets for the item from the
listmodel, instead we hand out a GtkListItem for them to add a widget
to.

GtkListItems are created in advance and can only be filled in by the
binding code by gtk_container_add()ing a widget.
However, they are GObjects, so they can provide properties that the
binding code can make use of - either via notify signals or GBinding.
2019-12-13 06:10:08 +01:00
Benjamin Otte
c65be391db 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.
2019-12-13 06:10:08 +01:00
Benjamin Otte
d516dd523e tests: Make animating listview do random resorts 2019-12-13 06:10:08 +01:00
Benjamin Otte
e431cd720f 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.
2019-12-13 06:10:08 +01:00
Benjamin Otte
9098382b76 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.
2019-12-13 06:10:08 +01:00
Benjamin Otte
a3cd145cbd listview: Add GtkListItem
GtkListItem is a generic row widget that is supposed to replace
GtkListBoxRow and GtkFlowBoxChild.
2019-12-13 06:10:08 +01:00
Benjamin Otte
08b225dd13 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.
2019-12-13 06:10:08 +01:00
Benjamin Otte
cbea54bb5b listview: Implement an anchor
The anchor selection is very basic: just anchor the top row.

That's vastly better than any other widget already though.
2019-12-13 06:10:08 +01:00
Benjamin Otte
058c7002d4 tests: Add a test for a permanently changing listview
This is mostly for dealing with proper anchoring and can be used to
check that things don't scroll or that selection and focus handling
properly works.

For comparison purposes, a ListBox is provided next to it.
2019-12-13 06:10:08 +01:00
Benjamin Otte
9722aef506 listview: Implement GtkScrollable
Scrolling in a very basic form is also supported
2019-12-13 06:10:08 +01:00
Benjamin Otte
2fb4df8973 listview: Make widget actually do something
The thing we're actually doing is create and maintain a widget for every
row. That's it.

Also add a testcase using this. The testcase quickly allocates too many
rows though and then becomes unresponsive though. You have been warned.
2019-12-13 06:10:08 +01:00
Benjamin Otte
bc637da95c listview: Introduce GtkListItemFactory
Thisis the abstraction I intend to use for creating widgets and binding
them to the item out of the listview.

For now this is a very dumb wrapper around the functions that exist in
the API.

But it leaves the freedom to turn this into public API, make an
interface out of it and most of all write different implementations, in
particular one that uses GtkBuilder.
2019-12-13 06:10:08 +01:00
Benjamin Otte
9575d54d4d gtk: Add a GtkListView skeleton 2019-12-13 06:09:56 +01:00
Benjamin Otte
c6a76c86c3 builder: Add <binding> tag
The tag contains an expression that it then gtk_expression_bind()s to
the object it is contained in.
2019-12-13 05:12:57 +01:00
Benjamin Otte
c04d63ff64 builder: Allow text content in <lookup>
<lookup>foo</lookup>
is now short for
  <lookup>
    <constant>foo</constant>
  </lookup>
ie it looks up the object with the given name so it can then do a
property lookup with it.

This is the most common operation, so it's a nice shortcut.
2019-12-13 05:12:57 +01:00
Benjamin Otte
cde3f3bc9e builder: Allow <constant> without a type
A constant without a type is assumed to be an object. This is the most
common case and allows
  <constant>foo</constant>
without requiring updates to the type whenever the foo object changes.
2019-12-13 05:12:57 +01:00
Benjamin Otte
c7344eef76 builder: Make <lookup> type optional
If no type is set, use the type of the expression.
2019-12-13 05:12:57 +01:00
Benjamin Otte
d2088059d7 gtk-demo: Make fishbowl info text use bindings
It's a good demo for how bindings can format multiple properties into an
informative string with 1 line of code (and 5 lines of XML).
2019-12-13 05:12:57 +01:00
Matthias Clasen
052a3c531f sorter: Add tests
Some basic tests for GtkSorter.
2019-12-13 05:12:57 +01:00
Benjamin Otte
8a07c5533e sortlistmodel: Make sort stable
The sort of the sortlistmodel is now stable with respect to the original
list model.

That means that if the sorter compares items as equal, the model
will make sure those items keep the order they were in in the original
model.

Or in other words: The model guarantees a total order based on the
item's position in the original model.
2019-12-13 05:12:57 +01:00
Benjamin Otte
54a9c07138 sortlistmodel: Redo the way we store the items
We need to keep this data around for changes in future commits where we
make the sorting stable.

An important part of the new data handling is that the unsorted list
needs to always be dealt with before the sorted list - upon creation we
rely on the unsorted iter and upon destruction, the sorted sequence
frees the entry leaving the unsorted sequence pointer invalid.

This change does not do any behavioral changes.
2019-12-13 05:12:57 +01:00
Matthias Clasen
bbc30a5810 Redo sort list model with GtkSorter
Reshuffle the api to take full advantage
of GtkSorter. Update all callers.
2019-12-13 05:12:57 +01:00
Matthias Clasen
3760289bbf Add GtkNumericSorter
This sorter compares numbers obtained from items
by evaluating an expression.
2019-12-13 05:12:57 +01:00
Matthias Clasen
f618c1b3ec Add GtkMultiSorter
This is a sorter that tries multiple sorters in turn.
2019-12-13 05:12:57 +01:00
Matthias Clasen
c0f31f4236 Add GtkStringSorter
This is a GtkSorter implementation collating strings
2019-12-13 05:12:57 +01:00
Matthias Clasen
5aeb9d3d8f Add GtkCustomSorter
This is a GtkSorter implementation which uses a GCompareDataFunc.
2019-12-13 05:12:57 +01:00
Matthias Clasen
38ee3ab8b6 Add GtkSorter
This is a helper object for sorting, similar to GtkFilter.
2019-12-13 05:12:57 +01:00