Commit Graph

59678 Commits

Author SHA1 Message Date
Benjamin Otte
9435b7135d testlistview: Show the row number
Always show the current row. This is mostly useful for debugging, not
for beauty.
2019-12-08 06:27:38 +01:00
Benjamin Otte
e802551369 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-08 06:27:38 +01:00
Benjamin Otte
522c1f2883 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-08 06:27:38 +01:00
Benjamin Otte
11de7bf1a0 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-08 06:27:38 +01:00
Benjamin Otte
d01138c4d5 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-08 06:27:38 +01:00
Benjamin Otte
637ba7afd2 tests: Make animating listview do random resorts 2019-12-08 06:27:38 +01:00
Benjamin Otte
715e597107 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-08 06:27:38 +01:00
Benjamin Otte
9dc9092bac 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-08 06:27:38 +01:00
Benjamin Otte
9ee0283ffa listview: Add GtkListItem
GtkListItem is a generic row widget that is supposed to replace
GtkListBoxRow and GtkFlowBoxChild.
2019-12-08 06:27:38 +01:00
Benjamin Otte
9672aa089a 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-08 06:27:38 +01:00
Benjamin Otte
a6dcfe7b58 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-08 06:27:38 +01:00
Benjamin Otte
545398e819 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-08 06:27:38 +01:00
Benjamin Otte
ccb13a4c92 listview: Implement GtkScrollable
Scrolling in a very basic form is also supported
2019-12-08 06:27:37 +01:00
Benjamin Otte
6e756d9ad0 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-08 06:27:37 +01:00
Benjamin Otte
34709bc815 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-08 06:27:37 +01:00
Benjamin Otte
054299d45b gtk: Add a GtkListView skeleton 2019-12-08 06:27:37 +01:00
Benjamin Otte
f4ad74de9d 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-08 06:27:37 +01:00
Benjamin Otte
b20105b7bc 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-08 06:27:37 +01:00
Benjamin Otte
6600776865 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-08 06:27:37 +01:00
Benjamin Otte
3f23255e0f builder: Make <lookup> type optional
If no type is set, use the type of the expression.
2019-12-08 06:27:37 +01:00
Benjamin Otte
615a0ccae1 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-08 06:27:37 +01:00
Matthias Clasen
6a098e451e More expression tests
Test type mismatches, and the this pointer
during evaluation.
2019-12-08 06:27:37 +01:00
Benjamin Otte
a94d4648c8 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.
2019-12-08 06:27:37 +01:00
Benjamin Otte
c3d67d3271 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().
2019-12-08 06:27:37 +01:00
Benjamin Otte
b9b4e3ebe4 testsuite: Add expression tests 2019-12-08 06:27:37 +01:00
Benjamin Otte
adab2ba0de expression: Add the ability to watch an expression 2019-12-08 06:27:37 +01:00
Benjamin Otte
e6b82215d2 builder: Add support for parsing expressions 2019-12-08 06:27:37 +01:00
Benjamin Otte
02619e8a47 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.
2019-12-08 06:27:37 +01:00
Benjamin Otte
0956255b50 expression: Make property expression allow subexpressions 2019-12-08 06:27:37 +01:00
Benjamin Otte
4567c425ae expression: Add GtkObjectExpression
Weak refs break cycles...
2019-12-08 06:27:37 +01:00
Benjamin Otte
9371102bf9 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.
2019-12-08 06:27:37 +01:00
Benjamin Otte
dbaec8756d filter: Add GtkAnyFilter 2019-12-08 06:27:37 +01:00
Benjamin Otte
d3e75bcb3b filterlistmodel: Rewrite to use GtkFilter 2019-12-08 06:27:37 +01:00
Benjamin Otte
614a748d65 tests: Remove testtreemodel test
testlistview does everything this test does.
2019-12-08 06:27:37 +01:00
Benjamin Otte
1fd1f71abf filter: Add a custom filter 2019-12-08 06:27:37 +01:00
Benjamin Otte
8bf8bdb8ef Add GtkFilter 2019-12-08 06:27:37 +01:00
Benjamin Otte
94cb76788d 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.
2019-12-08 06:27:37 +01:00
Benjamin Otte
f16a9a5f5c builder: Turn last dlsym() function into a scope API
Looking up a get_type function by its name is now also part of
GtkBuilderScope.
2019-12-08 06:27:37 +01:00
Benjamin Otte
dccef45600 builder: Add GtkBuilderScope
GtkBuilderScope is an interface that provides the scope that a builder
instance operates in.
It creates closures and resolves types. Language bindings are meant to
use this interface to customize the behavior of builder files, in
particular when instantiating templates.

