Skip to content

Commit

Permalink
Improve size logic
Browse files Browse the repository at this point in the history
NOTE: `:image-height` is ignored even if `:image-width` is declared, this is a default behavior of `set_size` method
  • Loading branch information
hypernova7 committed Aug 5, 2024
1 parent b8fc6cf commit 906497e
Showing 1 changed file with 5 additions and 9 deletions.
14 changes: 5 additions & 9 deletions crates/eww/src/widgets/widget_definitions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -546,15 +546,11 @@ fn svg_to_pixbuf(

let pixbuf_svg = gtk::gdk_pixbuf::PixbufLoader::with_type("svg")?;

if image_width >= 0 && image_height == -1 {
pixbuf_svg.set_size(image_width, image_width);
}
if image_width == -1 && image_height >= 0 {
pixbuf_svg.set_size(image_height, image_height);
}
if image_width >= 0 && image_height >= 0 {
pixbuf_svg.set_size(image_width, image_height);
}
match (image_width, image_height) {
(w, h) if w > 0 || h > 0 => pixbuf_svg.set_size(w, h),
// Add default size to prevent widget overflowing, if image is too big
_ => pixbuf_svg.set_size(24, 24),
};

let svg_buf: Vec<u8> = svg_data.as_bytes().to_vec();
pixbuf_svg.write(&svg_buf)?;
Expand Down

0 comments on commit 906497e

Please sign in to comment.