A "better" way of resizing GtkTreeViewColumns... but how do I do it? - gtk

I'm trying to create GtkTreeViewColumn resizing functionality like how it is in Thunderbird. Key word here is "trying". So far I haven't succeeded.
The easiest way to understand how this resizing works is to fire up Thunderbird and play with resizing the columns yourself, but basically the way it works in Thunderbird is if you drag, say, column #1 to the right, this increases the width of column #1, at the same time decreasing the width of column #2 by the same amount. This happens until column #2 reaches its minimum width (for example, 0 pixels). At this point, continuing to drag column #1 to the right still increases the width of column #1, but since column #2 cannot be shrunken any further, then column #3 is shrunken until it reaches its minimum width. This continues until all of the columns to the right of column #1 are at their absolute minimum widths; at this point, column #1 can't have its width increased anymore, so continuing to drag the column to the right does nothing.
While the mouse button is still held down, if you were to start dragging column #1 to the left again (to shrink it), what would happen is what happened above, except in reverse order. As column #1 shrinks, the last column in the tree view grows until reaching its width at the time the original drag (when the mouse was first pressed down to start the drag) first started. At this point, the second to last column grows until reaching its width at the time of the original drag... and so on.
Then of course, when column #1 reaches its minimum width, column #0 shrinks until it reaches its minimum width. Since column #0 is the first column, then continuing to drag column #1 to the left won't shrink it anymore; in fact, nothing will happen.
One of the major benefits to handling dragging like this is: the columns will never be resized "out of bounds" and cause the GtkTreeView to grow in width or, if the GtkTreeView containing the GtkTreeViewColumns is packed into a scrolled window, cause horizontal scrollbars to appear. Having these scrollbars appear, or the tree view grow in width (and thus increase the width of the window) is super annoying for the user and makes things look a lot less clean. Which is, I assume, why Thunderbird handles it this way, as do other applications.
So, anyway, my problem is that I just can't figure out how to do this in GTK+. I'm wondering if it's even possible? If it is... how would it be done? I'm clueless here.
As far as I know, the only signal you can connect to to know if a GtkTreeViewColumn has been resized is the notify::width signal. Problem is, you can't return TRUE or FALSE from the signal handler function to tell GTK+ not to allow the resize to go through. It's just a notification signal. So that prevents me from, for example, detecting that all columns to the right of the one being dragged have reached their minimum widths and then telling GTK+ to stop the column from having its width increased anymore.
Another problem: if you call gtk_tree_view_column_set_fixed_width() -- what I am doing is calling gtk_tree_view_column_set_resizable(column, TRUE) and then calling gtk_tree_view_column_set_sizing(column, GTK_TREE_VIEW_COLUMN_FIXED) when creating the columns, by the way -- within the notify::width signal, it creates an infinite loop, which I don't know how to prevent, either.
Again, any help would be much appreciated.

The infinite loop can be broken by temporarily blocking signals, like this:
g_signal_handler_block(...);
/* update width */
g_isgnal_handler_unblock(...)

I got the same problem and my approach was to use 2 functions for the resize signal:
The first one checked for connected/disconnected of handler; if not connected connect it and save the handler ID.
The second just resized all columns proportionally and then disconnect the signal with the saved handler ID.

Related

ag-grid is not rendering all my rows.

I am scratching my head on this one but I am starting to think it may be a bug in ag-grid.
I have a grid that is (inconsistently) only rendering 3 rows of data when I am expecting 5. There is a blank space for the 2 missing rows.
The pager says 5 rows, and the grid seems to know there are 5 rows (when I step through the javascript debugger). In fact, if I sort on the grid, or resize the window such that the grid provides scrollbars, the other 2 rows suddenly appear.
Has anyone seen anything like this?
----More detail but may not be relevant:
On this particular page, I have 2 grids. There is a main grid that has links in it, and when you click into a link, it hides the main grid and shows you the other grid. I was concerned that that was coming into play somehow, but I actually have seen this on another page I'm working on that has just 1 grid.
Based on various explanations I have seen online, I tried this and it appears to be working:
setTimeout(function ()
{
$scope.gridOptions.api.refreshView();
}, 0);
I call this after
params.successCallback(pResponse.data);
which invokes the grid's callback
Based on your observations that sorting or resizing the window makes the data appear, I get the feeling that the code needs to force the screen refresh somehow.
this.gridOptions.api.refreshView();
I had a similar issue and discovered that my gridOptions.rowHeight value did not match the actual height of my rows (I had a checkbox element in each row that was pushing the height taller).
As it turns out, the AgGrid row renderer uses absolute pixel location to calculate which rows should be visible. So if your actual row heights result in the rows not being in the exact position they are expected to be in, the renderer will skip them.
Ironically, the positioning code uses actual position, so the rows that do get rendered are positioned as if the skipped rows are still there, resulting in the blank space described by the OP.

