Skip to content

Commit

Permalink
calculate -> calc
Browse files Browse the repository at this point in the history
  • Loading branch information
emilk committed Sep 15, 2023
1 parent 6e4db12 commit de0a03f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
4 changes: 2 additions & 2 deletions crates/egui/src/widgets/button.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ impl Widget for Button<'_> {

let image_size = if let Some(image) = &image {
image
.load_and_calculate_size(ui, space_available_for_image)
.load_and_calc_size(ui, space_available_for_image)
.unwrap_or(space_available_for_image)
} else {
Vec2::ZERO
Expand Down Expand Up @@ -610,7 +610,7 @@ impl<'a> Widget for ImageButton<'a> {
let original_image_size = tlr.as_ref().ok().and_then(|t| t.size());
let image_size = self
.image
.calculate_size(available_size_for_image, original_image_size);
.calc_size(available_size_for_image, original_image_size);

let padded_size = image_size + 2.0 * padding;
let (rect, response) = ui.allocate_exact_size(padded_size, self.sense);
Expand Down
13 changes: 6 additions & 7 deletions crates/egui/src/widgets/image.rs
Original file line number Diff line number Diff line change
Expand Up @@ -239,15 +239,14 @@ impl<'a, T: Into<ImageSource<'a>>> From<T> for Image<'a> {
impl<'a> Image<'a> {
/// Returns the size the image will occupy in the final UI.
#[inline]
pub fn calculate_size(&self, available_size: Vec2, original_image_size: Option<Vec2>) -> Vec2 {
pub fn calc_size(&self, available_size: Vec2, original_image_size: Option<Vec2>) -> Vec2 {
let original_image_size = original_image_size.unwrap_or(Vec2::splat(24.0)); // Fallback for still-loading textures, or failure to load.
self.size
.calculate_size(available_size, original_image_size)
self.size.calc_size(available_size, original_image_size)
}

pub fn load_and_calculate_size(&self, ui: &mut Ui, available_size: Vec2) -> Option<Vec2> {
pub fn load_and_calc_size(&self, ui: &mut Ui, available_size: Vec2) -> Option<Vec2> {
let image_size = self.load_for_size(ui.ctx(), available_size).ok()?.size()?;
Some(self.size.calculate_size(available_size, image_size))
Some(self.size.calc_size(available_size, image_size))
}

#[inline]
Expand Down Expand Up @@ -298,7 +297,7 @@ impl<'a> Widget for Image<'a> {
fn ui(self, ui: &mut Ui) -> Response {
let tlr = self.load_for_size(ui.ctx(), ui.available_size());
let original_image_size = tlr.as_ref().ok().and_then(|t| t.size());
let ui_size = self.calculate_size(ui.available_size(), original_image_size);
let ui_size = self.calc_size(ui.available_size(), original_image_size);

let (rect, response) = ui.allocate_exact_size(ui_size, self.sense);
paint_texture_load_result(
Expand Down Expand Up @@ -389,7 +388,7 @@ impl ImageSize {
}

/// Calculate the final on-screen size in points.
pub fn calculate_size(&self, available_size: Vec2, original_image_size: Vec2) -> Vec2 {
pub fn calc_size(&self, available_size: Vec2, original_image_size: Vec2) -> Vec2 {
let Self {
maintain_aspect_ratio,
max_size,
Expand Down

0 comments on commit de0a03f

Please sign in to comment.