A default implementation for C is provided via GtkBuilderCScope (to keep
with the awkward naming that glib uses for closures). It is derivable on
purpose so that languages or extensions that extend C can use it.

The reftest code in fact does derive GtkBuilderCScope for its own scope
implementation that implements looking up symbols in modules.

gtk-widget-factory was updated to use the new GtkBuilderCScope to add
its custom callback symbols.
So it does it different from gtk-demo, which uses the normal way of
exporting symbols for dlsym() and thereby makes the 2 demos test the 2
ways GtkBuilder uses for looking up symbols.
2019-12-08 06:27:37 +01:00
Benjamin Otte
2baa8b750c builder: Add gtk_builder_set_current_object()
Use it as the default object for expression binds and when connecting
signals. It is intended to work kind of as the "this" object while
parsing. In fact, the term "current object" was stolen from the Java
docs and various C++ tutorials for the this pointer.

Set the current object in gtk_widget_init_template() and
GtkListItemBuilder.

This more-or-less replaces the object passed to
gtk_builder_connect_signals() in GTK3.
2019-12-08 06:27:37 +01:00
Benjamin Otte
1420deb167 builder: Add gtk_builder_lookup_object()
... and use it. This function looks up an object like
gtk_builder_get_object() but generates an error on failure.

Unlike the evil function _gtk_builder_lookup_object() which also
generates an error but hides it for later lookup.

Use this to avoid continuing applying properties when an error was
encountered.
2019-12-08 06:27:37 +01:00
Benjamin Otte
e3e8d72e72 a11y: We can peek here
Avoids instantiating a11y objects when we don't need to.
2019-12-08 06:27:37 +01:00
Benjamin Otte
2c48c1c9d9 treeview: Don't create a cyclic reference
TreeRowReference refs the proxy object, so don't use proxies.
2019-12-08 06:27:37 +01:00
Benjamin Otte
92a1683675 label: Compute label baselines correctly
When we were switching smallest and widest, we were not switching the
baselines.
2019-12-08 05:33:42 +01:00
Benjamin Otte
33bd8f322c builder: Improve error message 2019-12-03 18:12:25 +01:00
Benjamin Otte
bfe4255807 builder: Allow objects in gtk_builder_value_from_string_type()
Instead of throwing an error, lookup objects with
gtk_builder_get_object().
2019-12-03 18:12:25 +01:00
Benjamin Otte
a15fb95c46 gtk-demo: Use normal way to lookup up symbols
We're a normal application, so we can use the normal way to hook up code
into builder files, which is using dlsym() for the function pointers.

There's no need to to extra work exporting static symbols.
2019-12-03 18:12:25 +01:00
Benjamin Otte
292371932b css: Handle invalid :not() selectors
We weren't correctly ending the ( ) block when encountering an error.

Testcases added.

Fixes #2281
2019-12-03 18:12:25 +01:00
Timm Bäder
564e8f483c Merge branch 'wip/wayland-hidpi-swap-region' into 'master'
Fix HiDPI swap regions on Wayland

See merge request GNOME/gtk!1228
2019-12-03 16:05:08 +00:00
Jonas Ådahl
ba74f41a70 wayland/vulkancontext: Fix present region on HiDPI
VkPresentRegionsKHR is expected to operate in buffer coordinates, but
the region we get passed is in surface coordinates, so it must be scaled.
2019-12-03 16:45:37 +01:00