Image and ImageButton will no longer stretch to fill a justified layout
This commit is contained in:
parent
4933bb3c30
commit
d344c9d9a3
4 changed files with 16 additions and 15 deletions
|
@ -24,6 +24,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
|
||||||
### Fixed 🐛
|
### Fixed 🐛
|
||||||
|
|
||||||
* Fixed a bug that would sometimes trigger a "Mismatching panels" panic in debug builds.
|
* 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
|
## 0.7.0 - 2021-01-04
|
||||||
|
|
||||||
|
|
|
@ -822,9 +822,9 @@ impl Ui {
|
||||||
response
|
response
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Show an image here with the given size
|
/// Show an image here with the given size.
|
||||||
pub fn image(&mut self, texture_id: TextureId, desired_size: impl Into<Vec2>) -> Response {
|
pub fn image(&mut self, texture_id: TextureId, size: impl Into<Vec2>) -> Response {
|
||||||
self.add(Image::new(texture_id, desired_size))
|
self.add(Image::new(texture_id, size))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -328,9 +328,9 @@ pub struct ImageButton {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl 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 {
|
Self {
|
||||||
image: widgets::Image::new(texture_id, desired_size),
|
image: widgets::Image::new(texture_id, size),
|
||||||
sense: Sense::click(),
|
sense: Sense::click(),
|
||||||
frame: true,
|
frame: true,
|
||||||
selected: false,
|
selected: false,
|
||||||
|
@ -379,8 +379,8 @@ impl Widget for ImageButton {
|
||||||
} = self;
|
} = self;
|
||||||
|
|
||||||
let button_padding = ui.style().spacing.button_padding;
|
let button_padding = ui.style().spacing.button_padding;
|
||||||
let desired_size = image.desired_size() + 2.0 * button_padding;
|
let size = image.size() + 2.0 * button_padding;
|
||||||
let (rect, response) = ui.allocate_at_least(desired_size, sense);
|
let (rect, response) = ui.allocate_exact_size(size, sense);
|
||||||
|
|
||||||
if ui.clip_rect().intersects(rect) {
|
if ui.clip_rect().intersects(rect) {
|
||||||
let visuals = ui.style().interact(&response);
|
let visuals = ui.style().interact(&response);
|
||||||
|
@ -400,7 +400,7 @@ impl Widget for ImageButton {
|
||||||
|
|
||||||
let image_rect = ui
|
let image_rect = ui
|
||||||
.layout()
|
.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);
|
image.paint_at(ui, image_rect);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,17 +6,17 @@ use crate::*;
|
||||||
pub struct Image {
|
pub struct Image {
|
||||||
texture_id: TextureId,
|
texture_id: TextureId,
|
||||||
uv: Rect,
|
uv: Rect,
|
||||||
desired_size: Vec2,
|
size: Vec2,
|
||||||
bg_fill: Color32,
|
bg_fill: Color32,
|
||||||
tint: Color32,
|
tint: Color32,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Image {
|
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 {
|
Self {
|
||||||
texture_id,
|
texture_id,
|
||||||
uv: Rect::from_min_max(pos2(0.0, 0.0), pos2(1.0, 1.0)),
|
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(),
|
bg_fill: Default::default(),
|
||||||
tint: Color32::WHITE,
|
tint: Color32::WHITE,
|
||||||
}
|
}
|
||||||
|
@ -42,8 +42,8 @@ impl Image {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Image {
|
impl Image {
|
||||||
pub fn desired_size(&self) -> Vec2 {
|
pub fn size(&self) -> Vec2 {
|
||||||
self.desired_size
|
self.size
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn paint_at(&self, ui: &mut Ui, rect: Rect) {
|
pub fn paint_at(&self, ui: &mut Ui, rect: Rect) {
|
||||||
|
@ -51,7 +51,7 @@ impl Image {
|
||||||
let Self {
|
let Self {
|
||||||
texture_id,
|
texture_id,
|
||||||
uv,
|
uv,
|
||||||
desired_size: _,
|
size: _,
|
||||||
bg_fill,
|
bg_fill,
|
||||||
tint,
|
tint,
|
||||||
} = self;
|
} = self;
|
||||||
|
@ -73,7 +73,7 @@ impl Image {
|
||||||
|
|
||||||
impl Widget for Image {
|
impl Widget for Image {
|
||||||
fn ui(self, ui: &mut Ui) -> Response {
|
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);
|
self.paint_at(ui, rect);
|
||||||
response
|
response
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue