fltk_float/
misc.rs

1use std::ops::{Deref, DerefMut};
2
3use fltk::misc::InputChoice;
4use fltk::prelude::*;
5
6use super::{LayoutElement, LayoutWidgetWrapper, Size};
7
8pub struct InputChoiceElement {
9    widget: InputChoice,
10}
11
12impl LayoutWidgetWrapper<InputChoice> for InputChoiceElement {
13    fn wrap(widget: InputChoice) -> Self {
14        Self { widget }
15    }
16}
17
18impl LayoutElement for InputChoiceElement {
19    fn min_size(&self) -> Size {
20        fltk::draw::set_font(self.widget.text_font(), self.widget.text_size());
21        let text_height = fltk::draw::height();
22        let text_width = self
23            .widget
24            .menu_button()
25            .into_iter()
26            .filter_map(|item| item.label())
27            .map(|label| fltk::draw::measure(&label, true).0)
28            .max()
29            .unwrap_or_default();
30
31        let frame = self.widget.frame();
32        let frame_dx = frame.dx();
33        let frame_dy = frame.dy();
34        let frame_dw = frame.dw();
35        let frame_dh = frame.dh();
36        let frame_width = frame_dx + frame_dw;
37        let frame_height = frame_dy + frame_dh;
38
39        Size {
40            width: 3 * frame_width + text_width + text_height,
41            height: text_height + frame_height + 1,
42        }
43    }
44
45    fn layout(&self, x: i32, y: i32, width: i32, height: i32) {
46        self.widget.clone().resize(x, y, width, height);
47    }
48}
49
50impl Deref for InputChoiceElement {
51    type Target = InputChoice;
52    fn deref(&self) -> &Self::Target {
53        &self.widget
54    }
55}
56
57impl DerefMut for InputChoiceElement {
58    fn deref_mut(&mut self) -> &mut Self::Target {
59        &mut self.widget
60    }
61}