How can I scroll a Clutter.ScrollActor with a scrollbar? - gtk

I have a a GtkClutter.Embed that holds a complete graph of clutter actors. The most important actor is container_actor that holds a variable number of actors (laid out with a FlowLayout) that may overflow the height allocated to the parent Embed.
At some point, the container_actor takes the stage and be the only actor displayed (along with its children).
At this point I would like to be able to scroll through the content of container_actor.
Making my Embed implementing Gtk.Scrollable gives the ability to have a scrollbar. Also I've noticed that Clutter proposes a Clutter.ScrollActor.
Is using those two classes the recommended way to go?
Or do I need to use implement Gtk.Scrollable and move my container_actor manually on vadjustment.value_changed ?
edit: here's a sample in c for ScrollActor

ClutterScrollActor does not know anything about GtkScrollable or GtkAdjustment, so you will have to implement scrolling manually. It's not necessary to implement GtkScrollable — you just need a GtkScrollbar widget, a GtkAdjustment and some code that connects to the GtkAdjustment::value-changed signal to determine the point to which you wish to scroll the contents of the ClutterScrollActor.

Related

How does the "needsCompositing" bit work?

I'm trying to better understand how the Flutter framework interprets the "needsCompositing" / "alwaysNeedsCompositing" bits.
When the needsCompositing bit is set on a render object, does every single ancestor render object up to the nearest repaint boundary also need compositing (i.e., its own composited layer)? Is this because any of those objects might, say, add a clip which may affect the newly composited child and in order to ensure that it does, a clip layer has to be used instead?
The part that seems surprising is that this would appear to add N new layers for N render objects just because one descendant needs compositing.
If this is true, I suppose this explains why you'd want to organize things into a shallow "repaint boundary sandwich."
needsCompositing is just going to signal to the render object whether it should be pushing a layer or not, which may or may not be true depending on what properties are set on the object. alwaysNeedsCompositing is unconditionally saying that.
It has no effect on ancestors - they can independently need or not need compositing, which again will control how the layer tree is constructed so that composition will happen on the engine side.
On an update, we do pump logic up the tree to make sure things get properly marked dirty (up to the nearest RepaintBoundary). However, individual render objects may respond to that by only pumping the data further up the tree and not setting their needsCompositing to true, if they never actually need compositing.

Understanding Chrome Dev Tools timeline

