|
1 | 1 | use winio::{ |
2 | 2 | App, BrushPen, Button, ButtonEvent, Canvas, CanvasEvent, CheckBox, CheckBoxEvent, Child, Color, |
3 | 3 | ColorTheme, ComboBox, ComboBoxEvent, ComboBoxMessage, Component, ComponentSender, |
4 | | - DrawingFontBuilder, Edit, GradientStop, Grid, HAlign, Label, Layoutable, LinearGradientBrush, |
5 | | - Margin, MessageBox, MessageBoxButton, ObservableVec, ObservableVecEvent, Orient, Point, |
6 | | - Progress, RadialGradientBrush, RadioButton, RadioButtonGroup, Rect, RelativePoint, |
7 | | - RelativeSize, Size, SolidColorBrush, StackPanel, TextBox, VAlign, Visible, Window, WindowEvent, |
| 4 | + DrawingFontBuilder, Edit, Enable, GradientStop, Grid, HAlign, Label, Layoutable, |
| 5 | + LinearGradientBrush, Margin, MessageBox, MessageBoxButton, ObservableVec, ObservableVecEvent, |
| 6 | + Orient, Point, Progress, RadialGradientBrush, RadioButton, RadioButtonGroup, Rect, |
| 7 | + RelativePoint, RelativeSize, Size, SolidColorBrush, StackPanel, TextBox, VAlign, Visible, |
| 8 | + Window, WindowEvent, |
8 | 9 | }; |
9 | 10 |
|
10 | 11 | fn main() { |
@@ -219,6 +220,7 @@ impl Component for MainModel { |
219 | 220 | true |
220 | 221 | } |
221 | 222 | MainMessage::List(e) => { |
| 223 | + self.pop_button.set_enabled(!self.list.is_empty()); |
222 | 224 | self.combo |
223 | 225 | .emit(ComboBoxMessage::from_observable_vec_event(e)) |
224 | 226 | .await |
@@ -250,11 +252,12 @@ impl Component for MainModel { |
250 | 252 | MainMessage::Show => { |
251 | 253 | MessageBox::new() |
252 | 254 | .title("Show selected item") |
253 | | - .message(if let Some(index) = self.index { |
254 | | - self.list[index].as_str() |
255 | | - } else { |
256 | | - "No selection." |
257 | | - }) |
| 255 | + .message( |
| 256 | + self.index |
| 257 | + .and_then(|index| self.list.get(index)) |
| 258 | + .map(|s| s.as_str()) |
| 259 | + .unwrap_or("No selection."), |
| 260 | + ) |
258 | 261 | .buttons(MessageBoxButton::Ok) |
259 | 262 | .show(Some(&*self.window)) |
260 | 263 | .await; |
|
0 commit comments