47 lines
12 KiB
HTML
47 lines
12 KiB
HTML
<!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><meta name="generator" content="rustdoc"><meta name="description" content="Image loading"><title>egui::load - Rust</title><script>if(window.location.protocol!=="file:")document.head.insertAdjacentHTML("beforeend","SourceSerif4-Regular-6b053e98.ttf.woff2,FiraSans-Regular-0fe48ade.woff2,FiraSans-Medium-e1aa3f0a.woff2,SourceCodePro-Regular-8badfe75.ttf.woff2,SourceCodePro-Semibold-aa29a496.ttf.woff2".split(",").map(f=>`<link rel="preload" as="font" type="font/woff2" crossorigin href="../../static.files/${f}">`).join(""))</script><link rel="stylesheet" href="../../static.files/normalize-9960930a.css"><link rel="stylesheet" href="../../static.files/rustdoc-42caa33d.css"><meta name="rustdoc-vars" data-root-path="../../" data-static-root-path="../../static.files/" data-current-crate="egui" data-themes="" data-resource-suffix="" data-rustdoc-version="1.84.0 (9fc6b4312 2025-01-07)" data-channel="1.84.0" data-search-js="search-92e6798f.js" data-settings-js="settings-0f613d39.js" ><script src="../../static.files/storage-59e33391.js"></script><script defer src="../sidebar-items.js"></script><script defer src="../../static.files/main-5f194d8c.js"></script><noscript><link rel="stylesheet" href="../../static.files/noscript-893ab5e7.css"></noscript><link rel="alternate icon" type="image/png" href="../../static.files/favicon-32x32-6580c154.png"><link rel="icon" type="image/svg+xml" href="../../static.files/favicon-044be391.svg"></head><body class="rustdoc mod"><!--[if lte IE 11]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><nav class="mobile-topbar"><button class="sidebar-menu-toggle" title="show sidebar"></button></nav><nav class="sidebar"><div class="sidebar-crate"><h2><a href="../../egui/index.html">egui</a><span class="version">0.30.0</span></h2></div><div class="sidebar-elems"><section id="rustdoc-toc"><h2 class="location"><a href="#">Module load</a></h2><h3><a href="#">Sections</a></h3><ul class="block top-toc"><li><a href="#image-loading" title="Image loading">Image loading</a><ul><li><a href="#loading-process" title="Loading process">Loading process</a></li></ul></li></ul><h3><a href="#macros">Module Items</a></h3><ul class="block"><li><a href="#macros" title="Macros">Macros</a></li><li><a href="#structs" title="Structs">Structs</a></li><li><a href="#enums" title="Enums">Enums</a></li><li><a href="#traits" title="Traits">Traits</a></li><li><a href="#types" title="Type Aliases">Type Aliases</a></li></ul></section><div id="rustdoc-modnav"><h2 class="in-crate"><a href="../index.html">In crate egui</a></h2></div></div></nav><div class="sidebar-resizer"></div><main><div class="width-limiter"><rustdoc-search></rustdoc-search><section id="main-content" class="content"><div class="main-heading"><span class="rustdoc-breadcrumbs"><a href="../index.html">egui</a></span><h1>Module <span>load</span><button id="copy-path" title="Copy item path to clipboard">Copy item path</button></h1><rustdoc-toolbar></rustdoc-toolbar><span class="sub-heading"><a class="src" href="../../src/egui/load.rs.html#1-562">Source</a> </span></div><details class="toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><h2 id="image-loading"><a class="doc-anchor" href="#image-loading">§</a>Image loading</h2>
|
||
<p>If you just want to display some images, <a href="https://crates.io/crates/egui_extras/"><code>egui_extras</code></a>
|
||
will get you up and running quickly with its reasonable default implementations of the traits described below.</p>
|
||
<ol>
|
||
<li>Add <a href="https://crates.io/crates/egui_extras/"><code>egui_extras</code></a> as a dependency with the <code>all_loaders</code> feature.</li>
|
||
<li>Add a call to <a href="https://docs.rs/egui_extras/latest/egui_extras/fn.install_image_loaders.html"><code>egui_extras::install_image_loaders</code></a>
|
||
in your app’s setup code.</li>
|
||
<li>Use <a href="../struct.Ui.html#method.image" title="method egui::Ui::image"><code>Ui::image</code></a> with some <a href="../widgets/enum.ImageSource.html" title="enum egui::widgets::ImageSource"><code>ImageSource</code></a>.</li>
|
||
</ol>
|
||
<h3 id="loading-process"><a class="doc-anchor" href="#loading-process">§</a>Loading process</h3>
|
||
<p>There are three kinds of loaders:</p>
|
||
<ul>
|
||
<li><a href="trait.BytesLoader.html" title="trait egui::load::BytesLoader"><code>BytesLoader</code></a>: load the raw bytes of an image</li>
|
||
<li><a href="trait.ImageLoader.html" title="trait egui::load::ImageLoader"><code>ImageLoader</code></a>: decode the bytes into an array of colors</li>
|
||
<li><a href="trait.TextureLoader.html" title="trait egui::load::TextureLoader"><code>TextureLoader</code></a>: ask the backend to put an image onto the GPU</li>
|
||
</ul>
|
||
<p>The different kinds of loaders represent different layers in the loading process:</p>
|
||
<div class="example-wrap"><pre class="language-text"><code>ui.image("file://image.png")
|
||
└► Context::try_load_texture
|
||
└► TextureLoader::load
|
||
└► Context::try_load_image
|
||
└► ImageLoader::load
|
||
└► Context::try_load_bytes
|
||
└► BytesLoader::load</code></pre></div>
|
||
<p>As each layer attempts to load the URI, it first asks the layer below it
|
||
for the data it needs to do its job. But this is not a strict requirement,
|
||
an implementation could instead generate the data it needs!</p>
|
||
<p>Loader trait implementations may be registered on a context with:</p>
|
||
<ul>
|
||
<li><a href="../struct.Context.html#method.add_bytes_loader" title="method egui::Context::add_bytes_loader"><code>Context::add_bytes_loader</code></a></li>
|
||
<li><a href="../struct.Context.html#method.add_image_loader" title="method egui::Context::add_image_loader"><code>Context::add_image_loader</code></a></li>
|
||
<li><a href="../struct.Context.html#method.add_texture_loader" title="method egui::Context::add_texture_loader"><code>Context::add_texture_loader</code></a></li>
|
||
</ul>
|
||
<p>There may be multiple loaders of the same kind registered at the same time.
|
||
The <code>try_load</code> methods on <a href="../struct.Context.html" title="struct egui::Context"><code>Context</code></a> will attempt to call each loader one by one,
|
||
until one of them returns something other than <a href="enum.LoadError.html#variant.NotSupported" title="variant egui::load::LoadError::NotSupported"><code>LoadError::NotSupported</code></a>.</p>
|
||
<p>The loaders are stored in the context. This means they may hold state across frames,
|
||
which they can (and <em>should</em>) use to cache the results of the operations they perform.</p>
|
||
<p>For example, a <a href="trait.BytesLoader.html" title="trait egui::load::BytesLoader"><code>BytesLoader</code></a> that loads file URIs (<code>file://image.png</code>)
|
||
would cache each file read. A <a href="trait.TextureLoader.html" title="trait egui::load::TextureLoader"><code>TextureLoader</code></a> would cache each combination
|
||
of <code>(URI, TextureOptions)</code>, and so on.</p>
|
||
<p>Each URI will be passed through the loaders as a plain <code>&str</code>.
|
||
The loaders are free to derive as much meaning from the URI as they wish to.
|
||
For example, a loader may determine that it doesn’t support loading a specific URI
|
||
if the protocol does not match what it expects.</p>
|
||
</div></details><h2 id="macros" class="section-header">Macros<a href="#macros" class="anchor">§</a></h2><ul class="item-table"><li><div class="item-name"><a class="macro" href="macro.generate_loader_id.html" title="macro egui::load::generate_loader_id">generate_<wbr>loader_<wbr>id</a></div><div class="desc docblock-short">Used to get a unique ID when implementing one of the loader traits: <a href="trait.BytesLoader.html#tymethod.id" title="method egui::load::BytesLoader::id"><code>BytesLoader::id</code></a>, <a href="trait.ImageLoader.html#tymethod.id" title="method egui::load::ImageLoader::id"><code>ImageLoader::id</code></a>, and <a href="trait.TextureLoader.html#tymethod.id" title="method egui::load::TextureLoader::id"><code>TextureLoader::id</code></a>.</div></li></ul><h2 id="structs" class="section-header">Structs<a href="#structs" class="anchor">§</a></h2><ul class="item-table"><li><div class="item-name"><a class="struct" href="struct.DefaultBytesLoader.html" title="struct egui::load::DefaultBytesLoader">Default<wbr>Bytes<wbr>Loader</a></div><div class="desc docblock-short">Maps URI:s to <a href="enum.Bytes.html" title="enum egui::load::Bytes"><code>Bytes</code></a>, e.g. found with <code>include_bytes!</code>.</div></li><li><div class="item-name"><a class="struct" href="struct.DefaultTextureLoader.html" title="struct egui::load::DefaultTextureLoader">Default<wbr>Texture<wbr>Loader</a></div></li><li><div class="item-name"><a class="struct" href="struct.Loaders.html" title="struct egui::load::Loaders">Loaders</a></div><div class="desc docblock-short">The loaders of bytes, images, and textures.</div></li><li><div class="item-name"><a class="struct" href="struct.SizedTexture.html" title="struct egui::load::SizedTexture">Sized<wbr>Texture</a></div><div class="desc docblock-short">A texture with a known size.</div></li></ul><h2 id="enums" class="section-header">Enums<a href="#enums" class="anchor">§</a></h2><ul class="item-table"><li><div class="item-name"><a class="enum" href="enum.Bytes.html" title="enum egui::load::Bytes">Bytes</a></div><div class="desc docblock-short">Represents a byte buffer.</div></li><li><div class="item-name"><a class="enum" href="enum.BytesPoll.html" title="enum egui::load::BytesPoll">Bytes<wbr>Poll</a></div><div class="desc docblock-short">Represents bytes which are currently being loaded.</div></li><li><div class="item-name"><a class="enum" href="enum.ImagePoll.html" title="enum egui::load::ImagePoll">Image<wbr>Poll</a></div><div class="desc docblock-short">Represents an image which is currently being loaded.</div></li><li><div class="item-name"><a class="enum" href="enum.LoadError.html" title="enum egui::load::LoadError">Load<wbr>Error</a></div><div class="desc docblock-short">Represents a failed attempt at loading an image.</div></li><li><div class="item-name"><a class="enum" href="enum.SizeHint.html" title="enum egui::load::SizeHint">Size<wbr>Hint</a></div><div class="desc docblock-short">Given as a hint for image loading requests.</div></li><li><div class="item-name"><a class="enum" href="enum.TexturePoll.html" title="enum egui::load::TexturePoll">Texture<wbr>Poll</a></div><div class="desc docblock-short">Represents a texture is currently being loaded.</div></li></ul><h2 id="traits" class="section-header">Traits<a href="#traits" class="anchor">§</a></h2><ul class="item-table"><li><div class="item-name"><a class="trait" href="trait.BytesLoader.html" title="trait egui::load::BytesLoader">Bytes<wbr>Loader</a></div><div class="desc docblock-short">Represents a loader capable of loading raw unstructured bytes from somewhere,
|
||
e.g. from disk or network.</div></li><li><div class="item-name"><a class="trait" href="trait.ImageLoader.html" title="trait egui::load::ImageLoader">Image<wbr>Loader</a></div><div class="desc docblock-short">An <code>ImageLoader</code> decodes raw bytes into a <a href="../struct.ColorImage.html" title="struct egui::ColorImage"><code>ColorImage</code></a>.</div></li><li><div class="item-name"><a class="trait" href="trait.TextureLoader.html" title="trait egui::load::TextureLoader">Texture<wbr>Loader</a></div><div class="desc docblock-short">A <code>TextureLoader</code> uploads a <a href="../struct.ColorImage.html" title="struct egui::ColorImage"><code>ColorImage</code></a> to the GPU, returning a <a href="struct.SizedTexture.html" title="struct egui::load::SizedTexture"><code>SizedTexture</code></a>.</div></li></ul><h2 id="types" class="section-header">Type Aliases<a href="#types" class="anchor">§</a></h2><ul class="item-table"><li><div class="item-name"><a class="type" href="type.BytesLoadResult.html" title="type egui::load::BytesLoadResult">Bytes<wbr>Load<wbr>Result</a></div></li><li><div class="item-name"><a class="type" href="type.ImageLoadResult.html" title="type egui::load::ImageLoadResult">Image<wbr>Load<wbr>Result</a></div></li><li><div class="item-name"><a class="type" href="type.Result.html" title="type egui::load::Result">Result</a></div></li><li><div class="item-name"><a class="type" href="type.TextureLoadResult.html" title="type egui::load::TextureLoadResult">Texture<wbr>Load<wbr>Result</a></div></li></ul></section></div></main></body></html> |