Skip to content

Commit

Permalink
add more examples to ui.image + add include_image macro
Browse files Browse the repository at this point in the history
  • Loading branch information
jprochazk committed Sep 11, 2023
1 parent 269621a commit b42b3a4
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
Binary file added crates/egui/assets/ferris.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
19 changes: 19 additions & 0 deletions crates/egui/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,25 @@ pub fn warn_if_debug_build(ui: &mut crate::Ui) {

// ----------------------------------------------------------------------------

/// Include an image in the binary.
///
/// This is a wrapper over `include_bytes!`, and behaves in the same way.
///
/// It produces a tuple of `(path, bytes): (&str, &[u8])` which can be used
/// directly as a source in [`Ui::image`]:
///
/// ```
/// # egui::__run_test_ui(|ui| {
/// ui.image(egui::include_image!("../assets/ferris.png"));
/// # });
/// ```
#[macro_export]
macro_rules! include_image {
($path: expr) => {
(stringify!($path), include_bytes!($path))
};
}

/// Create a [`Hyperlink`](crate::Hyperlink) to the current [`file!()`] (and line) on Github
///
/// ```
Expand Down
6 changes: 5 additions & 1 deletion crates/egui/src/ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1568,7 +1568,11 @@ impl Ui {
///
/// ```
/// # egui::__run_test_ui(|ui| {
/// ui.image("file://ferris.svg");
/// ui.image("file://ferris.png");
/// ui.image("https://picsum.photos/480");
///
/// const FERRIS: (&str, &[u8]) = egui::include_image!("../assets/ferris.png");
/// ui.image(FERRIS);
/// # });
/// ```
///
Expand Down

0 comments on commit b42b3a4

Please sign in to comment.