pub struct Label {
pub handle: ControlHandle,
/* private fields */
}Expand description
A label is a single line of static text. Use \r\n to split the text on multiple lines.
Label is not behind any features.
Builder parameters:
parent: Required. The label parent container.text: The label text.size: The label size.position: The label position.enabled: If the label is enabled. A disabled label won’t trigger eventsflags: A combination of the LabelFlags values.ex_flags: A combination of win32 window extended flags. Unlikeflags, ex_flags must be used straight from winapifont: The font used for the label textbackground_color: The background color of the labelh_align: The horizontal aligment of the label
Control events:
OnLabelClick: When the user click the labelOnLabelDoubleClick: When the user double click a labelMousePress(_): Generic mouse press events on the labelOnMouseMove: Generic mouse mouse eventOnMouseWheel: Generic mouse wheel event
** Example **
use native_windows_gui2 as nwg;
fn build_label(label: &mut nwg::Label, window: &nwg::Window, font: &nwg::Font) {
nwg::Label::builder()
.text("Hello")
.font(Some(font))
.parent(window)
.build(label);
}Fields§
§handle: ControlHandleImplementations§
Source§impl Label
impl Label
Sourcepub fn builder<'a>() -> LabelBuilder<'a>
pub fn builder<'a>() -> LabelBuilder<'a>
Examples found in repository?
examples/partials.rs (line 275)
269 fn build_partial<W: Into<ControlHandle>>(
270 data: &mut PeopleUi,
271 parent: Option<W>,
272 ) -> Result<(), NwgError> {
273 let parent = parent.unwrap().into();
274
275 nwg::Label::builder()
276 .text("Name:")
277 .h_align(nwg::HTextAlign::Right)
278 .parent(&parent)
279 .build(&mut data.label1)?;
280
281 nwg::Label::builder()
282 .text("Age:")
283 .h_align(nwg::HTextAlign::Right)
284 .parent(&parent)
285 .build(&mut data.label2)?;
286
287 nwg::Label::builder()
288 .text("Job:")
289 .h_align(nwg::HTextAlign::Right)
290 .parent(&parent)
291 .build(&mut data.label3)?;
292
293 nwg::TextInput::builder()
294 .text("John Doe")
295 .parent(&parent)
296 .build(&mut data.name_input)?;
297
298 nwg::TextInput::builder()
299 .text("75")
300 .flags(nwg::TextInputFlags::VISIBLE | nwg::TextInputFlags::NUMBER)
301 .parent(&parent)
302 .build(&mut data.age_input)?;
303
304 nwg::TextInput::builder()
305 .text("Programmer")
306 .parent(&parent)
307 .build(&mut data.job_input)?;
308
309 nwg::Button::builder()
310 .text("Save")
311 .parent(&parent)
312 .build(&mut data.save_btn)?;
313
314 nwg::GridLayout::builder()
315 .parent(&parent)
316 .max_size([1000, 150])
317 .min_size([100, 120])
318 .child(0, 0, &data.label1)
319 .child(0, 1, &data.label2)
320 .child(0, 2, &data.label3)
321 .child(1, 0, &data.name_input)
322 .child(1, 1, &data.age_input)
323 .child(1, 2, &data.job_input)
324 .build(&data.layout)?;
325
326 nwg::GridLayout::builder()
327 .min_size([100, 200])
328 .max_column(Some(2))
329 .max_row(Some(6))
330 .child(1, 5, &data.save_btn)
331 .parent(&parent)
332 .build(&data.layout2)?;
333
334 Ok(())
335 }
336
337 fn process_event<'a>(
338 &self,
339 _evt: nwg::Event,
340 _evt_data: &nwg::EventData,
341 _handle: ControlHandle,
342 ) {
343 }
344
345 fn handles(&self) -> Vec<&ControlHandle> {
346 Vec::new()
347 }
348 }
349}
350
351mod partial_animal_ui {
352 use self::nwg::{ControlHandle, NwgError, PartialUi};
353 use super::*;
354 use native_windows_gui2 as nwg;
355
356 impl PartialUi for AnimalUi {
357 fn build_partial<W: Into<ControlHandle>>(
358 data: &mut AnimalUi,
359 parent: Option<W>,
360 ) -> Result<(), NwgError> {
361 let parent = parent.unwrap().into();
362
363 nwg::Label::builder()
364 .text("Name:")
365 .h_align(nwg::HTextAlign::Right)
366 .parent(&parent)
367 .build(&mut data.label1)?;
368
369 nwg::Label::builder()
370 .text("Race:")
371 .h_align(nwg::HTextAlign::Right)
372 .parent(&parent)
373 .build(&mut data.label2)?;
374
375 nwg::Label::builder()
376 .text("Is fluffy:")
377 .h_align(nwg::HTextAlign::Right)
378 .parent(&parent)
379 .build(&mut data.label3)?;
380
381 nwg::TextInput::builder()
382 .text("Mittens")
383 .parent(&parent)
384 .build(&mut data.name_input)?;
385
386 nwg::ComboBox::builder()
387 .collection(vec!["Cat", "Dog", "Pidgeon", "Monkey"])
388 .selected_index(Some(0))
389 .parent(&parent)
390 .build(&mut data.race_input)?;
391
392 nwg::CheckBox::builder()
393 .text("")
394 .check_state(nwg::CheckBoxState::Checked)
395 .parent(&parent)
396 .build(&mut data.is_soft_input)?;
397
398 nwg::Button::builder()
399 .text("Save")
400 .parent(&parent)
401 .build(&mut data.save_btn)?;
402
403 nwg::GridLayout::builder()
404 .parent(&parent)
405 .max_size([1000, 150])
406 .min_size([100, 120])
407 .child(0, 0, &data.label1)
408 .child(0, 1, &data.label2)
409 .child(0, 2, &data.label3)
410 .child(1, 0, &data.name_input)
411 .child(1, 1, &data.race_input)
412 .child(1, 2, &data.is_soft_input)
413 .build(&data.layout)?;
414
415 nwg::GridLayout::builder()
416 .min_size([100, 200])
417 .max_column(Some(2))
418 .max_row(Some(6))
419 .child(1, 5, &data.save_btn)
420 .parent(&parent)
421 .build(&data.layout2)?;
422
423 Ok(())
424 }
425
426 fn process_event<'a>(
427 &self,
428 _evt: nwg::Event,
429 _evt_data: &nwg::EventData,
430 _handle: ControlHandle,
431 ) {
432 }
433
434 fn handles(&self) -> Vec<&ControlHandle> {
435 Vec::new()
436 }
437 }
438}
439
440mod partial_food_ui {
441 use self::nwg::{ControlHandle, NwgError, PartialUi};
442 use super::*;
443 use native_windows_gui2 as nwg;
444
445 impl PartialUi for FoodUi {
446 fn build_partial<W: Into<ControlHandle>>(
447 data: &mut FoodUi,
448 parent: Option<W>,
449 ) -> Result<(), NwgError> {
450 let parent = parent.unwrap().into();
451
452 nwg::Label::builder()
453 .text("Name:")
454 .h_align(nwg::HTextAlign::Right)
455 .parent(&parent)
456 .build(&mut data.label1)?;
457
458 nwg::Label::builder()
459 .text("Tasty:")
460 .h_align(nwg::HTextAlign::Right)
461 .parent(&parent)
462 .build(&mut data.label2)?;
463
464 nwg::TextInput::builder()
465 .text("Banana")
466 .parent(&parent)
467 .build(&mut data.name_input)?;
468
469 nwg::CheckBox::builder()
470 .text("")
471 .check_state(nwg::CheckBoxState::Checked)
472 .parent(&parent)
473 .build(&mut data.tasty_input)?;
474
475 nwg::Button::builder()
476 .text("Save")
477 .parent(&parent)
478 .build(&mut data.save_btn)?;
479
480 nwg::GridLayout::builder()
481 .parent(&parent)
482 .max_size([1000, 90])
483 .min_size([100, 80])
484 .child(0, 0, &data.label1)
485 .child(0, 1, &data.label2)
486 .child(1, 0, &data.name_input)
487 .child(1, 1, &data.tasty_input)
488 .build(&data.layout)?;
489
490 nwg::GridLayout::builder()
491 .min_size([100, 200])
492 .max_column(Some(2))
493 .max_row(Some(6))
494 .child(1, 5, &data.save_btn)
495 .parent(&parent)
496 .build(&data.layout2)?;
497
498 Ok(())
499 }Sourcepub fn enabled(&self) -> bool
pub fn enabled(&self) -> bool
Return true if the control user can interact with the control, return false otherwise
Sourcepub fn set_enabled(&self, v: bool)
pub fn set_enabled(&self, v: bool)
Enable or disable the control
Sourcepub fn visible(&self) -> bool
pub fn visible(&self) -> bool
Return true if the control is visible to the user. Will return true even if the control is outside of the parent client view (ex: at the position (10000, 10000))
Sourcepub fn set_visible(&self, v: bool)
pub fn set_visible(&self, v: bool)
Show or hide the control to the user
Sourcepub fn set_position(&self, x: i32, y: i32)
pub fn set_position(&self, x: i32, y: i32)
Set the position of the label in the parent window
Sourcepub fn class_name(&self) -> &'static str
pub fn class_name(&self) -> &'static str
Winapi class name used during control creation
Sourcepub fn forced_flags(&self) -> u32
pub fn forced_flags(&self) -> u32
Winapi flags required by the control
Trait Implementations§
Source§impl From<&Label> for ControlHandle
impl From<&Label> for ControlHandle
Source§impl From<&mut Label> for ControlHandle
impl From<&mut Label> for ControlHandle
Source§impl PartialEq<ControlHandle> for Label
impl PartialEq<ControlHandle> for Label
Source§impl PartialEq<Label> for ControlHandle
impl PartialEq<Label> for ControlHandle
Auto Trait Implementations§
impl !Freeze for Label
impl !RefUnwindSafe for Label
impl !Send for Label
impl !Sync for Label
impl Unpin for Label
impl UnwindSafe for Label
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more