Skip to main content

Label

Struct Label 

Source
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 events
  • flags: A combination of the LabelFlags values.
  • ex_flags: A combination of win32 window extended flags. Unlike flags, ex_flags must be used straight from winapi
  • font: The font used for the label text
  • background_color: The background color of the label
  • h_align: The horizontal aligment of the label

Control events:

  • OnLabelClick: When the user click the label
  • OnLabelDoubleClick: When the user double click a label
  • MousePress(_): Generic mouse press events on the label
  • OnMouseMove: Generic mouse mouse event
  • OnMouseWheel: 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: ControlHandle

Implementations§

Source§

impl Label

Source

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        }
Source

pub fn font(&self) -> Option<Font>

Return the font of the control

Source

pub fn set_font(&self, font: Option<&Font>)

Set the font of the control

Source

pub fn focus(&self) -> bool

Return true if the control currently has the keyboard focus

Source

pub fn set_focus(&self)

Set the keyboard focus on the button.

Source

pub fn enabled(&self) -> bool

Return true if the control user can interact with the control, return false otherwise

Source

pub fn set_enabled(&self, v: bool)

Enable or disable the control

Source

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))

Source

pub fn set_visible(&self, v: bool)

Show or hide the control to the user

Source

pub fn size(&self) -> (u32, u32)

Return the size of the label in the parent window

Source

pub fn set_size(&self, x: u32, y: u32)

Set the size of the label in the parent window

Source

pub fn position(&self) -> (i32, i32)

Return the position of the label in the parent window

Source

pub fn set_position(&self, x: i32, y: i32)

Set the position of the label in the parent window

Source

pub fn text(&self) -> String

Return the label text

Source

pub fn set_text<'a>(&self, v: &'a str)

Set the label text

Source

pub fn class_name(&self) -> &'static str

Winapi class name used during control creation

Source

pub fn flags(&self) -> u32

Winapi base flags used during window creation

Source

pub fn forced_flags(&self) -> u32

Winapi flags required by the control

Trait Implementations§

Source§

impl Default for Label

Source§

fn default() -> Label

Returns the “default value” for a type. Read more
Source§

impl Drop for Label

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more
Source§

impl From<&Label> for ControlHandle

Source§

fn from(control: &Label) -> Self

Converts to this type from the input type.
Source§

impl From<&mut Label> for ControlHandle

Source§

fn from(control: &mut Label) -> Self

Converts to this type from the input type.
Source§

impl PartialEq for Label

Source§

fn eq(&self, other: &Self) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialEq<ControlHandle> for Label

Source§

fn eq(&self, other: &ControlHandle) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialEq<Label> for ControlHandle

Source§

fn eq(&self, other: &Label) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.

Auto Trait Implementations§

§

impl !Freeze for Label

§

impl !RefUnwindSafe for Label

§

impl !Send for Label

§

impl !Sync for Label

§

impl Unpin for Label

§

impl UnsafeUnpin for Label

§

impl UnwindSafe for Label

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.