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。设置窗口图标。