I'm trying to understand why I have several Long Frames reported by Chrome Dev Tools.
The first row (top of the call stack) in the flame chart are mostly Timer Fired events, triggered by jQuery.Deferred()s executing a bunch of $(function(){ }); ready funcs.
If I dig into the jQuery source and replace their use of setTimeout with requestAnimationFrame the flame chart doesn't change much, I still get many of the rAFs firing within a single frame (as reported by dev tools) making long frames. I'd have expected doing the below pseudocode:
window.requestAnimationFrame(function() {
// do stuff
});
window.requestAnimationFrame(function() {
// do more stuff
});
to be executed on two difference animation frames. Is this not the case?
All of the JS that is executing is necessary, but what should I do to execute it as "micro tasks" (as hinted at, but not explained here https://developers.google.com/web/fundamentals/performance/rendering/optimize-javascript-execution) when setTimeout and rAF don't seem to achieve this.
Update
Here's a zoomed in shot of one of the long frames that doesn't seem to have any reflows (forced or otherwise) in it. Why are all the rAF callbacks here being executed in one frame?
Long frames are usually caused by forced synchronous layouts, which is when you (unintentionally) force a layout operation to happen early.
When you write to the DOM, the layout needs to be reflowed because it has been invalidated by the write operation. This usually happens at the next frame. However, if you try to read from the DOM, the layout happens early, in the current frame, in order to make sure that the correct value gets returned. When forced layout occurs, it causes long frames, leading to jank.
To prevent this from happening, you should only perform the write operations inside your requestAnimationFrame function. The read operations should be done outside of this, so as to avoid the browser doing an early layout.
Diagnose Forced Synchronous Layouts is a nicely explained article, and has a simple example demo for detecting forced reflow in DevTools, and how to resolve it.
It might also be worth checking out FastDom, which is a library for batching your read and write. It is basically a queuing system, and is more scalable.
Additional Source:
What forces layout / reflow, by Paul Irish, contains a comprehensive list of properties and methods that will force layout/reflow.
Update: As for the assumption that multiple requestAnimationFrame calls will execute callbacks on separate frames, this is not the case. When you have consecutive calls, the browser adds the callbacks to a document list of animation callbacks. When the browser goes to run the next frame, it traverses the document list and executes each of the callbacks, in the order they were added.
See Animation Frames from the HTML spec for more of the implementation details.
This means that you should avoid using the consecutive calls, especially where the callback function execution times combined exceed your frame budget. I think this would explain the long frames that aren't caused by reflow.

Use Z-order and position to organize open forms in MS Access

For MS Access 2010, I need a way to flexibly maintain the position and Z-order when a dozen forms are open. There can be multiple instances of the Parent form, and each one can lead to multiple instances of the Child form (some background here).
I want the user to be able to choose which form is top-most -- which means I don't want any forms set as Popup. Also, I want the Z-Order essentially preserved when a new Child opens. As the Child opens, the Parent loses the focus; at that point I'd like the Parent to drop back to its former position in the Z-order. I could add requirements along this line, but you get the idea ... I imagined a default behavior might do what I want, but if I have to assign Z-order locations from an array or something like that, I could accept that.
I also want to control the on-screen position of the Child forms (I mean only when they are first opened; they can be repositioned). If they open with the same X,Y coordinates, they'll appear stacked on top of each other and the user will have to reposition the top instance in order to see the others. That is inconvenient and, more important I think, disorienting.
So far I'm not able to have it all. I can get a nice cascade result by specifying X,Y positions, but it stops working when I use the flags to poke at the Z-order.
I've been using the API...
Declare Sub SetWindowPos Lib "user32" ( _
ByVal Hwnd&, _
ByVal hWndInsertAfter&, _
ByVal X&, ByVal Y&, ByVal cX&, _
ByVal cY&, ByVal wFlags&)
Global Const HWND_TOP = 0
Global Const HWND_TOPMOST = -1
SetWindowPos Hwnd, HWND_TOP, lngPosX, lngPosX, 0, 0, SWP_NOSIZE
I have different results when I try options for hWndInsertAfter& and wFlags&. Also when I set forms as Popup (results are better, but as mentioned, I want the user to bring any form to the top; therefore no Popup).
(Hmm... I bet Popup (and 'Modal`) are precisely what bring the API into best usage, because while a "must-answer" dialog is showing, control basically reverts to Windows. Confirm?)
My biggest frustration is that documentation for the API seems fragmentary and incoherent. And I wonder, am I stuck with that API? Is there something else I can use? I'd love a VBA solution apart from the API, but I guess this is what the API is for. Still, is there a method I'm missing?
I can post my variant attempts in more detail, but I feel I've been shooting in the dark, so I will wait on your feedback.
Update
I tried Reading The Manual. I tried twiddling with "form ownership" and NO/TOPMOST. For the Child form, I still have to choose between:
Being able to set the position upon opening
Being able to bring the Parent form back "on top" of the Child
Sorry for the late answer! I bumped into this while searching for a related issue.
One way to manage Z-order 'Access-only' is to use Form.SetFocus. The general solution outline:
Keep an array or collection of your form names and their Z-orders
When Z-order changes:
Resort your list to reflect the new Z-order
Turn screen updating off: Application.Echo False
Iterate through your list of forms in reverse Z-order. Use Form.SetFocus for each form. This will put the highest form on top.
Turn screen updating back on: Application.Echo True
This should work as long as all of your forms are non-modal.
If you need modal forms, be aware that they are by default on top, and you can only have one modal form open at a time. You can still use the above logic, just be sure to set Form.Modal = False for every form not on the top.
This is the 'how' answer, but I can't offer advice as to whether this is a sound approach for your application.
I believe the solution doesn't exist, or isn't worth pursuing because it would lean on Windows API libraries that may not be available in a few years. (This pessimism is not based on specific insights; but in general I see big pressures on the Windows user interface, so it's easy to imagine things shifting.)
I see some other hazards. Users will open numerous windows; resources will fail at some point, and probably before then they'll have lost any advantages from a human analytical point of view. Nonetheless they'll continue past the point of diminishing returns. Also I can expect to find a few pitfalls that gobble development time and lead in the end to complaints no matter how much time I spend mitigating them. Think "multi-user" and you'll know what I mean.
Instead, I need to re-think the approach. The application offers complicated and sometimes volumnous information. There's a way to do it. Not this way.
I might delete this OP, but it's gotten three up-votes, so I'll wait and see what you think. I can always punt to community wiki.

gtk.fixed layout laid out events?

I have a gtk.Fixed. I move components inside it around using:
myFixed.move( myEventBox, new_x, new_y )
What event do I listen for to know when myEventBox has been rendered at its new position?
Do I connect to the fixed or the eventbox?
MORE INFO:
I need this information so I know when it is safe to queue a video under the eventbox... if I do it too soon (e.g. right after calling myFixed.move) I can see the glitch. Currently getting around this with a gobject.idle_add.
To be honest, I am not aware of any such event. The object should move immediately and redraw the screen, but I don't think any signal is emitted when that happens.
The PyGTK documentation is very comprehensive, and it will list all of the functions and events of every object in the library. In searching (through both the gtk.Container (for fixed) and gtk.Widget (for fixed and eventbox) signal lists, I can't find any such event. The closest thing is an "add" signal in gtk.Container, but I don't think that's what you're looking for.
If the object is not moving, please post your code, because there is probably a subtle error.
If the object is moving just fine and you just want the event/signal, you may have to simulate it yourself. Write the function you want to be called as soon as the object is moved in a function (def) inside "__ init __", and then call that function in code in the line right after "myFixed.move".

Interacting with events and listeners in MATLAB

I want to write GUI code that is orthogonal. Lets say I have a circle class and a square class and they need to interact. Right now, to get the circle and square talking to each other - say the circle object sends a message to the square object, I would use something like square_obj.listen_for_circle(circle_obj) where listen_for_circle is a method that implements an addlistener.
This is a problem for me since now the two objects are linked - and removing one object from my code would break it. What I am looking to do is for the circle_obj to be able to broadcast a global message say 'CIRCLE_EVENT'. Additionally square_obj would be listening for global message broadcasts of type 'CIRCLE_EVENT', and upon hearing the event - does some action.(Ahhh, now the objects have no links to each other in the code base!)
Is this possible or even reasonable in MATLAB? (or maybe i'm just going crazy).
As always, advice much appreciated.
I'm not really sure why addlistener is problematic for you. It basically just adds an event listener that doesn't do anything if the event-origin object (the circle) is deleted.
Alternately you can use event.listener or handle.listener. They are undocumented but work well, and are widely used within the Matlab codebase (m-files). See explanation here: http://UndocumentedMatlab.com/blog/continuous-slider-callback/#Event_Listener