Skip to content

bluebell9/druid-icon

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

druid-icon

在Windows上,如果可执行文件包含一个id为1的图标资源,这个图标将被用在Druid窗口的任务栏和标题栏中。如果没有这样的图标资源,则将使用默认的应用程序图标。 添加自定义图标:一种方法是使用winres crate并遵循其自述文件中的指南;winres::WindowsResource::set_icon() 添加ID为1的图标。 创建druid项目设置窗体图标

cargo new druid-icon

添加druid包

[dependencies]
druid = "0.8.2"

添加设置图标使用的库

[package]
build = "build.rs"

[build-dependencies]
winres = "0.1.12"

添加build.rs启动文件 (项目根目录下)

extern crate winres;

fn main() {
    if cfg!(target_os = "windows") {
        let mut res = winres::WindowsResource::new();
        //设置图标,图标和build.rs文件都放在项目根目录下
        res.set_icon("logo.ico");
        res.compile().unwrap();
    }
}

编写main.rs主方法

use druid::widget::{Flex, Label};
use druid::{AppLauncher, PlatformError, Widget, WindowDesc, Data, Lens};

#[derive(Data,Lens,Clone)]
struct AppData{

}

fn main() -> Result<(), PlatformError> {
    //创建窗体,并且设置为300x250
    let main_window = WindowDesc::new(ui_builder()).window_size((300.,250.));
    //启动
    AppLauncher::with_window(main_window)
        //打印日志log
        .log_to_console()
        .launch(AppData{})
}

fn ui_builder() -> impl Widget<AppData> {
    
    //创建显示的内容
    Flex::<AppData>::column()
        .with_child(Label::new("设置图标"))
}

运行效果

image.png

项目目录

image.png

github地址:https://github.com/dream45678/druid-icon.git

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages