pub struct Spinner { /* private fields */ }
Expand description
Creates a spinner widget
Implementations§
Source§impl Spinner
impl Spinner
Sourcepub fn new<'a, T: Into<Option<&'a str>>>(
x: i32,
y: i32,
width: i32,
height: i32,
title: T,
) -> Spinner
pub fn new<'a, T: Into<Option<&'a str>>>( x: i32, y: i32, width: i32, height: i32, title: T, ) -> Spinner
Creates a new widget, takes an x, y coordinates, as well as a width and height, plus a title
§Arguments
x
- The x coordinate in the screeny
- The y coordinate in the screenwidth
- The width of the widgetheigth
- The height of the widgettitle
- The title or label of the widget
To use dynamic strings use with_label(self, &str)
or set_label(&mut self, &str)
.
labels support special symbols preceded by an @
sign
and for the associated formatting.
Sourcepub fn default_fill() -> Self
pub fn default_fill() -> Self
Constructs a widget with the size of its parent
Source§impl Spinner
impl Spinner
Sourcepub fn set_minimum(&mut self, a: f64)
pub fn set_minimum(&mut self, a: f64)
Sets the minimum value of the spinner widget
Sourcepub fn set_maximum(&mut self, a: f64)
pub fn set_maximum(&mut self, a: f64)
Sets the minimum value of the spinner widget
Sourcepub fn set_range(&mut self, a: f64, b: f64)
pub fn set_range(&mut self, a: f64, b: f64)
Sets the range of the spinner widget
Examples found in repository?
122fn main() {
123 let style = Rc::from(RefCell::from(Style::new()));
124
125 let app = App::default().with_scheme(Scheme::Gleam);
126 let mut wind = Window::default()
127 .with_size(500, 200)
128 .with_label("Highlight");
129 let mut vpack = Pack::new(4, 4, 492, 192, "");
130 vpack.set_spacing(4);
131 let mut text_editor = TextEditor::default().with_size(492, 163);
132
133 let mut hpack = Pack::new(4, 4, 492, 25, "").with_type(PackType::Horizontal);
134 hpack.set_spacing(8);
135 let mut font = Choice::default().with_size(130, 25);
136 let mut choice = Choice::default().with_size(130, 25);
137 let mut size = Spinner::default().with_size(60, 25);
138
139 let mut color = Choice::default().with_size(100, 25);
140 let mut btn_clear = Button::default().with_size(40, 25).with_label("X");
141 hpack.end();
142
143 vpack.end();
144 wind.end();
145 wind.show();
146
147 text_editor.wrap_mode(fltk::text::WrapMode::AtBounds, 0);
148 text_editor.set_buffer(TextBuffer::default());
149
150 font.add_choice("Courier|Helvetica|Times");
151 font.set_value(0);
152 font.set_tooltip("Font");
153
154 choice.add_choice("Normal|Underline|Strike");
155 choice.set_value(0);
156
157 size.set_value(18.0);
158 size.set_step(1.0);
159 size.set_range(12.0, 28.0);
160 size.set_tooltip("Size");
161
162 color.set_tooltip("Color");
163 color.add_choice("#000000|#ff0000|#00ff00|#0000ff|#ffff00|#00ffff");
164 color.set_value(0);
165
166 btn_clear.set_label_color(Color::Red);
167 btn_clear.set_tooltip("Clear style");
168
169 // set colors
170 for mut item in color.clone() {
171 if let Some(lbl) = item.label() {
172 item.set_label_color(Color::from_u32(
173 u32::from_str_radix(lbl.trim().strip_prefix('#').unwrap(), 16)
174 .ok()
175 .unwrap(),
176 ));
177 }
178 }
179
180 let style_rc1 = Rc::clone(&style);
181
182 text_editor.buffer().unwrap().add_modify_callback({
183 let mut text_editor1 = text_editor.clone();
184 let font1 = font.clone();
185 let size1 = size.clone();
186 let color1 = color.clone();
187 let choice1 = choice.clone();
188 move |_buf, pos: i32, ins_items: i32, del_items: i32, _: i32, _: Option<&str>| {
189 let attr = if choice1.value() == 1 {
190 TextAttr::Underline
191 } else if choice1.value() == 2 {
192 TextAttr::StrikeThrough
193 } else {
194 TextAttr::None
195 };
196 if ins_items > 0 || del_items > 0 {
197 let mut style = style_rc1.borrow_mut();
198 let color = Color::from_u32(
199 u32::from_str_radix(
200 color1
201 .text(color1.value())
202 .unwrap()
203 .trim()
204 .strip_prefix('#')
205 .unwrap(),
206 16,
207 )
208 .ok()
209 .unwrap(),
210 );
211 style.apply_style(
212 Some(pos),
213 Some(ins_items),
214 Some(del_items),
215 None,
216 None,
217 Font::by_name(font1.text(font1.value()).unwrap().trim()),
218 size1.value() as i32,
219 color,
220 attr,
221 &mut text_editor1,
222 );
223 }
224 }
225 });
226
227 color.set_callback({
228 let size = size.clone();
229 let font = font.clone();
230 let choice = choice.clone();
231 let mut text_editor = text_editor.clone();
232 let style_rc1 = Rc::clone(&style);
233 move |color| {
234 let attr = match choice.value() {
235 0 => TextAttr::None,
236 1 => TextAttr::Underline,
237 2 => TextAttr::StrikeThrough,
238 _ => unreachable!(),
239 };
240 if let Some(buf) = text_editor.buffer() {
241 if let Some((s, e)) = buf.selection_position() {
242 let mut style = style_rc1.borrow_mut();
243 let color = Color::from_u32(
244 u32::from_str_radix(
245 color
246 .text(color.value())
247 .unwrap()
248 .trim()
249 .strip_prefix('#')
250 .unwrap(),
251 16,
252 )
253 .ok()
254 .unwrap(),
255 );
256 style.apply_style(
257 None,
258 None,
259 None,
260 Some(s),
261 Some(e),
262 Font::by_name(font.text(font.value()).unwrap().trim()),
263 size.value() as i32,
264 color,
265 attr,
266 &mut text_editor,
267 );
268 }
269 }
270 }
271 });
272
273 // get the style from the current cursor position
274 text_editor.handle({
275 let style_rc1 = Rc::clone(&style);
276 let mut font1 = font.clone();
277 let mut size1 = size.clone();
278 let mut color1 = color.clone();
279 move |te, e| match e {
280 Event::KeyUp | Event::Released => {
281 if let Some(buff) = te.style_buffer() {
282 let i = te.insert_position();
283 if let Some(t) = buff.text_range(i, i + 1) {
284 if !t.is_empty() {
285 let style = style_rc1.borrow_mut();
286 if let Some(i) = t.chars().next().map(|c| (c as usize - 65)) {
287 if let Some(style) = style.style_table.get(i) {
288 if let Some(mn) = font1.find_item(&format!("{:?}", style.font))
289 {
290 font1.set_item(&mn);
291 }
292 size1.set_value(style.size as f64);
293 let (r, g, b) = style.color.to_rgb();
294 if let Some(mn) =
295 color1.find_item(format!("{r:02x}{g:02x}{b:02x}").as_str())
296 {
297 color1.set_item(&mn);
298 }
299 }
300 }
301 }
302 }
303 }
304 true
305 }
306 _ => false,
307 }
308 });
309
310 choice.set_callback({
311 let mut color1 = color.clone();
312 move |_| color1.do_callback()
313 });
314
315 font.set_callback({
316 let mut color1 = color.clone();
317 move |_| color1.do_callback()
318 });
319
320 size.set_callback({
321 let mut color1 = color.clone();
322 move |_| color1.do_callback()
323 });
324
325 // clear style of the current selection or, if no text is selected, clear all text style
326 btn_clear.set_callback({
327 let style_rc1 = Rc::clone(&style);
328 let text_editor1 = text_editor.clone();
329 move |_| {
330 match text_editor1.buffer().unwrap().selection_position() {
331 Some((_, _)) => {
332 font.set_value(0);
333 size.set_value(18.0);
334 color.set_value(0);
335 choice.set_value(0);
336 color.do_callback();
337 }
338 None => {
339 font.set_value(0);
340 size.set_value(18.0);
341 color.set_value(0);
342 style_rc1.borrow_mut().apply_style(
343 None,
344 None,
345 None,
346 Some(0),
347 Some(text_editor1.buffer().unwrap().length()),
348 Font::Courier,
349 16,
350 Color::Black,
351 TextAttr::None,
352 &mut text_editor,
353 );
354 }
355 };
356 }
357 });
358
359 app.run().unwrap();
360}
Sourcepub fn set_step(&mut self, a: f64)
pub fn set_step(&mut self, a: f64)
Sets the step of the spinner widget
Examples found in repository?
122fn main() {
123 let style = Rc::from(RefCell::from(Style::new()));
124
125 let app = App::default().with_scheme(Scheme::Gleam);
126 let mut wind = Window::default()
127 .with_size(500, 200)
128 .with_label("Highlight");
129 let mut vpack = Pack::new(4, 4, 492, 192, "");
130 vpack.set_spacing(4);
131 let mut text_editor = TextEditor::default().with_size(492, 163);
132
133 let mut hpack = Pack::new(4, 4, 492, 25, "").with_type(PackType::Horizontal);
134 hpack.set_spacing(8);
135 let mut font = Choice::default().with_size(130, 25);
136 let mut choice = Choice::default().with_size(130, 25);
137 let mut size = Spinner::default().with_size(60, 25);
138
139 let mut color = Choice::default().with_size(100, 25);
140 let mut btn_clear = Button::default().with_size(40, 25).with_label("X");
141 hpack.end();
142
143 vpack.end();
144 wind.end();
145 wind.show();
146
147 text_editor.wrap_mode(fltk::text::WrapMode::AtBounds, 0);
148 text_editor.set_buffer(TextBuffer::default());
149
150 font.add_choice("Courier|Helvetica|Times");
151 font.set_value(0);
152 font.set_tooltip("Font");
153
154 choice.add_choice("Normal|Underline|Strike");
155 choice.set_value(0);
156
157 size.set_value(18.0);
158 size.set_step(1.0);
159 size.set_range(12.0, 28.0);
160 size.set_tooltip("Size");
161
162 color.set_tooltip("Color");
163 color.add_choice("#000000|#ff0000|#00ff00|#0000ff|#ffff00|#00ffff");
164 color.set_value(0);
165
166 btn_clear.set_label_color(Color::Red);
167 btn_clear.set_tooltip("Clear style");
168
169 // set colors
170 for mut item in color.clone() {
171 if let Some(lbl) = item.label() {
172 item.set_label_color(Color::from_u32(
173 u32::from_str_radix(lbl.trim().strip_prefix('#').unwrap(), 16)
174 .ok()
175 .unwrap(),
176 ));
177 }
178 }
179
180 let style_rc1 = Rc::clone(&style);
181
182 text_editor.buffer().unwrap().add_modify_callback({
183 let mut text_editor1 = text_editor.clone();
184 let font1 = font.clone();
185 let size1 = size.clone();
186 let color1 = color.clone();
187 let choice1 = choice.clone();
188 move |_buf, pos: i32, ins_items: i32, del_items: i32, _: i32, _: Option<&str>| {
189 let attr = if choice1.value() == 1 {
190 TextAttr::Underline
191 } else if choice1.value() == 2 {
192 TextAttr::StrikeThrough
193 } else {
194 TextAttr::None
195 };
196 if ins_items > 0 || del_items > 0 {
197 let mut style = style_rc1.borrow_mut();
198 let color = Color::from_u32(
199 u32::from_str_radix(
200 color1
201 .text(color1.value())
202 .unwrap()
203 .trim()
204 .strip_prefix('#')
205 .unwrap(),
206 16,
207 )
208 .ok()
209 .unwrap(),
210 );
211 style.apply_style(
212 Some(pos),
213 Some(ins_items),
214 Some(del_items),
215 None,
216 None,
217 Font::by_name(font1.text(font1.value()).unwrap().trim()),
218 size1.value() as i32,
219 color,
220 attr,
221 &mut text_editor1,
222 );
223 }
224 }
225 });
226
227 color.set_callback({
228 let size = size.clone();
229 let font = font.clone();
230 let choice = choice.clone();
231 let mut text_editor = text_editor.clone();
232 let style_rc1 = Rc::clone(&style);
233 move |color| {
234 let attr = match choice.value() {
235 0 => TextAttr::None,
236 1 => TextAttr::Underline,
237 2 => TextAttr::StrikeThrough,
238 _ => unreachable!(),
239 };
240 if let Some(buf) = text_editor.buffer() {
241 if let Some((s, e)) = buf.selection_position() {
242 let mut style = style_rc1.borrow_mut();
243 let color = Color::from_u32(
244 u32::from_str_radix(
245 color
246 .text(color.value())
247 .unwrap()
248 .trim()
249 .strip_prefix('#')
250 .unwrap(),
251 16,
252 )
253 .ok()
254 .unwrap(),
255 );
256 style.apply_style(
257 None,
258 None,
259 None,
260 Some(s),
261 Some(e),
262 Font::by_name(font.text(font.value()).unwrap().trim()),
263 size.value() as i32,
264 color,
265 attr,
266 &mut text_editor,
267 );
268 }
269 }
270 }
271 });
272
273 // get the style from the current cursor position
274 text_editor.handle({
275 let style_rc1 = Rc::clone(&style);
276 let mut font1 = font.clone();
277 let mut size1 = size.clone();
278 let mut color1 = color.clone();
279 move |te, e| match e {
280 Event::KeyUp | Event::Released => {
281 if let Some(buff) = te.style_buffer() {
282 let i = te.insert_position();
283 if let Some(t) = buff.text_range(i, i + 1) {
284 if !t.is_empty() {
285 let style = style_rc1.borrow_mut();
286 if let Some(i) = t.chars().next().map(|c| (c as usize - 65)) {
287 if let Some(style) = style.style_table.get(i) {
288 if let Some(mn) = font1.find_item(&format!("{:?}", style.font))
289 {
290 font1.set_item(&mn);
291 }
292 size1.set_value(style.size as f64);
293 let (r, g, b) = style.color.to_rgb();
294 if let Some(mn) =
295 color1.find_item(format!("{r:02x}{g:02x}{b:02x}").as_str())
296 {
297 color1.set_item(&mn);
298 }
299 }
300 }
301 }
302 }
303 }
304 true
305 }
306 _ => false,
307 }
308 });
309
310 choice.set_callback({
311 let mut color1 = color.clone();
312 move |_| color1.do_callback()
313 });
314
315 font.set_callback({
316 let mut color1 = color.clone();
317 move |_| color1.do_callback()
318 });
319
320 size.set_callback({
321 let mut color1 = color.clone();
322 move |_| color1.do_callback()
323 });
324
325 // clear style of the current selection or, if no text is selected, clear all text style
326 btn_clear.set_callback({
327 let style_rc1 = Rc::clone(&style);
328 let text_editor1 = text_editor.clone();
329 move |_| {
330 match text_editor1.buffer().unwrap().selection_position() {
331 Some((_, _)) => {
332 font.set_value(0);
333 size.set_value(18.0);
334 color.set_value(0);
335 choice.set_value(0);
336 color.do_callback();
337 }
338 None => {
339 font.set_value(0);
340 size.set_value(18.0);
341 color.set_value(0);
342 style_rc1.borrow_mut().apply_style(
343 None,
344 None,
345 None,
346 Some(0),
347 Some(text_editor1.buffer().unwrap().length()),
348 Font::Courier,
349 16,
350 Color::Black,
351 TextAttr::None,
352 &mut text_editor,
353 );
354 }
355 };
356 }
357 });
358
359 app.run().unwrap();
360}
Sourcepub fn maximum_size(&self) -> i32
pub fn maximum_size(&self) -> i32
Returns the maximum size supported by the spinner widget
Sourcepub fn set_maximum_size(&mut self, s: i32)
pub fn set_maximum_size(&mut self, s: i32)
Sets the maximum size supported by the spinner widget
Sourcepub fn set_text_font(&mut self, f: Font)
pub fn set_text_font(&mut self, f: Font)
Sets the text font
Sourcepub fn set_text_size(&mut self, s: i32)
pub fn set_text_size(&mut self, s: i32)
Sets the text size
Sourcepub fn text_color(&self) -> Color
pub fn text_color(&self) -> Color
Gets the text’s color
Sourcepub fn set_text_color(&mut self, color: Color)
pub fn set_text_color(&mut self, color: Color)
Sets the text’s color
Sourcepub fn value(&self) -> f64
pub fn value(&self) -> f64
Returns the value of the spinner
Examples found in repository?
122fn main() {
123 let style = Rc::from(RefCell::from(Style::new()));
124
125 let app = App::default().with_scheme(Scheme::Gleam);
126 let mut wind = Window::default()
127 .with_size(500, 200)
128 .with_label("Highlight");
129 let mut vpack = Pack::new(4, 4, 492, 192, "");
130 vpack.set_spacing(4);
131 let mut text_editor = TextEditor::default().with_size(492, 163);
132
133 let mut hpack = Pack::new(4, 4, 492, 25, "").with_type(PackType::Horizontal);
134 hpack.set_spacing(8);
135 let mut font = Choice::default().with_size(130, 25);
136 let mut choice = Choice::default().with_size(130, 25);
137 let mut size = Spinner::default().with_size(60, 25);
138
139 let mut color = Choice::default().with_size(100, 25);
140 let mut btn_clear = Button::default().with_size(40, 25).with_label("X");
141 hpack.end();
142
143 vpack.end();
144 wind.end();
145 wind.show();
146
147 text_editor.wrap_mode(fltk::text::WrapMode::AtBounds, 0);
148 text_editor.set_buffer(TextBuffer::default());
149
150 font.add_choice("Courier|Helvetica|Times");
151 font.set_value(0);
152 font.set_tooltip("Font");
153
154 choice.add_choice("Normal|Underline|Strike");
155 choice.set_value(0);
156
157 size.set_value(18.0);
158 size.set_step(1.0);
159 size.set_range(12.0, 28.0);
160 size.set_tooltip("Size");
161
162 color.set_tooltip("Color");
163 color.add_choice("#000000|#ff0000|#00ff00|#0000ff|#ffff00|#00ffff");
164 color.set_value(0);
165
166 btn_clear.set_label_color(Color::Red);
167 btn_clear.set_tooltip("Clear style");
168
169 // set colors
170 for mut item in color.clone() {
171 if let Some(lbl) = item.label() {
172 item.set_label_color(Color::from_u32(
173 u32::from_str_radix(lbl.trim().strip_prefix('#').unwrap(), 16)
174 .ok()
175 .unwrap(),
176 ));
177 }
178 }
179
180 let style_rc1 = Rc::clone(&style);
181
182 text_editor.buffer().unwrap().add_modify_callback({
183 let mut text_editor1 = text_editor.clone();
184 let font1 = font.clone();
185 let size1 = size.clone();
186 let color1 = color.clone();
187 let choice1 = choice.clone();
188 move |_buf, pos: i32, ins_items: i32, del_items: i32, _: i32, _: Option<&str>| {
189 let attr = if choice1.value() == 1 {
190 TextAttr::Underline
191 } else if choice1.value() == 2 {
192 TextAttr::StrikeThrough
193 } else {
194 TextAttr::None
195 };
196 if ins_items > 0 || del_items > 0 {
197 let mut style = style_rc1.borrow_mut();
198 let color = Color::from_u32(
199 u32::from_str_radix(
200 color1
201 .text(color1.value())
202 .unwrap()
203 .trim()
204 .strip_prefix('#')
205 .unwrap(),
206 16,
207 )
208 .ok()
209 .unwrap(),
210 );
211 style.apply_style(
212 Some(pos),
213 Some(ins_items),
214 Some(del_items),
215 None,
216 None,
217 Font::by_name(font1.text(font1.value()).unwrap().trim()),
218 size1.value() as i32,
219 color,
220 attr,
221 &mut text_editor1,
222 );
223 }
224 }
225 });
226
227 color.set_callback({
228 let size = size.clone();
229 let font = font.clone();
230 let choice = choice.clone();
231 let mut text_editor = text_editor.clone();
232 let style_rc1 = Rc::clone(&style);
233 move |color| {
234 let attr = match choice.value() {
235 0 => TextAttr::None,
236 1 => TextAttr::Underline,
237 2 => TextAttr::StrikeThrough,
238 _ => unreachable!(),
239 };
240 if let Some(buf) = text_editor.buffer() {
241 if let Some((s, e)) = buf.selection_position() {
242 let mut style = style_rc1.borrow_mut();
243 let color = Color::from_u32(
244 u32::from_str_radix(
245 color
246 .text(color.value())
247 .unwrap()
248 .trim()
249 .strip_prefix('#')
250 .unwrap(),
251 16,
252 )
253 .ok()
254 .unwrap(),
255 );
256 style.apply_style(
257 None,
258 None,
259 None,
260 Some(s),
261 Some(e),
262 Font::by_name(font.text(font.value()).unwrap().trim()),
263 size.value() as i32,
264 color,
265 attr,
266 &mut text_editor,
267 );
268 }
269 }
270 }
271 });
272
273 // get the style from the current cursor position
274 text_editor.handle({
275 let style_rc1 = Rc::clone(&style);
276 let mut font1 = font.clone();
277 let mut size1 = size.clone();
278 let mut color1 = color.clone();
279 move |te, e| match e {
280 Event::KeyUp | Event::Released => {
281 if let Some(buff) = te.style_buffer() {
282 let i = te.insert_position();
283 if let Some(t) = buff.text_range(i, i + 1) {
284 if !t.is_empty() {
285 let style = style_rc1.borrow_mut();
286 if let Some(i) = t.chars().next().map(|c| (c as usize - 65)) {
287 if let Some(style) = style.style_table.get(i) {
288 if let Some(mn) = font1.find_item(&format!("{:?}", style.font))
289 {
290 font1.set_item(&mn);
291 }
292 size1.set_value(style.size as f64);
293 let (r, g, b) = style.color.to_rgb();
294 if let Some(mn) =
295 color1.find_item(format!("{r:02x}{g:02x}{b:02x}").as_str())
296 {
297 color1.set_item(&mn);
298 }
299 }
300 }
301 }
302 }
303 }
304 true
305 }
306 _ => false,
307 }
308 });
309
310 choice.set_callback({
311 let mut color1 = color.clone();
312 move |_| color1.do_callback()
313 });
314
315 font.set_callback({
316 let mut color1 = color.clone();
317 move |_| color1.do_callback()
318 });
319
320 size.set_callback({
321 let mut color1 = color.clone();
322 move |_| color1.do_callback()
323 });
324
325 // clear style of the current selection or, if no text is selected, clear all text style
326 btn_clear.set_callback({
327 let style_rc1 = Rc::clone(&style);
328 let text_editor1 = text_editor.clone();
329 move |_| {
330 match text_editor1.buffer().unwrap().selection_position() {
331 Some((_, _)) => {
332 font.set_value(0);
333 size.set_value(18.0);
334 color.set_value(0);
335 choice.set_value(0);
336 color.do_callback();
337 }
338 None => {
339 font.set_value(0);
340 size.set_value(18.0);
341 color.set_value(0);
342 style_rc1.borrow_mut().apply_style(
343 None,
344 None,
345 None,
346 Some(0),
347 Some(text_editor1.buffer().unwrap().length()),
348 Font::Courier,
349 16,
350 Color::Black,
351 TextAttr::None,
352 &mut text_editor,
353 );
354 }
355 };
356 }
357 });
358
359 app.run().unwrap();
360}
Sourcepub fn set_value(&mut self, arg2: f64)
pub fn set_value(&mut self, arg2: f64)
Sets the value of the spinner
Examples found in repository?
122fn main() {
123 let style = Rc::from(RefCell::from(Style::new()));
124
125 let app = App::default().with_scheme(Scheme::Gleam);
126 let mut wind = Window::default()
127 .with_size(500, 200)
128 .with_label("Highlight");
129 let mut vpack = Pack::new(4, 4, 492, 192, "");
130 vpack.set_spacing(4);
131 let mut text_editor = TextEditor::default().with_size(492, 163);
132
133 let mut hpack = Pack::new(4, 4, 492, 25, "").with_type(PackType::Horizontal);
134 hpack.set_spacing(8);
135 let mut font = Choice::default().with_size(130, 25);
136 let mut choice = Choice::default().with_size(130, 25);
137 let mut size = Spinner::default().with_size(60, 25);
138
139 let mut color = Choice::default().with_size(100, 25);
140 let mut btn_clear = Button::default().with_size(40, 25).with_label("X");
141 hpack.end();
142
143 vpack.end();
144 wind.end();
145 wind.show();
146
147 text_editor.wrap_mode(fltk::text::WrapMode::AtBounds, 0);
148 text_editor.set_buffer(TextBuffer::default());
149
150 font.add_choice("Courier|Helvetica|Times");
151 font.set_value(0);
152 font.set_tooltip("Font");
153
154 choice.add_choice("Normal|Underline|Strike");
155 choice.set_value(0);
156
157 size.set_value(18.0);
158 size.set_step(1.0);
159 size.set_range(12.0, 28.0);
160 size.set_tooltip("Size");
161
162 color.set_tooltip("Color");
163 color.add_choice("#000000|#ff0000|#00ff00|#0000ff|#ffff00|#00ffff");
164 color.set_value(0);
165
166 btn_clear.set_label_color(Color::Red);
167 btn_clear.set_tooltip("Clear style");
168
169 // set colors
170 for mut item in color.clone() {
171 if let Some(lbl) = item.label() {
172 item.set_label_color(Color::from_u32(
173 u32::from_str_radix(lbl.trim().strip_prefix('#').unwrap(), 16)
174 .ok()
175 .unwrap(),
176 ));
177 }
178 }
179
180 let style_rc1 = Rc::clone(&style);
181
182 text_editor.buffer().unwrap().add_modify_callback({
183 let mut text_editor1 = text_editor.clone();
184 let font1 = font.clone();
185 let size1 = size.clone();
186 let color1 = color.clone();
187 let choice1 = choice.clone();
188 move |_buf, pos: i32, ins_items: i32, del_items: i32, _: i32, _: Option<&str>| {
189 let attr = if choice1.value() == 1 {
190 TextAttr::Underline
191 } else if choice1.value() == 2 {
192 TextAttr::StrikeThrough
193 } else {
194 TextAttr::None
195 };
196 if ins_items > 0 || del_items > 0 {
197 let mut style = style_rc1.borrow_mut();
198 let color = Color::from_u32(
199 u32::from_str_radix(
200 color1
201 .text(color1.value())
202 .unwrap()
203 .trim()
204 .strip_prefix('#')
205 .unwrap(),
206 16,
207 )
208 .ok()
209 .unwrap(),
210 );
211 style.apply_style(
212 Some(pos),
213 Some(ins_items),
214 Some(del_items),
215 None,
216 None,
217 Font::by_name(font1.text(font1.value()).unwrap().trim()),
218 size1.value() as i32,
219 color,
220 attr,
221 &mut text_editor1,
222 );
223 }
224 }
225 });
226
227 color.set_callback({
228 let size = size.clone();
229 let font = font.clone();
230 let choice = choice.clone();
231 let mut text_editor = text_editor.clone();
232 let style_rc1 = Rc::clone(&style);
233 move |color| {
234 let attr = match choice.value() {
235 0 => TextAttr::None,
236 1 => TextAttr::Underline,
237 2 => TextAttr::StrikeThrough,
238 _ => unreachable!(),
239 };
240 if let Some(buf) = text_editor.buffer() {
241 if let Some((s, e)) = buf.selection_position() {
242 let mut style = style_rc1.borrow_mut();
243 let color = Color::from_u32(
244 u32::from_str_radix(
245 color
246 .text(color.value())
247 .unwrap()
248 .trim()
249 .strip_prefix('#')
250 .unwrap(),
251 16,
252 )
253 .ok()
254 .unwrap(),
255 );
256 style.apply_style(
257 None,
258 None,
259 None,
260 Some(s),
261 Some(e),
262 Font::by_name(font.text(font.value()).unwrap().trim()),
263 size.value() as i32,
264 color,
265 attr,
266 &mut text_editor,
267 );
268 }
269 }
270 }
271 });
272
273 // get the style from the current cursor position
274 text_editor.handle({
275 let style_rc1 = Rc::clone(&style);
276 let mut font1 = font.clone();
277 let mut size1 = size.clone();
278 let mut color1 = color.clone();
279 move |te, e| match e {
280 Event::KeyUp | Event::Released => {
281 if let Some(buff) = te.style_buffer() {
282 let i = te.insert_position();
283 if let Some(t) = buff.text_range(i, i + 1) {
284 if !t.is_empty() {
285 let style = style_rc1.borrow_mut();
286 if let Some(i) = t.chars().next().map(|c| (c as usize - 65)) {
287 if let Some(style) = style.style_table.get(i) {
288 if let Some(mn) = font1.find_item(&format!("{:?}", style.font))
289 {
290 font1.set_item(&mn);
291 }
292 size1.set_value(style.size as f64);
293 let (r, g, b) = style.color.to_rgb();
294 if let Some(mn) =
295 color1.find_item(format!("{r:02x}{g:02x}{b:02x}").as_str())
296 {
297 color1.set_item(&mn);
298 }
299 }
300 }
301 }
302 }
303 }
304 true
305 }
306 _ => false,
307 }
308 });
309
310 choice.set_callback({
311 let mut color1 = color.clone();
312 move |_| color1.do_callback()
313 });
314
315 font.set_callback({
316 let mut color1 = color.clone();
317 move |_| color1.do_callback()
318 });
319
320 size.set_callback({
321 let mut color1 = color.clone();
322 move |_| color1.do_callback()
323 });
324
325 // clear style of the current selection or, if no text is selected, clear all text style
326 btn_clear.set_callback({
327 let style_rc1 = Rc::clone(&style);
328 let text_editor1 = text_editor.clone();
329 move |_| {
330 match text_editor1.buffer().unwrap().selection_position() {
331 Some((_, _)) => {
332 font.set_value(0);
333 size.set_value(18.0);
334 color.set_value(0);
335 choice.set_value(0);
336 color.do_callback();
337 }
338 None => {
339 font.set_value(0);
340 size.set_value(18.0);
341 color.set_value(0);
342 style_rc1.borrow_mut().apply_style(
343 None,
344 None,
345 None,
346 Some(0),
347 Some(text_editor1.buffer().unwrap().length()),
348 Font::Courier,
349 16,
350 Color::Black,
351 TextAttr::None,
352 &mut text_editor,
353 );
354 }
355 };
356 }
357 });
358
359 app.run().unwrap();
360}
Trait Implementations§
Source§impl WidgetBase for Spinner
impl WidgetBase for Spinner
Source§unsafe fn from_widget_ptr(ptr: *mut Fl_Widget) -> Self
unsafe fn from_widget_ptr(ptr: *mut Fl_Widget) -> Self
Source§unsafe fn from_widget<W: WidgetExt>(w: W) -> Self
unsafe fn from_widget<W: WidgetExt>(w: W) -> Self
Source§fn handle<F: FnMut(&mut Self, Event) -> bool + 'static>(&mut self, cb: F)
fn handle<F: FnMut(&mut Self, Event) -> bool + 'static>(&mut self, cb: F)
Fl_Widget::handle(int)
.
Handled or ignored events should return true, unhandled events should return false.
takes the widget as a closure argument.
The ability to handle an event might depend on handling other events, as explained hereSource§fn draw<F: FnMut(&mut Self) + 'static>(&mut self, cb: F)
fn draw<F: FnMut(&mut Self) + 'static>(&mut self, cb: F)
WidgetBase::draw
actually calls drawing functionsSource§fn resize_callback<F: FnMut(&mut Self, i32, i32, i32, i32) + 'static>(
&mut self,
cb: F,
)
fn resize_callback<F: FnMut(&mut Self, i32, i32, i32, i32) + 'static>( &mut self, cb: F, )
Source§unsafe fn assume_derived(&mut self)
unsafe fn assume_derived(&mut self)
Source§impl WidgetExt for Spinner
impl WidgetExt for Spinner
Source§fn set_label(&mut self, title: &str)
fn set_label(&mut self, title: &str)
@
sign.
and for the associated formatting.Source§fn unset_label(&mut self)
fn unset_label(&mut self)
Source§fn measure_label(&self) -> (i32, i32)
fn measure_label(&self) -> (i32, i32)
Source§fn as_widget_ptr(&self) -> *mut Fl_Widget
fn as_widget_ptr(&self) -> *mut Fl_Widget
Fl_Widget
, for internal useSource§fn deactivate(&mut self)
fn deactivate(&mut self)
Source§fn redraw_label(&mut self)
fn redraw_label(&mut self)
Source§fn resize(&mut self, x: i32, y: i32, width: i32, height: i32)
fn resize(&mut self, x: i32, y: i32, width: i32, height: i32)
Source§fn widget_resize(&mut self, x: i32, y: i32, width: i32, height: i32)
fn widget_resize(&mut self, x: i32, y: i32, width: i32, height: i32)
Source§fn set_tooltip(&mut self, txt: &str)
fn set_tooltip(&mut self, txt: &str)
Source§fn label_color(&self) -> Color
fn label_color(&self) -> Color
Source§fn set_label_color(&mut self, color: Color)
fn set_label_color(&mut self, color: Color)
Source§fn label_font(&self) -> Font
fn label_font(&self) -> Font
Source§fn set_label_font(&mut self, font: Font)
fn set_label_font(&mut self, font: Font)
Source§fn label_size(&self) -> i32
fn label_size(&self) -> i32
Source§fn set_label_size(&mut self, sz: i32)
fn set_label_size(&mut self, sz: i32)
Source§fn label_type(&self) -> LabelType
fn label_type(&self) -> LabelType
Source§fn set_label_type(&mut self, typ: LabelType)
fn set_label_type(&mut self, typ: LabelType)
Source§fn set_changed(&mut self)
fn set_changed(&mut self)
Source§fn clear_changed(&mut self)
fn clear_changed(&mut self)
Source§fn set_when(&mut self, trigger: When)
fn set_when(&mut self, trigger: When)
when()
Source§fn selection_color(&self) -> Color
fn selection_color(&self) -> Color
Source§fn set_selection_color(&mut self, color: Color)
fn set_selection_color(&mut self, color: Color)
Source§fn do_callback(&mut self)
fn do_callback(&mut self)
Source§fn top_window(&self) -> Option<Box<dyn WindowExt>>
fn top_window(&self) -> Option<Box<dyn WindowExt>>
Source§fn takes_events(&self) -> bool
fn takes_events(&self) -> bool
Source§fn set_visible_focus(&mut self)
fn set_visible_focus(&mut self)
Source§fn clear_visible_focus(&mut self)
fn clear_visible_focus(&mut self)
Source§fn visible_focus(&mut self, v: bool)
fn visible_focus(&mut self, v: bool)
Source§fn has_visible_focus(&self) -> bool
fn has_visible_focus(&self) -> bool
Source§fn was_deleted(&self) -> bool
fn was_deleted(&self) -> bool
Source§fn set_damage(&mut self, flag: bool)
fn set_damage(&mut self, flag: bool)
Source§fn damage_type(&self) -> Damage
fn damage_type(&self) -> Damage
Source§fn set_damage_type(&mut self, mask: Damage)
fn set_damage_type(&mut self, mask: Damage)
Source§fn set_damage_area(&mut self, mask: Damage, x: i32, y: i32, w: i32, h: i32)
fn set_damage_area(&mut self, mask: Damage, x: i32, y: i32, w: i32, h: i32)
Source§fn clear_damage(&mut self)
fn clear_damage(&mut self)
Source§fn as_window(&self) -> Option<Box<dyn WindowExt>>
fn as_window(&self) -> Option<Box<dyn WindowExt>>
Source§fn as_group(&self) -> Option<Group>
fn as_group(&self) -> Option<Group>
Source§fn inside<W: WidgetExt>(&self, wid: &W) -> bool
fn inside<W: WidgetExt>(&self, wid: &W) -> bool
Source§fn get_type<T: WidgetType>(&self) -> T
fn get_type<T: WidgetType>(&self) -> T
Source§fn set_type<T: WidgetType>(&mut self, typ: T)
fn set_type<T: WidgetType>(&mut self, typ: T)
Source§fn set_image_scaled<I: ImageExt>(&mut self, image: Option<I>)
fn set_image_scaled<I: ImageExt>(&mut self, image: Option<I>)
Source§fn set_deimage<I: ImageExt>(&mut self, image: Option<I>)
fn set_deimage<I: ImageExt>(&mut self, image: Option<I>)
Source§fn set_deimage_scaled<I: ImageExt>(&mut self, image: Option<I>)
fn set_deimage_scaled<I: ImageExt>(&mut self, image: Option<I>)
Source§fn deimage(&self) -> Option<Box<dyn ImageExt>>
fn deimage(&self) -> Option<Box<dyn ImageExt>>
Source§fn set_callback<F: FnMut(&mut Self) + 'static>(&mut self, cb: F)
fn set_callback<F: FnMut(&mut Self) + 'static>(&mut self, cb: F)
Source§fn emit<T: 'static + Clone + Send + Sync>(&mut self, sender: Sender<T>, msg: T)
fn emit<T: 'static + Clone + Send + Sync>(&mut self, sender: Sender<T>, msg: T)
Source§unsafe fn as_widget<W: WidgetBase>(&self) -> W
unsafe fn as_widget<W: WidgetBase>(&self) -> W
WidgetExt
to some widget type Read moreSource§fn visible_r(&self) -> bool
fn visible_r(&self) -> bool
Source§fn is_same<W: WidgetExt>(&self, other: &W) -> bool
fn is_same<W: WidgetExt>(&self, other: &W) -> bool
Source§fn active_r(&self) -> bool
fn active_r(&self) -> bool
Source§fn handle_event(&mut self, event: Event) -> bool
fn handle_event(&mut self, event: Event) -> bool
Source§fn is_derived(&self) -> bool
fn is_derived(&self) -> bool
Source§fn as_base_widget(&self) -> Widgetwhere
Self: Sized,
fn as_base_widget(&self) -> Widgetwhere
Self: Sized,
WidgetExt
to a WidgetSource§impl WidgetProps for Spinner
impl WidgetProps for Spinner
Source§fn with_label(self, title: &str) -> Self
fn with_label(self, title: &str) -> Self
Initialize with a label
Source§fn with_align(self, align: Align) -> Self
fn with_align(self, align: Align) -> Self
Initialize with alignment
Source§fn with_type<T: WidgetType>(self, typ: T) -> Self
fn with_type<T: WidgetType>(self, typ: T) -> Self
Initialize with type
Source§fn below_of<W: WidgetExt>(self, wid: &W, padding: i32) -> Self
fn below_of<W: WidgetExt>(self, wid: &W, padding: i32) -> Self
Initialize at bottom of another widget
Source§fn above_of<W: WidgetExt>(self, wid: &W, padding: i32) -> Self
fn above_of<W: WidgetExt>(self, wid: &W, padding: i32) -> Self
Initialize above of another widget
Source§fn right_of<W: WidgetExt>(self, wid: &W, padding: i32) -> Self
fn right_of<W: WidgetExt>(self, wid: &W, padding: i32) -> Self
Initialize right of another widget
Source§fn left_of<W: WidgetExt>(self, wid: &W, padding: i32) -> Self
fn left_of<W: WidgetExt>(self, wid: &W, padding: i32) -> Self
Initialize left of another widget
Source§fn center_x<W: WidgetExt>(self, w: &W) -> Self
fn center_x<W: WidgetExt>(self, w: &W) -> Self
Initialize center of another widget on the x axis
Source§fn center_y<W: WidgetExt>(self, w: &W) -> Self
fn center_y<W: WidgetExt>(self, w: &W) -> Self
Initialize center of another widget on the y axis
Source§fn center_of_parent(self) -> Self
fn center_of_parent(self) -> Self
Initialize center of parent
Source§fn size_of_parent(self) -> Self
fn size_of_parent(self) -> Self
Initialize to the size of the parent
impl Eq for Spinner
impl Send for Spinner
single-threaded
only.impl Sync for Spinner
single-threaded
only.