gpt4 book ai didi

user-interface - 用冰 rust 画img

转载 作者:行者123 更新时间:2023-12-03 11:41:14 25 4
gpt4 key购买 nike

我开始在Rust中进行开发,我想为打印图片开发图形界面。
我的问题是使用此库绘制img。 Doc用过的https://docs.rs/iced/0.1.1/iced/widget/image/struct.Image.html
因此,您可以在下面观看我的代码:

use iced::*;

pub struct GeoRust;

impl Application for GeoRust {
type Executor = executor::Null;
type Message = ();
type Flags = ();

fn new(_flags: ()) -> (GeoRust, Command<Self::Message>) {
(GeoRust, Command::none())
}

fn title(&self) -> String {
String::from("GeoRust")
}

fn update(&mut self, _message: Self::Message) -> Command<Self::Message> {
let img = widget::image::Image::new("./data/dataGetLegendGraphic.png");
img.draw(renderer: &mut Renderer, _defaults: &Renderer::Defaults, layout: Layout<'_>, _cursor_position: Point);
Command::none()
}

fn view(&mut self) -> Element<Self::Message> {
Text::new("GeoRust, world!").into()
}
}
而且我不知道将什么作为参数。我什么都看不到,或者我可以在lib中找到。
而且,如果您有时间,我不知道如何将变量放入GeoRust结构中。

最佳答案

确保启用documentation for image 中列出的0.1.1功能。
cargo.toml

[dependencies]
iced = { version = "0.1", features = ["image"] }
给定以下工作目录:
.  iced_stackoverflow
├─ Cargo.lock
├─ Cargo.toml
├─ resources/
│ └─ ferris.png
├─ src/
│ └─ main.rs
└─ target/
我们可以使用以下代码创建完整尺寸的图像:
src/main.rs
use iced::{executor, Application, Command, Container, Element, Image, Length, Settings};

fn main() {
Example::run(Settings::default());
}

struct Example;

impl Application for Example {
type Executor = executor::Null;
type Message = ();
type Flags = ();

fn new(_flags: ()) -> (Example, Command<Self::Message>) {
(Example, Command::none())
}

fn title(&self) -> String {
String::from("Example application")
}

fn update(&mut self, _message: Self::Message) -> Command<Self::Message> {
Command::none()
}

fn view(&mut self) -> Element<Self::Message> {
let image = Image::new("resources/ferris.png")
.width(Length::Fill)
.height(Length::Fill);

Container::new(image)
.width(Length::Fill)
.height(Length::Fill)
.center_x()
.center_y()
.into()
}
}
这将为我们提供以下应用程序:
Screenshot of the Iced application with an image of Ferris
可以从 Iced存储库中学习很多 examples

关于user-interface - 用冰 rust 画img,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62712245/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com