pub fn error_message<'a>(title: &'a str, content: &'a str) -> MessageChoiceExpand description
Display a simple error message box. The message box has for style MessageButtons::Ok and MessageIcons::Error.
It is recommended to use modal_error_message because it locks the window that creates the message box.
This method may be deprecated in the future
Parameters:
- title: The message box title
- content: The message box message
Examples found in repository?
examples/calculator.rs (line 75)
57 fn compute(&self) {
58 use Token::*;
59 static SYMBOLS: &'static [char] = &['+', '-', '*', '/'];
60
61 let eq = self.input.text();
62 if eq.len() == 0 {
63 return;
64 }
65
66 let mut tokens: Vec<Token> = Vec::with_capacity(5);
67 let mut last = 0;
68
69 for (i, chr) in eq.char_indices() {
70 if SYMBOLS.iter().any(|&s| s == chr) {
71 let left = &eq[last..i];
72 match left.parse::<i32>() {
73 Ok(i) => tokens.push(Token::Number(i)),
74 _ => {
75 nwg::error_message("Error", "Invalid equation!");
76 self.input.set_text("");
77 return
78 }
79 }
80
81 let tk = match chr {
82 '+' => Plus,
83 '-' => Minus,
84 '*' => Mult,
85 '/' => Div,
86 _ => unreachable!()
87 };
88
89 tokens.push(tk);
90
91 last = i+1;
92 }
93 }
94
95 let right = &eq[last..];
96 match right.parse::<i32>() {
97 Ok(i) => tokens.push(Token::Number(i)),
98 _ => {
99 nwg::error_message("Error", "Invalid equation!");
100 self.input.set_text("");
101 return
102 }
103 }
104
105 let mut i = 1;
106 let mut result = match &tokens[0] { Token::Number(n) => *n, _ => unreachable!() };
107 while i < tokens.len() {
108 match [&tokens[i], &tokens[i+1]] {
109 [Plus, Number(n)] => { result += n; },
110 [Minus, Number(n)] => { result -= n;},
111 [Mult, Number(n)] => { result *= n; },
112 [Div, Number(n)] => { result /= n; },
113 _ => unreachable!()
114 }
115 i += 2;
116 }
117
118 self.input.set_text(&result.to_string());
119 }