/**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 {// ControlsMainWindow,NameInput,HelloButton,Label(u8), // Ids for static controls that won't be referenced in the Ui logic can be shortened this way.// EventsSayHello,// ResourcesMainFont,TextFont}use AppId::*; // Shortcutnwg_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();}
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?;
原文作者:Rust语言中文社区;如有侵权,请联系管理员删除。