【Rust 日报】2020-04-29 windows GUI 工具包

1 - windows GUI 工具包

native-windows-gui :Rust 轻量级的 windows GUI 工具包。

代码使用样例:

/**    Simple example on how to use the nwg template system.*/
//To hide console window#![windows_subsystem = "windows"]
#[macro_use] extern crate native_windows_gui as nwg;
use nwg::{Event, Ui, simple_message, fatal_message, dispatch_events};
/// Custom enums are the preferred way to define ui ids. It's clearer and more extensible than any other types (such as &'str).#[derive(Debug, Clone, Hash)]pub enum AppId {    // Controls    MainWindow,    NameInput,    HelloButton,    Label(u8),   // Ids for static controls that won't be referenced in the Ui logic can be shortened this way.
    // Events    SayHello,
    // Resources    MainFont,    TextFont}
use AppId::*; // Shortcut
nwg_template!(    head: setup_ui<AppId>,    controls: [        (MainWindow, nwg_window!( title="Template Example"; size=(280, 105) )),        (Label(0), nwg_label!( parent=MainWindow; text="Your Name: "; position=(5,15); size=(80, 25); font=Some(TextFont) )),        (NameInput, nwg_textinput!( parent=MainWindow; position=(85,13); size=(185,22); font=Some(TextFont) )),        (HelloButton, nwg_button!( parent=MainWindow; text="Hello World!"; position=(5, 45); size=(270, 50); font=Some(MainFont) ))    ];    events: [        (HelloButton, SayHello, Event::Click, |ui,_,_,_| {            let your_name = nwg_get!(ui; (NameInput, nwg::TextInput));            simple_message("Hello", &format!("Hello {}!", your_name.get_text()) );        })    ];    resources: [        (MainFont, nwg_font!(family="Arial"; size=27)),        (TextFont, nwg_font!(family="Arial"; size=17))    ];    values: []);
fn main() {    let app: Ui<AppId>;
    match Ui::new() {        Ok(_app) => { app = _app; },        Err(e) => { fatal_message("Fatal Error", &format!("{:?}", e) ); }    }
    if let Err(e) = setup_ui(&app) {        fatal_message("Fatal Error", &format!("{:?}", e));    }
    dispatch_events();}

https://github.com/gabdube/native-windows-gui

2 -【博客】减小 Rust GStreamer 插件的体积

受困于 Rust 项目编译后二进制包过大,尤其是对于嵌入式开发就更是一个问题了。作者受到 Tiny Rocket以及Minimizing Rust Binary Size的启发,在这篇博客中介绍了他是如何给GStreamer 压缩体积的。

https://www.collabora.com/news-and-blog/blog/2020/04/28/reducing-size-rust-gstreamer-plugin/

3 - 2048-rs

对2048游戏的轻量级 Rust 实现

https://github.com/adrienball/2048-rs

4 - sonor : 可以控制 sonos 的 crate

sonos 是一个家庭无线音响系统的品牌,这个库可以通过代码来控制 sonos。

样例:

let speaker = sonor::find("your room name", Duration::from_secs(2)).await?    .expect("room exists");
println!("The volume is currently at {}", speaker.volume().await?);
match speaker.track().await? {    Some(track_info) => println!("- Currently playing '{}", track_info.track()),    None => println!("- No track currently playing"),}
speaker.clear_queue().await?;
speaker.join("some other room").await?;

https://docs.rs/sonor/0.1.2/sonor/


From 日报小组 挺肥

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值