How do I find the next widget in a given direction in GTK+? - gtk

I want to find out which widget is in a given direction in GTK+, i.e. doing what the "move-focus" signal does, but without actually changing the focus. What I have in mind is a function that takes a GtkWidget * and a GtkDirectionType and returns the GtkWidget in the given direction (if any).
What I want this for is to ultimately enumerate the widgets inside a specific GtkFrame in my UI definition, in order from left to right. I.e. basically create a list of widgets from leftmost to rightmost, inside my GtkFrame (or in the general case, inside any container).
I've tried to search the GTK documentation but haven't found anything that doesn't also change focus.

Failing any other approach, the way I'm going forward with is to copy a selected set of static functions from the library implementation of GtkContainer and put them in a file in my own application, modifying them to suit my needs.
More specifically, the function gtk_container_focus_sort_left_right() and any local functions that it depends on. This includes the GCompareFunc left_right_compare() and get_allocation_coords().

Assuming the directions you care about are "Forward" and "Backward", it sounds like you want to use gtk_container_get_focus_chain() on the frame: it does pretty much what it says on the tin: you get a list of widgets in order of focus when tabbing.

Related

How to build a tree in GTK4 (>= 4.10)

As the document said, TreeView in GTK4 has been deprecated since 4.10. The recommended replacement for it is ColumnView. However, I can't find clear documentation or example about how to build a treeView-like widget in GTK4 by ColumnView.
I found maybe TreeExpander related to it but I still don't know how to deal with it.
A very brief outline of what I did:
Familiarize yourself with how the new dynamic list widgets (Gtk.GridView and Gtk.ColumnView) work for a flat model (GLib.ListStore). There is example code in the Demo app.
Create a Gtk.TreeListModelCreateModelFunc function that takes a model item as a parameter and, if that item has children (e.g. is a folder in a filesystem model), creates and returns a Gtk.ListStore to hold the children. If the child items are already available then they can also be appended to the child model here. This means the child items are preloaded whether or not the row is expanded. For startup performance reasons, you might want to arrange to load them when the row is actually expanded which is more difficult - in this case you have to add a dummy child to the model else the expander will not be displayed.
Create a Gtk.SignalListItemFactory.
In the setup handler, create a display widget as usual then instead of using your display widget as child of the Gtk.ListItem, you create a Gtk.TreeExpander, and make that the child the Gtk.ListItem and make the display widget a child of the expander.
In the bind handler, get the display widget and model item from the supplied object. A complication here is that the object may be a Gtk.TreeListRow whose item might be another Gtk.TreeListRow so getting to the model item is harder. Bind the widget to the model item as usual. Then get the Gtk.TreeListRow from the Gtk.ListItem position and set the expander's list-row property to it.
If you delayed loading the child items then you would need to detect when the row is first expanded. You can connect to the notify signal for the Gtk.TreeListRow.expanded property to do this.
Use a Gtk.TreeListModel with a GLib.ListStore as its root_store as the model of a Gtk.ColumnView (after wrapping in Gtk.SelectionModel as usual). You must set the passthrough property to false else no expanders appear. If you are loading child items on demand then autoexpand should also be false.
If you are using a Gtk.ColumnView with multiple columns, you only need add the expander to the first column. Otherwise the factory signal handlers or similar to the flat model except the bind handler needs to be adapted for Gtk.TreeListRow parameter.
Simplifications and performance improvements may well be possible or later versions of Gtk4 may introduce some conveniences to make it less fiddly.
I am working on a file browser implementation using the above strategy, currently at https://github.com/elementary/files/tree/gtk4-treelistmodel but this may be merged into other branches (or abandoned!). Note that this branch is under development and contains unresolved bugs but the display of items works.

Flutter Connected Node/Graph of Widgets

