I’m trying to display an SVG image which needs to be fit into a container that has a fixed height and width. The image is being loaded from resources. I’m trying to do the equivalent of a
`<img style=”height: 3rem; width: 3rem; object-fit: contain"`.
Right now I have
fn build_logo_widget() → gtk4::Image {
let image = gtk::Image::from_resource(logo_resource_for_theme());
image.set_hexpand(false);
image.set_vexpand(false);
image.set_halign(gtk4::Align::End);
image.set_valign(gtk4::Align::Start);
image.set_size_request(120, 30);
image.set_pixel_size(80);
image
}
set_size_request is just increasing the width and height of the container.
set_pixel_size is increasing the size. But it’s also adding the padding at the top and bottom and keeping the image center aligned. It’s behaving like scaling factor as far as I have understood.
I have also tried gtk4::Picture but it’s displaying the SVG at the original size and not respecting any styling I try to do.
How do I achieve this behavior?