-
-
Notifications
You must be signed in to change notification settings - Fork 124
/
month_name_d.rs
89 lines (67 loc) · 2.49 KB
/
month_name_d.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
/*!
An application that list the month name of the selected locale. If you need inspiration see
https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes
Requires the following features: `cargo run --example month_name_d --features "winnls textbox"`
*/
extern crate native_windows_gui as nwg;
extern crate native_windows_derive as nwd;
use nwd::NwgUi;
use nwg::NativeUi;
#[derive(Default, NwgUi)]
pub struct CalendarNames {
#[nwg_control(size: (300, 230), position: (600, 300), title: "Localization example")]
#[nwg_events( OnWindowClose: [CalendarNames::exit], OnInit: [CalendarNames::init] )]
window: nwg::Window,
#[nwg_layout(parent: window)]
layout: nwg::GridLayout,
#[nwg_control(text: "Locale:", h_align: HTextAlign::Right)]
#[nwg_layout_item(layout: layout, col: 0, row: 0)]
locale_label: nwg::Label,
#[nwg_control(focus: true)]
#[nwg_layout_item(layout: layout, col: 1, row: 0, col_span: 2)]
locale_input: nwg::TextInput,
#[nwg_control(text: "Load")]
#[nwg_layout_item(layout: layout, col: 3, row: 0)]
#[nwg_events( OnButtonClick: [CalendarNames::load] )]
local_load: nwg::Button,
#[nwg_control]
#[nwg_layout_item(layout: layout, col: 0, row: 1, col_span: 4, row_span: 4)]
months: nwg::TextBox,
}
impl CalendarNames {
fn init(&self) {
let locale = nwg::Locale::user();
self.locale_input.set_text(locale.name());
self.load_months(&locale);
}
fn load(&self) {
match nwg::Locale::new(self.locale_input.text()) {
Ok(loc) => {
self.load_months(&loc);
},
Err(_) => {
nwg::error_message("Error", "Failed to load locale");
}
}
}
fn load_months(&self, locale: &nwg::Locale) {
let mut months_string = String::new();
months_string.push_str(&locale.display_name());
months_string.push_str("\r\n\r\n");
for i in 1..=12 {
let month_name = locale.month_name(i);
months_string.push_str(&month_name);
months_string.push_str("\r\n");
}
self.months.set_text(&months_string);
}
fn exit(&self) {
nwg::stop_thread_dispatch();
}
}
fn main() {
nwg::init().expect("Failed to init Native Windows GUI");
nwg::Font::set_global_family("Segoe UI").expect("Failed to set default font");
let _app = CalendarNames::build_ui(Default::default()).expect("Failed to build UI");
nwg::dispatch_thread_events();
}