Comments (2)
You can try release mode:
cargo run --release
If the performance is still not good, you can try loading the image asynchronously:
use iced::{
widget::{button, column, container, image, image::Handle},
Application, Command,
};
use tokio::{fs::File, io::AsyncReadExt};
const PATH_TO_YOUR_IMAGE: &str = "/path/to/your/image";
fn main() -> iced::Result {
App::run(iced::Settings::default())
}
#[derive(Debug, Clone)]
enum Message {
Load,
Loaded(Vec<u8>),
}
struct App {
image_handle: Option<Handle>,
show_container: bool,
}
impl Application for App {
type Executor = iced::executor::Default;
type Message = Message;
type Theme = iced::Theme;
type Flags = ();
fn new(_flags: Self::Flags) -> (Self, iced::Command<Self::Message>) {
(
Self {
image_handle: None,
show_container: false,
},
Command::none(),
)
}
fn title(&self) -> String {
"Lazily load image".into()
}
fn update(&mut self, message: Self::Message) -> iced::Command<Self::Message> {
match message {
Message::Load => {
self.show_container = true;
return Command::perform(
async {
let mut file = File::open(PATH_TO_YOUR_IMAGE).await.unwrap();
let mut buffer = Vec::new();
file.read_to_end(&mut buffer).await.unwrap();
buffer
},
Message::Loaded,
)
}
Message::Loaded(data) => self.image_handle = Some(Handle::from_memory(data)),
}
Command::none()
}
fn view(&self) -> iced::Element<'_, Self::Message, iced::Renderer<Self::Theme>> {
column![
button("Load").on_press(Message::Load),
if self.show_container {
match &self.image_handle {
Some(h) => container(image(h.clone())),
None => container("Loading..."),
}
} else {
container("")
},
]
.into()
}
}
with the dependencies:
[dependencies]
iced = { version = "0.10.0", features = ["image", "advanced", "tokio"] }
tokio = { version = "1.35.1", features = ["full"] }
See if this method solves your problem.
from iced.
Hmm i think this is way too complex to what i was trying to accomplish, but with release mode it feels fast enough, its like 100-200ms to load 3 more images, which is fine. Thanks for suggestion
from iced.
Related Issues (20)
- feature request - mac system menu support HOT 2
- Error: `palette` overflow evaluating the requirement `&_: std::iter::IntoIterator` HOT 1
- `palette` is ambiguous ambiguous because of multiple potential import sources HOT 1
- New release required to work with iced_aw 0.8.0? HOT 4
- GUI freezes upon interacting with a widget under Wayland HOT 8
- Themer widget doens't apply its theme to Text widgets HOT 2
- Compilation fails on x86_64-pc-windows-msvc. HOT 1
- column macro possibly in conflict with core column macro HOT 5
- svg scaling artifacts
- iced-winit depends on a yanked version of winit HOT 2
- tiny_skia backend panics if you have an Combobox menu with zero search results
- Panic in minimal Application with default settings HOT 4
- TextInput paragraph state cache
- Problem with a custom widget that wraps a `TextInput` HOT 2
- Clock example hangs, when you hold down the left mouse button HOT 3
- Unicode characters not showing up on the Text Input step in the tour HOT 2
- text_editor panic when backspacing with long lines
- tiny-skia crashes on long texts within a `Row` that also contain other elements
- Toast example crahses if two or more toasts are removed at the same time HOT 1
- Crash on raspberry pi when using wgpu feature HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from iced.