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_gui 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 253)
250        fn build_partial<W: Into<ControlHandle>>(data: &mut PeopleUi, parent: Option<W>) -> Result<(), NwgError> {
251            let parent = parent.unwrap().into();
252
253            nwg::Label::builder()
254                .text("Name:")
255                .h_align(nwg::HTextAlign::Right)
256                .parent(&parent)
257                .build(&mut data.label1)?;
258
259            nwg::Label::builder()
260                .text("Age:")
261                .h_align(nwg::HTextAlign::Right)
262                .parent(&parent)
263                .build(&mut data.label2)?;
264
265            nwg::Label::builder()
266                .text("Job:")
267                .h_align(nwg::HTextAlign::Right)
268                .parent(&parent)
269                .build(&mut data.label3)?;
270
271            nwg::TextInput::builder()
272                .text("John Doe")
273                .parent(&parent)
274                .build(&mut data.name_input)?;
275
276            nwg::TextInput::builder()
277                .text("75")
278                .flags(nwg::TextInputFlags::VISIBLE | nwg::TextInputFlags::NUMBER)
279                .parent(&parent)
280                .build(&mut data.age_input)?;
281
282            nwg::TextInput::builder()
283                .text("Programmer")
284                .parent(&parent)
285                .build(&mut data.job_input)?;
286
287            nwg::Button::builder()
288                .text("Save")
289                .parent(&parent)
290                .build(&mut data.save_btn)?;
291                
292            nwg::GridLayout::builder()
293                .parent(&parent)
294                .max_size([1000, 150])
295                .min_size([100, 120])
296                .child(0, 0, &data.label1)
297                .child(0, 1, &data.label2)
298                .child(0, 2, &data.label3)
299                .child(1, 0, &data.name_input)
300                .child(1, 1, &data.age_input)
301                .child(1, 2, &data.job_input)
302                .build(&data.layout)?;
303
304            nwg::GridLayout::builder()
305                .min_size([100, 200])
306                .max_column(Some(2))
307                .max_row(Some(6))
308                .child(1, 5, &data.save_btn)
309                .parent(&parent)
310                .build(&data.layout2)?;
311
312            Ok(())
313        }
314
315        fn process_event<'a>(&self, _evt: nwg::Event, _evt_data: &nwg::EventData, _handle: ControlHandle) {
316        }
317
318        fn handles(&self) -> Vec<&ControlHandle> {
319            Vec::new()
320        }
321    }
322}
323
324mod partial_animal_ui {
325    use native_windows_gui as nwg;
326    use self::nwg::{PartialUi, NwgError, ControlHandle};
327    use super::*;
328
329    impl PartialUi for AnimalUi {
330
331        fn build_partial<W: Into<ControlHandle>>(data: &mut AnimalUi, parent: Option<W>) -> Result<(), NwgError> {
332            let parent = parent.unwrap().into();
333
334            nwg::Label::builder()
335                .text("Name:")
336                .h_align(nwg::HTextAlign::Right)
337                .parent(&parent)
338                .build(&mut data.label1)?;
339
340            nwg::Label::builder()
341                .text("Race:")
342                .h_align(nwg::HTextAlign::Right)
343                .parent(&parent)
344                .build(&mut data.label2)?;
345
346            nwg::Label::builder()
347                .text("Is fluffy:")
348                .h_align(nwg::HTextAlign::Right)
349                .parent(&parent)
350                .build(&mut data.label3)?;
351
352            nwg::TextInput::builder()
353                .text("Mittens")
354                .parent(&parent)
355                .build(&mut data.name_input)?;
356
357            nwg::ComboBox::builder()
358                .collection(vec!["Cat", "Dog", "Pidgeon", "Monkey"])
359                .selected_index(Some(0))
360                .parent(&parent)
361                .build(&mut data.race_input)?;
362
363            nwg::CheckBox::builder()
364                .text("")
365                .check_state(nwg::CheckBoxState::Checked)
366                .parent(&parent)
367                .build(&mut data.is_soft_input)?;
368
369            nwg::Button::builder()
370                .text("Save")
371                .parent(&parent)
372                .build(&mut data.save_btn)?;
373
374            nwg::GridLayout::builder()
375                .parent(&parent)
376                .max_size([1000, 150])
377                .min_size([100, 120])
378                .child(0, 0, &data.label1)
379                .child(0, 1, &data.label2)
380                .child(0, 2, &data.label3)
381                .child(1, 0, &data.name_input)
382                .child(1, 1, &data.race_input)
383                .child(1, 2, &data.is_soft_input)
384                .build(&data.layout)?;
385
386            nwg::GridLayout::builder()
387                .min_size([100, 200])
388                .max_column(Some(2))
389                .max_row(Some(6))
390                .child(1, 5, &data.save_btn)
391                .parent(&parent)
392                .build(&data.layout2)?;
393
394            Ok(())
395        }
396
397        fn process_event<'a>(&self, _evt: nwg::Event, _evt_data: &nwg::EventData, _handle: ControlHandle) {
398        }
399
400        fn handles(&self) -> Vec<&ControlHandle> {
401            Vec::new()
402        }
403    }
404}
405
406mod partial_food_ui {
407    use native_windows_gui as nwg;
408    use self::nwg::{PartialUi, NwgError, ControlHandle};
409    use super::*;
410
411    impl PartialUi for FoodUi {
412        fn build_partial<W: Into<ControlHandle>>(data: &mut FoodUi, parent: Option<W>) -> Result<(), NwgError> {
413            let parent = parent.unwrap().into();
414
415            nwg::Label::builder()
416                .text("Name:")
417                .h_align(nwg::HTextAlign::Right)
418                .parent(&parent)
419                .build(&mut data.label1)?;
420
421            nwg::Label::builder()
422                .text("Tasty:")
423                .h_align(nwg::HTextAlign::Right)
424                .parent(&parent)
425                .build(&mut data.label2)?;
426
427            nwg::TextInput::builder()
428                .text("Banana")
429                .parent(&parent)
430                .build(&mut data.name_input)?;
431
432            nwg::CheckBox::builder()
433                .text("")
434                .check_state(nwg::CheckBoxState::Checked)
435                .parent(&parent)
436                .build(&mut data.tasty_input)?;
437
438            nwg::Button::builder()
439                .text("Save")
440                .parent(&parent)
441                .build(&mut data.save_btn)?;
442
443            nwg::GridLayout::builder()
444                .parent(&parent)
445                .max_size([1000, 90])
446                .min_size([100, 80])
447                .child(0, 0, &data.label1)
448                .child(0, 1, &data.label2)
449                .child(1, 0, &data.name_input)
450                .child(1, 1, &data.tasty_input)
451                .build(&data.layout)?;
452
453            nwg::GridLayout::builder()
454                .min_size([100, 200])
455                .max_column(Some(2))
456                .max_row(Some(6))
457                .child(1, 5, &data.save_btn)
458                .parent(&parent)
459                .build(&data.layout2)?;
460
461            Ok(())
462        }
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§

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<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 · 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 · 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 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 · 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 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.