user-interface - 用冰 rust 画img

标签 user-interface graphics rust

我开始在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/

相关文章:

c# - 如何防止在图形对象上发生的 ExternalException

c++ - WM 6.x 中的 GDI 路径

rust - 我得到的特征绑定(bind) `T: sns_pub::_IMPL_DESERIALIZE_FOR_Message::_serde::Serialize` 不满意

ios - UIPIckerView:如何定义所选项目再次被选中?

multithreading - 从后台线程 SWIFT 更新 UI

c++ - 如何正确清理 QWidget/管理一组窗口?

rust - 如何在 Rust 中将字符串转换为二进制字符串?

java - JTree 中的 JTextField - 使其可编辑

android - 绘制圆形扇形

rust - 是否可以在 stdin.lines() 中间执行另一次读取?