gtk treeview column resizing and horizontal scrollbar

I have a gtk treeview (inside a GtkScrolledWindow) with two columns.
If I set both columns to the default sizing policy, I have a horizontal scrollbar for the treeview but the columns can't be sized down by the user, which is impractical.
If I set both columns to setSizing Fixed, fixed width 120, I get a nice display and the columns can be resized, but there is no horizontal scrollbar in the treeview (since the columns size down to fit in the width of the treeview I guess).
If I set the first column to setSizing fixed, fixed width 120, the second one to automatic, only the second column is displayed (???).
I would like that by default the first column takes let's say at most 60% of the display, the second column can go all the way and I have a horizontal scrollbar. Certainly I want the user to be able to resize them up or down, not as with the default policy, that you can resize them down!
That's why I tried the first column fixed, the second automatic, it was promessing but I don't understand why the first column is not displayed at all in that configuration.
I add the cell renderers with packstart true, I tried false but it didn't change anything, also I tried setting the expand for the columns to true or false, which didn't have any effect.
Note I'm using the gtk2hs haskell bindings but I'm certain it would be the same in any other gtk binding. Just mentioning if people will ask for code samples.
I'm pretty sure this is a common problem... I'd say nautilus is fixing it the way I'd like to fix it, but I think digging in the nautilus source is going to be quite long...
EDIT well i've discovered the cell renderer's ellipsize setting also has an effect. Setting it to end for the first column and none for the second should be what i want but then the first column is very small and cannot be expanded through resize...
EDIT2 well for now i've moved to word wrapping for the cell renderer, that way i don't have to bother with a horizontal scrollbar... Still curious for the solution to that question though.

GTK+ 3: Restore TreeViewColumn widths without making them behave as if manually sized

I have a TreeView whose columns are all expandable with fixed-mode sizing. I would like to restore the widths of the columns when the user restarts the app. It seems that calling set_fixed_size is the way to do this, but:
If I set only the widths of the columns that the user resized, then the actual column widths end up different from what they were before.
If instead I set all column widths explicitly, then all columns behave as though they had been resized by the user, which is not ideal.
Is there a way to restore the column widths that gets around these problems?
It turns out that expand interferes with fixed_width. In my case, the solution was to set fixed_width and expand=false on columns that the user resized, and expand=true on the others.

Crystal Reports fields won't align

I have several items that I want to line up. The Width and Height of all fields match. Usually I just use the Align, but it's making it worse. My out of line field which is slighly lower, moves way up, way out of line (with align tops)
So I tried using the Size and Position to set it manually. Several objects have a Y of 0.056, but my last one has 0.061. I change the last one to 0.056 and save it. It doesn't appear to be different, and when I look at it again, it's still 0.061. (When I used align, it went up to 0.028!)
I do NOT have Snap to Grid set (my grid size is 0.083). (Nor does turning on Snap to Grid make them align.) The fields have exactly the same formatting. But unless I can magically make them align by hand, they refuse to align. Why?
You've already done a lot of the regular troubleshooting steps. One more ting that I sometimes do is to select all the fields I want to align, then use the arrow keys and move them up into the section above and then back down into their original section. That usually puts them all into the 0 position. If it dosn't work with all of them selected, try each one separately.

GtkTreeViewColumn resizing based on contents

So it turns out that we'd like to use fixed height mode, because it's faster and it doesn't constantly try to update the treeview — we saw a significant decrease in CPU use with a table that, unfortunately, may contain a few thousand rows and some 20-ish columns.
Oddly enough, merely turning off autosizing on all the columns doesn't help, one needs to set fixed height mode too.
But of course, the cell contents are of varying length (they're text and numbers), and it would be nice to update the column size time to time (ie. when I know they should be updated, and not all the time like autosizing unfortunately does).
So what I need is being able to figure out that the newly inserted row / cell has insufficient size (I guess something to do with the GtkCellRendererText and Pango will come handy), and then resize the affected GtkTreeViewColumn using set_fixed_width. I've looked at the source of GTK+ to see what they do when autosizing, but couldn't really make head or tails of it. My main problem here is getting to the text layout and/or the cell size requirements from a given TreeView/ListStore/iter combination.
I use perl-Gtk2, but answers are welcome in any commonly used language.