fltk_builder/extensions/builder/
input.rs

1use fltk::{
2    enums::{Color, Font},
3    prelude::InputExt,
4};
5
6/// Adds builder pattern friendly versions of several setter functions for Input widgets
7pub trait InputBuilderExt {
8    /// Sets the value inside an input/output widget
9    fn with_value(self, val: &str) -> Self;
10    /// Sets the maximum size (in bytes) accepted by an input/output widget
11    fn with_maximum_size(self, val: i32) -> Self;
12    /// Sets the text font
13    fn with_text_font(self, font: Font) -> Self;
14    /// Sets the text color
15    fn with_text_color(self, color: Color) -> Self;
16    /// Sets the text size
17    fn with_text_size(self, sz: i32) -> Self;
18    /// Set readonly status of the input/output widget
19    fn as_readonly(self, val: bool) -> Self;
20    /// Set whether text is wrapped inside an input/output widget
21    fn as_wrap(self, val: bool) -> Self;
22}
23
24impl<I> InputBuilderExt for I
25where
26    I: InputExt,
27{
28    fn with_value(mut self, val: &str) -> Self {
29        self.set_value(val);
30        self
31    }
32
33    fn with_maximum_size(mut self, val: i32) -> Self {
34        self.set_maximum_size(val);
35        self
36    }
37
38    fn with_text_font(mut self, font: Font) -> Self {
39        self.set_text_font(font);
40        self
41    }
42
43    fn with_text_color(mut self, color: Color) -> Self {
44        self.set_text_color(color);
45        self
46    }
47
48    fn with_text_size(mut self, sz: i32) -> Self {
49        self.set_text_size(sz);
50        self
51    }
52
53    fn as_readonly(mut self, val: bool) -> Self {
54        self.set_readonly(val);
55        self
56    }
57
58    fn as_wrap(mut self, val: bool) -> Self {
59        self.set_wrap(val);
60        self
61    }
62}