GTK4 Image Which Fills Parent - gtk4

I am trying to create an image which fills its parent widget in both dimensions while keeping the aspect ratio. In gtk4-rs I did
let picture_widget = gtk::Picture::builder()
.hexpand(true)
.vexpand(true)
.halign(gtk::Align::Fill)
.valign(gtk::Align::Fill)
.keep_aspect_ratio(true)
.can_shrink(true)
.build();
But this fills only one dimension of the parent. However, I would like to overflow the parent in that dimension, such that both dimensions are filled.
Generally, I think my goal could be achieved by child.set_size_request(parent_width, parent_height). That needs to be done every time the parent size changes.
Idea 1: Listen to size_allocate signal of parent. Does not work, because the size_allocate signal has been removed: https://docs.gtk.org/gtk4/migrating-3to4.html#adapt-to-gtkwidgets-size-allocation-changes
Idea 2: Subclass Picture and set size in allocate(). But Picture is apparently not subclassable. The compiler tells me that
type ParentType = gtk::Picture; => the trait IsSubclassable<FillingPicture> is not implemented for Picture
Idea 3: Subclass Widget and use Picture inside (from https://github.com/gtk-rs/gtk4-rs/issues/393). I do not know how to then link all the function calls together such that the Picture is actually shown. (It also feels wrong to do this. If this was easily possible, Picture would probably be subclassable?)
Idea 4: Reimplement the whole Picture class from scratch. Seems overkill and too much maintenance overhead just for a simple resize.
Idea 5: Use CSS properties to fill the parent. I tried setting width and height to 100%, but apparently relative sizes are not allowed. Also the cover CSS attribute is not supported.
Idea 6: Drop GTK
Any other ideas or fixes for the ideas above?

Just getting with the same problem yesterday. The one that works for me was the 5th idea...
Idea 5: Use CSS properties to fill the parent. I tried setting width and height to 100%, but apparently relative sizes are not allowed. Also the cover CSS attribute is not supported.
But using background-image instead.
box.nameofclass {
background-image: url("resource:///{your_path_in_gresources}/pic.jpg");
background-position: center;
}
More info:
Backgrounds
I'm just beginning with gtk4-rs, so it may not be the best way to do it. It would be great to set this via properties tbh.

Related

React Three Fiber: How to switch between TrackballControls and OrbitControls?

I'm trying to create a viewer in react-three-fiber with react-three/drei where I can switch between OrbitControls and TrackballControls.
The problem is that when switching from TrackballControls to OrbitControls, the axis that the camera rotates around changes as of course the TrackballControls change the up-vector when moving around.
I created a couple of minimal examples in codesandbox to explain my approach to solve this and to show where I'm stuck.
Base Case
This shows the initial attempt to switch between the different control types:
https://codesandbox.io/s/r3f-camera-controllers-base-neu07
Attempt #1
Obviously, this does not work as it is, so I tried resetting the up-vector to (0, 1, 0) and calling lookAt(). This seems to work initially as the camera reorients itself correctly (this is how it should look like). However, it does not rotate around the correct axis and instead moves in strange arcs. See here:
https://codesandbox.io/s/r3f-camera-controllers-set-up-vector-yps4k
Attempt #2
For this question it was suggested to create a new camera which I also tried but ultimately it lead to the same result. This here is my attempt at creating a new camera and copying some values to the new camera:
https://codesandbox.io/s/r3f-camera-controllers-reset-camera-3cih0
Any help appreciated. Thanks!
After a couple of days, I finally figured out a way to achieve what I want.
Instead of trying to remove the different controls, I just enable and disable them separately. I can then call the reset() functions on both Controls via a ref if the control prop changes. To retain the camera position, I can just temporarily store it before resetting the controls.
You can find an example here.

Looking for guidance on how to add custom class to sections and modules in Squarespace?

I have a client who is using Squarespace and asked that I fix a mobile stacking issue.
I have 2 rows that have image + text alternating side by side. This looks fine on desktop, but the on mobile the stacking order is wrong.
Desktop Stacking:
Image + Text
Text + Image
Current Mobile Stacking:
ImageĀ 
Text
Text
Image
Ideal Stacking:
Image
Text
Image
Text
Typically I was accomplish this by alternating the sections with a custom class, but I'm not seeing any place to add this. Are you able to add custom classes to sections?
Any help is appreciated. Thanks!
It is not possible to directly edit the markup that appears within Squarepace's default grid and block system (they call it, "LayoutEngine"). Generally speaking, one must either write their own HTML within a Code Block (or via Code Injection points), or use JavaScript to alter the HTML after the default markup is loaded onto the page.
But in your case specifically, this is a common problem in Squarespace, and it is usually solved with just CSS, using a combination of:
first-child, last-child and nth-child selectors, and/or
the > direct-descendant/child-combinator, and/or
specific block IDs (each sqs-block has a unique id attribute), and/or
a media query so that the rules only take affect after your mobile breakpoint is reached, and/or
either display:flex with the order property. or display:table-header with display:table-footer in order to force a different stacking order.
The specific CSS often varies greatly based on the specific circumstance, whether you're trying to reorder blocks, columns, or rows. The similar question linked to above provides a specific solution to the same problem you are trying to solve, but the code that solves it in your case may look quite different, though it will likely use a combination of the five things mentioned above.
Or, you can use JavaScript to target the blocks and add your own classes, then write the CSS with those classes. Even in that case, the general approach is the same.

I want bigger pixbufs rendered onto GtkSourceGutter

It seems that the size of the source marks rendered with GtkSourceGutterRenderer are remotely tied up to the size of the text in the GtkSourceView. I want to have bigger pixbufs, without making the text font size bigger and to achieve that I concluded I have to subclass a widget and override its draw signal handler.
However I have no idea which widget to subclass on. Surely one of you knows?
I think it's probably GtkSourceGutterRendererPixbuf itself that you have to subclass. If not that, then probably GtkSourceGutterRenderer with a lot of duplicated code from GtkSourceGutterRendererPixbuf.

Codename one SpanLabel text does not occupying full width

I'm using the SpanLabel Component, but on the screen the text content does not occupying the full width when text size is lower
Someone can help please?
This can happen if the width isn't deterministic. The SpanLabel won't be able to reflow and at best will cause only its own Container to resize. There are two solutions:
Deterministic hierarchy - this is generally best but not always possible
Use TextArea - sometimes this works around the issue by reducing the hierarchy depth.
Deterministic layout means that the size of the elements is determined in a clear way by the hierarchy. E.g. BoxLayout.Y is deterministic on the X axis as it gives the components on the X axis all available space. FlowLayout isn't deterministic as it gives components their preferred size.
Some layouts can go back and forth and vary in determinism based on their axis.
This is important because when we layout the components we go from top down. So we go through the Form to its children asking each for their preferred size. If at this point the SpanLabel doesn't know its size it can give the wrong value and we can't really fix that later as we don't reflow the UI. Reflow would create a potential infinite loop and a performance problem at best.
We try to workaround some of this behavior by making a revalidate() call within TextArea but that has its limits. If the hierarchy is too deep the preferred size is already set and won't adapt. SpanLabel is just a Container with a TextArea and a Label (for the icon). So by only using a TextArea you'd slightly simplify the hierarchy and it sometimes might be enough. E.g.
TextArea t = new TextArea(myText);
t.setEditable(false);
t.setFocusable(false);
t.setUIID("Label");

Textured resizable buttons with Core Image filter and appearance proxy iOS

The app I'm writing involves buttons that have a slight noise filter texture, which can be any size. For a standard button I'd simply use resizableImageWithCapInsets: but due to the texture, this causes unusual artefacts to appear on the resulting button.
A solution I have in mind, is to use the Core Image monochrome filter combined with the random noise filter to add the noise texture to a plain image. In theory this works, and in practice this has been shown to work (One example here) but these are all in cases where the button size is known at the point of invoking the CI code.
What I'm looking to do, is use the appearance proxies, so across the app I can simply set the style of UIBarButtonItems for instance.
Is there a way I can apply these CI filters to the buttons through the appearance proxies or isn't this possible? Would something like a category on UIImage to add noise work? I'm not entirely sure at which point the appearance proxy would actually invoke that code.
Any help is appreciated
OK So I finally solved it but found out some stuff on the way.
It seems you can create a category on UIImage and use that in the appearance proxy. I created a category to add noise, and it seemed to partly work, but I couldn't get it looking how I wanted as it wasn't quite rendering properly, but in the process of coding this discovered another method
resizableImageWithCapInsets:resizingMode:
Because the texture I was dealing with was simply noise, it could be tiled, so rather than the image now being stretched, the centre of the image is instead tiled which gives me the appearance I needed :)

Resources