Skip to content

Commit

Permalink
Use new API in WidgetGallery
Browse files Browse the repository at this point in the history
  • Loading branch information
emilk committed Sep 13, 2023
1 parent f6df497 commit 9af8b77
Showing 1 changed file with 4 additions and 14 deletions.
18 changes: 4 additions & 14 deletions crates/egui_demo_lib/src/demo/widget_gallery.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,6 @@ pub struct WidgetGallery {
#[cfg(feature = "chrono")]
#[cfg_attr(feature = "serde", serde(skip))]
date: Option<chrono::NaiveDate>,

#[cfg_attr(feature = "serde", serde(skip))]
texture: Option<egui::TextureHandle>,
}

impl Default for WidgetGallery {
Expand All @@ -39,7 +36,6 @@ impl Default for WidgetGallery {
animate_progress_bar: false,
#[cfg(feature = "chrono")]
date: None,
texture: None,
}
}
}
Expand Down Expand Up @@ -111,14 +107,8 @@ impl WidgetGallery {
animate_progress_bar,
#[cfg(feature = "chrono")]
date,
texture,
} = self;

let texture: &egui::TextureHandle = texture.get_or_insert_with(|| {
ui.ctx()
.load_texture("example", egui::ColorImage::example(), Default::default())
});

ui.add(doc_link_label("Label", "label,heading"));
ui.label("Welcome to the widget gallery!");
ui.end_row();
Expand Down Expand Up @@ -206,16 +196,16 @@ impl WidgetGallery {
ui.color_edit_button_srgba(color);
ui.end_row();

let img_size = 16.0 * texture.size_vec2() / texture.size_vec2().y;

ui.add(doc_link_label("Image", "Image"));
let egui_icon = egui::include_image!("../../assets/icon.png");
ui.add(egui::Image::new(egui_icon).max_size(Some(egui::Vec2::splat(32.0))));
ui.add(egui::Image::new(egui_icon.clone()));
ui.end_row();

ui.add(doc_link_label("ImageButton", "ImageButton"));
if ui
.add(egui::ImageButton::new((texture.id(), img_size)))
.add(egui::ImageButton::new(
egui::Image::from(egui_icon).max_size(egui::Vec2::splat(16.0)),
))
.clicked()
{
*boolean = !*boolean;
Expand Down

0 comments on commit 9af8b77

Please sign in to comment.