【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

本文通过代码实验,了解窗口参数(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}

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()
    }
}

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。设置窗口图标。
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值