fltk_builder/extensions/builder/
display.rs

1use fltk::{
2    enums::{Align, Color, Font},
3    prelude::DisplayExt,
4    text::{Cursor, StyleTableEntry, StyleTableEntryExt, TextBuffer, WrapMode},
5};
6
7/// Adds builder pattern friendly versions of several setter functions
8pub trait DisplayBuilderExt {
9    /// Sets the associated `TextBuffer`
10    fn with_buffer<B: Into<Option<TextBuffer>>>(self, buffer: B) -> Self;
11    /// Sets the text font
12    fn with_text_font(self, font: Font) -> Self;
13    /// Sets the text color
14    fn with_text_color(self, color: Color) -> Self;
15    /// Sets the text size
16    fn with_text_size(self, sz: i32) -> Self;
17    /// Sets the style of the text widget
18    fn with_highlight_data<B: Into<Option<TextBuffer>>>(
19        self,
20        style_buffer: B,
21        entries: Vec<StyleTableEntry>,
22    ) -> Self;
23    /// Sets the style of the text widget
24    fn with_highlight_data_ext<B: Into<Option<TextBuffer>>>(
25        self,
26        style_buffer: B,
27        entries: Vec<StyleTableEntryExt>,
28    ) -> Self;
29    /// Sets the cursor style
30    fn with_cursor_style(self, style: Cursor) -> Self;
31    /// Sets the cursor color
32    fn with_cursor_color(self, color: Color) -> Self;
33    /// Sets the scrollbar size in pixels
34    fn with_scrollbar_size(self, size: i32) -> Self;
35    /// Sets the scrollbar alignment
36    fn with_scrollbar_align(self, align: Align) -> Self;
37    /// Sets the linenumber width
38    fn with_linenumber_width(self, w: i32) -> Self;
39    /// Sets the linenumber font
40    fn with_linenumber_font(self, font: Font) -> Self;
41    /// Sets the linenumber size
42    fn with_linenumber_size(self, size: i32) -> Self;
43    /// Sets the linenumber foreground color
44    fn with_linenumber_fgcolor(self, color: Color) -> Self;
45    /// Sets the linenumber background color
46    fn with_linenumber_bgcolor(self, color: Color) -> Self;
47    /// Sets the linenumber alignment
48    fn with_linenumber_align(self, align: Align) -> Self;
49    /// Sets the wrap mode of the Display widget.
50    /// If the wrap mode is `AtColumn`, wrap margin is the column.
51    /// If the wrap mode is `AtPixel`, wrap margin is the pixel.
52    /// For more [info](https://www.fltk.org/doc-1.4/classFl__Text__Display.html#ab9378d48b949f8fc7da04c6be4142c54)
53    fn with_wrap_mode(self, wrap: WrapMode, wrap_margin: i32) -> Self;
54    /// Set the grammar underline color
55    fn with_grammar_underline_color(self, color: Color) -> Self;
56    /// Set the spelling underline color
57    fn with_spelling_underline_color(self, color: Color) -> Self;
58    /// Set the secondary selection color
59    fn with_secondary_selection_color(self, color: Color) -> Self;
60}
61
62impl<D> DisplayBuilderExt for D
63where
64    D: DisplayExt,
65{
66    fn with_buffer<B: Into<Option<TextBuffer>>>(mut self, buffer: B) -> Self {
67        self.set_buffer(buffer);
68        self
69    }
70
71    fn with_text_font(mut self, font: Font) -> Self {
72        self.set_text_font(font);
73        self
74    }
75
76    fn with_text_color(mut self, color: Color) -> Self {
77        self.set_text_color(color);
78        self
79    }
80
81    fn with_text_size(mut self, sz: i32) -> Self {
82        self.set_text_size(sz);
83        self
84    }
85
86    fn with_highlight_data<B: Into<Option<TextBuffer>>>(
87        mut self,
88        style_buffer: B,
89        entries: Vec<StyleTableEntry>,
90    ) -> Self {
91        self.set_highlight_data(style_buffer, entries);
92        self
93    }
94
95    fn with_highlight_data_ext<B: Into<Option<TextBuffer>>>(
96        mut self,
97        style_buffer: B,
98        entries: Vec<StyleTableEntryExt>,
99    ) -> Self {
100        self.set_highlight_data_ext(style_buffer, entries);
101        self
102    }
103
104    fn with_cursor_style(mut self, style: Cursor) -> Self {
105        self.set_cursor_style(style);
106        self
107    }
108
109    fn with_cursor_color(mut self, color: Color) -> Self {
110        self.set_cursor_color(color);
111        self
112    }
113
114    fn with_scrollbar_size(mut self, size: i32) -> Self {
115        self.set_scrollbar_size(size);
116        self
117    }
118
119    fn with_scrollbar_align(mut self, align: Align) -> Self {
120        self.set_scrollbar_align(align);
121        self
122    }
123
124    fn with_linenumber_width(mut self, w: i32) -> Self {
125        self.set_linenumber_width(w);
126        self
127    }
128
129    fn with_linenumber_font(mut self, font: Font) -> Self {
130        self.set_linenumber_font(font);
131        self
132    }
133
134    fn with_linenumber_size(mut self, size: i32) -> Self {
135        self.set_linenumber_size(size);
136        self
137    }
138
139    fn with_linenumber_fgcolor(mut self, color: Color) -> Self {
140        self.set_linenumber_fgcolor(color);
141        self
142    }
143
144    fn with_linenumber_bgcolor(mut self, color: Color) -> Self {
145        self.set_linenumber_bgcolor(color);
146        self
147    }
148
149    fn with_linenumber_align(mut self, align: Align) -> Self {
150        self.set_linenumber_align(align);
151        self
152    }
153
154    fn with_wrap_mode(mut self, wrap: WrapMode, wrap_margin: i32) -> Self {
155        self.wrap_mode(wrap, wrap_margin);
156        self
157    }
158
159    fn with_grammar_underline_color(mut self, color: Color) -> Self {
160        self.set_grammar_underline_color(color);
161        self
162    }
163
164    fn with_spelling_underline_color(mut self, color: Color) -> Self {
165        self.set_spelling_underline_color(color);
166        self
167    }
168
169    fn with_secondary_selection_color(mut self, color: Color) -> Self {
170        self.set_secondary_selection_color(color);
171        self
172    }
173}