当前位置:   article > 正文

【rust】iced 窗体参数_rust iced 最小化 窗口

rust iced 最小化 窗口

iced是rust语言开发的一个跨平台GUI库(Windows、macOS、Linux、Web),介绍请参见:https://docs.rs/iced/0.3.0/iced/index.html
在Ubuntu下使用的话,需要先安装freetype库:

sudo apt install libfreetype-dev
  • 1

本文通过代码实验,了解窗口参数(iced::window::Settings)的意义。


Cargo.toml:

[package]
name = "Hello_iced"
version = "0.1.0"
authors = ["wuu19 <wuu19@163.com>"]
edition = "2018"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
iced = {version = "0.3.0"}
font-kit = {version = "0.10.0", optional = true}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11

main.rs:

use iced::{executor, Application, Clipboard, Command, Element, Settings, Text};

pub fn main() -> iced::Result {
    Hello::run(Settings{
        // 设置窗口属性
        window:iced::window::Settings{
            size: (1600, 900), 
            resizable: false, 
            decorations: true, 
            transparent: false, 
            always_on_top: false, 
            ..iced::window::Settings::default()
        },
        // 指定字体文件位置
        default_font: Some(include_bytes!("/home/user/work/rust/font/DroidSansFallback.ttf")), 
        ..Settings::default()
    })
}

struct Hello;

impl Application for Hello {
    type Executor = executor::Default;
    type Message = ();
    type Flags = ();

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

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

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

    fn view(&mut self) -> Element<Self::Message> {
        Text::new("Hello, world!").into()
    }
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42

iced::window::Settings,属性说明如下:

  • size: (u32, u32):The initial size of the window。设置初始化窗口的大小。
  • min_size: Option<(u32, u32)>:The minimum size of the window。设置窗口最小化的大小。
  • max_size: Option<(u32, u32)>:The maximum size of the window。设置窗口最大化的大小。
  • resizable: bool:Whether the window should be resizable or not。设置窗口是否可以放大。
  • decorations: bool:Whether the window should have a border, a title bar, etc. or not。设置窗口是否有标题栏。
  • transparent: bool:Whether the window should be transparent。设置窗口是否透明(测试中,该属性好像无效)。
  • always_on_top: bool:Whether the window will always be on top of other windows。设置窗口是否一直在最上层。
  • icon: Option:The icon of the window。设置窗口图标。
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小舞很执着/article/detail/753348
推荐阅读
相关标签
  

闽ICP备14008679号