Image and ImageButton will no longer stretch to fill a justified layout

This commit is contained in:
Emil Ernerfeldt 2021-01-11 18:14:34 +01:00
parent 4933bb3c30
commit d344c9d9a3
4 changed files with 16 additions and 15 deletions

View file

@ -24,6 +24,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
### Fixed 🐛
* Fixed a bug that would sometimes trigger a "Mismatching panels" panic in debug builds.
* `Image` and `ImageButton` will no longer stretch to fill a justified layout.
## 0.7.0 - 2021-01-04

View file

@ -822,9 +822,9 @@ impl Ui {
response
}
/// Show an image here with the given size
pub fn image(&mut self, texture_id: TextureId, desired_size: impl Into<Vec2>) -> Response {
self.add(Image::new(texture_id, desired_size))
/// Show an image here with the given size.
pub fn image(&mut self, texture_id: TextureId, size: impl Into<Vec2>) -> Response {
self.add(Image::new(texture_id, size))
}
}

View file

@ -328,9 +328,9 @@ pub struct ImageButton {
}
impl ImageButton {
pub fn new(texture_id: TextureId, desired_size: impl Into<Vec2>) -> Self {
pub fn new(texture_id: TextureId, size: impl Into<Vec2>) -> Self {
Self {
image: widgets::Image::new(texture_id, desired_size),
image: widgets::Image::new(texture_id, size),
sense: Sense::click(),
frame: true,
selected: false,
@ -379,8 +379,8 @@ impl Widget for ImageButton {
} = self;
let button_padding = ui.style().spacing.button_padding;
let desired_size = image.desired_size() + 2.0 * button_padding;
let (rect, response) = ui.allocate_at_least(desired_size, sense);
let size = image.size() + 2.0 * button_padding;
let (rect, response) = ui.allocate_exact_size(size, sense);
if ui.clip_rect().intersects(rect) {
let visuals = ui.style().interact(&response);
@ -400,7 +400,7 @@ impl Widget for ImageButton {
let image_rect = ui
.layout()
.align_size_within_rect(image.desired_size(), rect.shrink2(button_padding));
.align_size_within_rect(image.size(), rect.shrink2(button_padding));
image.paint_at(ui, image_rect);
}

View file

@ -6,17 +6,17 @@ use crate::*;
pub struct Image {
texture_id: TextureId,
uv: Rect,
desired_size: Vec2,
size: Vec2,
bg_fill: Color32,
tint: Color32,
}
impl Image {
pub fn new(texture_id: TextureId, desired_size: impl Into<Vec2>) -> Self {
pub fn new(texture_id: TextureId, size: impl Into<Vec2>) -> Self {
Self {
texture_id,
uv: Rect::from_min_max(pos2(0.0, 0.0), pos2(1.0, 1.0)),
desired_size: desired_size.into(),
size: size.into(),
bg_fill: Default::default(),
tint: Color32::WHITE,
}
@ -42,8 +42,8 @@ impl Image {
}
impl Image {
pub fn desired_size(&self) -> Vec2 {
self.desired_size
pub fn size(&self) -> Vec2 {
self.size
}
pub fn paint_at(&self, ui: &mut Ui, rect: Rect) {
@ -51,7 +51,7 @@ impl Image {
let Self {
texture_id,
uv,
desired_size: _,
size: _,
bg_fill,
tint,
} = self;
@ -73,7 +73,7 @@ impl Image {
impl Widget for Image {
fn ui(self, ui: &mut Ui) -> Response {
let (rect, response) = ui.allocate_at_least(self.desired_size, Sense::hover());
let (rect, response) = ui.allocate_exact_size(self.size, Sense::hover());
self.paint_at(ui, rect);
response
}