How to achieve image scaling and adaptive width #927
-
I want to realize that when the window becomes wider or narrower, the picture can adapt to the window, what should I do?
|
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
Did you try just passing the https://docs.rs/egui/0.15.0/egui/struct.Ui.html#method.available_size as the size for image widget? |
Beta Was this translation helpful? Give feedback.
-
The http example app does this: let mut size = egui::Vec2::new(image.size[0] as f32, image.size[1] as f32);
size *= (ui.available_width() / size.x).min(1.0);
ui.image(texture_id, size); This gets a proportional scaling, if you are interested in that. |
Beta Was this translation helpful? Give feedback.
Did you try just passing the https://docs.rs/egui/0.15.0/egui/struct.Ui.html#method.available_size as the size for image widget?
Just choose whatever container like egui area or central panel and inside the closure get the remaining area to set as image widget size.