What would be the best approach to get started on creating something like this:
I could probably get the second & fourth rows created as horizontally scrolled lists, with the first & third rows as just a row with two cards; but how does one draw a line between or connecting two widgets?
The only way i could think of creating such a view is a little complicated (may be iam wrong)Please enlighten me if someone know any packages or simple widgets or some other way to do it .
The core feature of flutter is reusability of code but sadly until now no one has created a GraphView the way i think of doing this is ... Iam not going to implement it here I'll certainly wouldve give it a try soon.
Although I will Share the way i think of implementing it and the steps required to do so.
1) You have to build a container or any widget to hold whatever data
there is in the node.
2) You have to find the coordinates of each of this nodes using a
function say getOffset(). To do this I found a good youtube tutorial
Video to find position and size of a widget. Its actually quite
simple(after i saw the tutorial) you have to create a key for each
node and pass it as the key parameter to the node widget and use the
initstate funtion to create a function which uses the _newBox =
_theKeyYouCreated.currentContext.findRenderObject() to find that object
3) Then use _newBox.localToGlobal(Offset.zero) to get the location
of the object.
4)Now say you got all the location of the containers now just use this
locations to draw some line between these container.If you want some
more beautiful right angled straight line you can first go to through
the y axis then draw the x axis(of course some extra distance to
compensate for the width and heights of widgets is to be used)
5)Drawing lines between two co-ordinates is a pretty straight forward
thing with
canvas.drawLine(p1, p2, paint);
6)Now if you manage to do this for all pairs of nodes You are done.
Seems like a pretty lot of work.I think there are no packages that do this .But its certainly Time to make one. If you manage to to do this just make it in a reusable form and publish it .I'll certainly give a try to implement this after my current project.

Adding a header to a listbox

I want to know if it's possible to make first two lines (Titles and horizontal line in the image below) always show on top and to be unclickable, to make them something like a header of the current listbox.
I think that your approach is not feasible since this is just not how listboxes work (i.e. it's not a spreadsheet where you fix the top rows). Having said that, you might be able to create something that looks like what you're suggesting, by creating two listboxes one below the other, making the top one read-only or non-interactable (or better yet, make the top one a static text label or a text area).
Another thing I'd like to comment about is the structure of your listbox. In terms of UX, it's uncommon for a user to choose two things at the same time. So even if this makes sense in your context, I would advise to split it into two lists, and have them change each other within callbacks.

Call hierarchy from a certain function

Background:
Working in eclipse, I have two function: do_something and perform_task. I know that do_something calls a number of other functions which in turn call others (and so on and so on) and somewhere down the line perform_task gets called as well.
Since this is a big project, lots of flows and so on, I've already found two different sequences where do_something activates perform_task through some other sequence of functions.
Actuall question:
Is there a way in eclipse to get the call hierarchy of a certain function, but only sequences that will include also a certain other function in the sequence?
Thinking of this in terms of graph paths, we have a directed graph, and instead of asking what are paths to node x, I want to know what are the paths to node x that include node y.
It's not exactly what you're asking for, but might be useful enough:
In the Call Hierarchy view, there's an option to show the callees of the selected method instead of the callers. Look at the view toolbar of Call Hiearchy for the two buttons that depict green dots connected with lines; those button toggle between the two modes.
If you select do_something and open the Call Hierarchy view on it, then set the mode to Show Callees you might be able to explore the various paths out of do_something that lead to perform_task.

How can I sort widgets in GWT?

I have a list of widgets which needs to be sorted. I want to create a container for these list of widgets to re-sort them each time new widget is added. How can I do it?
I can see the following ways:
a straightforward way is place them into arraylist and sort via Comparator, but after a new element is added we have to remove all list from container and add them again, in a new order.
use some sorting container. i have found only CellTable for this. But actually I dont need its rich functionality - I have only one column, dont need to sort on user events, only when new element added or removed, - so is there something else I can utilize in my use case?
GWT 2.4
PS
Actually, I am looking for something, that can be expressed like "widget container backed by widget collection", i.e. I change collection - container changes its contents, how can I implement this, or where can I find it?
PPS
The widgets can be different, thats why I dont think I can use CellTable easily.
There is no straightforward way of re-sorting the elements in the DOM after you add a new widget.
When the widgets are attached you cannot just move them (change their position in the document structure) without detaching and re-attaching.
Well, with absolute positioning you can just change the left-top coordinates to move the items, if it is what you need.
I had a similar problem to solve when I had to sort TreeItem elements (no built-in sort method available). As a workaround, I read all the children into the list and remove them from the parent widget at the same time, then sort these items using Comparator and add them back to parent from the sorted list. Everything is in a single sort() method, which encapsulates all required functionality and kind of simplifies understanding of this code.
"widget container backed by widget collection"
I would like to learn about one like that that also can do sorting and re-attaching on the fly. But it still will be backed by the same detaching-attaching I assume. I would recommend you to write one yourself, that will fit your particular needs. Either you need a Tree or a FlowPanel or anything else - you can extend that and add sort() logic according to context. And override add() method accordingly. So, your first option looks like a possible solution to me.