Commit Graph

63546 Commits

Author SHA1 Message Date
Benjamin Otte
70cf9fca3a 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.
2020-05-29 19:46:30 -04:00
Benjamin Otte
88770cae09 testlistview: Show the row number
Always show the current row. This is mostly useful for debugging, not
for beauty.
2020-05-29 19:46:30 -04:00
Benjamin Otte
fd7b833a3f 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.
2020-05-29 19:46:30 -04:00
Benjamin Otte
93deba171e 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-29 19:46:30 -04:00
Benjamin Otte
1d1b69b359 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.
2020-05-29 19:46:30 -04:00
Benjamin Otte
68272e773c 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-29 19:46:30 -04:00
Benjamin Otte
b07338fc08 tests: Make animating listview do random resorts 2020-05-29 19:46:30 -04:00
Benjamin Otte
29a10cb829 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-29 19:46:30 -04:00
Benjamin Otte
67b824f33c 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-29 19:46:30 -04:00
Benjamin Otte
a44780f602 listview: Add GtkListItem
GtkListItem is a generic row widget that is supposed to replace
GtkListBoxRow and GtkFlowBoxChild.
2020-05-29 19:46:30 -04:00
Benjamin Otte
6a52f19b18 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-29 19:46:30 -04:00
Benjamin Otte
ab432878f9 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.
2020-05-29 19:46:30 -04:00
Benjamin Otte
74fbb6f428 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.
2020-05-29 19:46:30 -04:00
Benjamin Otte
a0f353ef3d listview: Implement GtkScrollable
Scrolling in a very basic form is also supported
2020-05-29 19:46:30 -04:00
Benjamin Otte
16a12f4733 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.
2020-05-29 19:46:30 -04:00
Benjamin Otte
7859781abc 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.
2020-05-29 19:46:30 -04:00
Benjamin Otte
3f1c02cb42 gtk: Add a GtkListView skeleton 2020-05-29 19:46:30 -04:00
Benjamin Otte
28a274149d builder: Add <binding> tag
The tag contains an expression that it then gtk_expression_bind()s to
the object it is contained in.
2020-05-29 19:46:30 -04:00
Benjamin Otte
e99c499158 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.
2020-05-29 19:46:30 -04:00
Benjamin Otte
4905647f0e 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.
2020-05-29 19:46:30 -04:00
Benjamin Otte
0c8daa10db builder: Make <lookup> type optional
If no type is set, use the type of the expression.
2020-05-29 19:46:30 -04:00
Benjamin Otte
d39011b59d 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).
2020-05-29 19:46:30 -04:00
Matthias Clasen
c0fb606bf8 sorter: Add tests
Some basic tests for GtkSorter.
2020-05-29 19:46:30 -04:00
Benjamin Otte
b493322a99 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.
2020-05-29 19:46:30 -04:00
Benjamin Otte
0bac3ca807 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.
2020-05-29 19:46:30 -04:00
Matthias Clasen
d104d874a9 Redo sort list model with GtkSorter
Reshuffle the api to take full advantage
of GtkSorter. Update all callers.
2020-05-29 19:46:30 -04:00
Matthias Clasen
dc2bb3e22a Add GtkNumericSorter
This sorter compares numbers obtained from items
by evaluating an expression.
2020-05-29 19:46:30 -04:00
Matthias Clasen
a596779064 Add GtkMultiSorter
This is a sorter that tries multiple sorters in turn.
2020-05-29 19:46:30 -04:00
Matthias Clasen
e160941d48 Add GtkStringSorter
This is a GtkSorter implementation collating strings
2020-05-29 19:46:30 -04:00
Matthias Clasen
a2581c3f01 Add GtkCustomSorter
This is a GtkSorter implementation which uses a GCompareDataFunc.
2020-05-29 19:46:30 -04:00
Matthias Clasen
76494d2a5d Add GtkSorter
This is a helper object for sorting, similar to GtkFilter.
2020-05-29 19:46:30 -04:00
Benjamin Otte
a9b19db81d Add GtkOrdering
This is an enum that we're gonna use soon and it's worth introducing as a
separate commit.

The intention is to have meaningful names for return values in
comparison functions.
2020-05-29 19:46:30 -04:00
Matthias Clasen
0178dd9a94 More expression tests
Test type mismatches, and the this pointer
during evaluation.
2020-05-29 19:46:30 -04:00
Benjamin Otte
6762d7f1d6 expression: Invalidate bindings before destroying them
Use a weak ref to invalidate bindings. Make sure that this happens
before creating any watches, so that notifies from the
watched expression about changes will not trigger set_property() calls
during dispose()/finalize().

Invalidating also ensures that the watches aren't removed, which can
trigger warnings if the watches are watching the object itself, and the
weak refs cannot be removed anymore.
2020-05-29 19:46:30 -04:00
Benjamin Otte
f493b22421 expression: Add gtk_expression_bind()
Add a simple way to bind expressions to object properties. This is
essentially the thing to replace g_object_bind_property().
2020-05-29 19:46:30 -04:00
Benjamin Otte
b4479ea118 testsuite: Add expression tests 2020-05-29 19:46:30 -04:00
Benjamin Otte
7751d54e98 expression: Add the ability to watch an expression 2020-05-29 19:46:30 -04:00
Benjamin Otte
037106c27d builder: Add support for parsing expressions 2020-05-29 19:46:30 -04:00
Benjamin Otte
4730d50968 filter: Add tests
Some basic tests for GtkFilter
2020-05-29 19:46:30 -04:00
Benjamin Otte
a541d89d8c Add GtkMultiFilter, GtkAnyFilter, GtkEveryFilter
GtkMultiFilter is the abstract base class for managing multiple child
filter.
GtkAnyFilter and GtkEveryFilter are the actual implementations.
2020-05-29 19:46:30 -04:00
Benjamin Otte
9cc97fd678 filter: Add GtkStringFilter
Users provide a search filter and an expression that evaluates the items
to a string and then the filter goes and matches those strings to the
search term.
2020-05-29 19:46:30 -04:00
Benjamin Otte
9c34fc9d21 expression: Make property expression allow subexpressions 2020-05-29 19:46:30 -04:00
Benjamin Otte
da3ae70b78 expression: Add GtkObjectExpression
Weak refs break cycles...
2020-05-29 19:46:30 -04:00
Benjamin Otte
e4d0ee3fd9 Add GtkExpression
GtkExpressions allow looking up values from objects.

There are a few simple expressions, but the main one is the closure
expression that just calls a user-provided closure.
2020-05-29 19:46:30 -04:00
Benjamin Otte
d665a8bf51 filterlistmodel: Rewrite to use GtkFilter 2020-05-29 19:46:30 -04:00
Benjamin Otte
1266f76dc0 tests: Remove testtreemodel test
testlistview does everything this test does.
2020-05-29 19:46:30 -04:00
Benjamin Otte
f4ec02ef40 Add GtkCustomFilter 2020-05-29 19:46:30 -04:00
Benjamin Otte
eecc27c330 Add GtkFilter 2020-05-29 19:46:30 -04:00
Benjamin Otte
34cce1dea6 Add GtkDirectoryList
Adds a new listmodel called GtkDirectoryList that lists the children of
a GFile as GFileInfos.

This is supposed to be used by the filechooser.
2020-05-29 19:46:30 -04:00
Benjamin Otte
c56cb1e89b builder: Allow <property bind /> for objects
Previously, object properties had to always be set to a value.
This now works without it.
2020-05-29 19:46:30 -04:00