Skip to main content

TextBox

Struct TextBox 

Source
pub struct TextBox {
    pub handle: ControlHandle,
}
Expand description

An edit control is a rectangular control window to permit the user to enter and edit text by typing on the keyboard This control allow multi line input. For a single line of text, use TextInput.

Requires the textbox feature.

Note: Use \r\n to input a new line not just \n.

Builder parameters:

  • parent: Required. The text box parent container.
  • text: The text box text.
  • size: The text box size.
  • position: The text box position.
  • flags: A combination of the TextBoxFlags 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 text box text
  • limit: The maximum number of character that can be inserted in the control
  • readonly: If the textbox should allow user input or not
  • focus: The control receive focus after being created

Control events:

  • OnTextInput: When a TextBox value is changed
  • MousePress(_): Generic mouse press events on the button
  • OnMouseMove: Generic mouse mouse event
  • OnMouseWheel: Generic mouse wheel event
  • OnKeyPress: Generic key press event
  • OnKeyRelease: Generic key release event
use native_windows_gui2 as nwg;
fn build_box(tbox: &mut nwg::TextBox, window: &nwg::Window, font: &nwg::Font) {
    nwg::TextBox::builder()
        .text("Hello")
        .font(Some(font))
        .parent(window)
        .build(tbox);
}

Fields§

§handle: ControlHandle

Implementations§

Source§

impl TextBox

Source

pub fn builder<'a>() -> TextBoxBuilder<'a>

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 limit(&self) -> u32

Return the number of maximum character allowed in this text input

Source

pub fn set_limit(&self, limit: usize)

Set the number of maximum character allowed in this text input

Source

pub fn modified(&self) -> bool

Check if the content of the text input was modified after it’s creation

Source

pub fn set_modified(&self, e: bool)

Manually set modified flag of the text input

Source

pub fn undo(&self)

Undo the last action by the user in the control

Source

pub fn selection(&self) -> Range<u32>

Return the selected range of characters by the user in the text input

Source

pub fn set_selection(&self, r: Range<u32>)

Return the selected range of characters by the user in the text input

Source

pub fn len(&self) -> u32

Return the length of the user input in the control. Performs a newline conversion first since Windows treats “\r\n” as a single character

Source

pub fn linecount(&self) -> i32

Return the number of lines in the multiline edit control. If the control has no text, the return value is 1.

Source

pub fn scroll(&self, v: i32)

Scroll v lines in the multiline edit control.

Source

pub fn scroll_lastline(&self)

Get the linecount and then scroll the text to the last line

Source

pub fn readonly(&self) -> bool

Return true if the TextInput value cannot be edited. Retrurn false otherwise. A user can still copy text from a readonly TextEdit (unlike disabled)

Source

pub fn set_readonly(&self, r: bool)

Set the readonly flag of the text input A user can still copy text from a readonly TextEdit (unlike disabled)

Source

pub fn clear(&self)

Remove all text from the textbox

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 button in the parent window

Source

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

Set the size of the button in the parent window

Source

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

Return the position of the button in the parent window

Source

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

Set the position of the button in the parent window

Source

pub fn text(&self) -> String

Return the text displayed in the TextInput

Source

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

Set the text displayed in the TextInput

Source

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

Set the text in the current control, converting unix-style newlines in the input to “\r\n”

Source

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

Append text to the current control

Source

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

Append text to the current control followed by “\r\n”

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 TextBox

Source§

fn default() -> TextBox

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

impl Drop for TextBox

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 Eq for TextBox

Source§

impl From<&TextBox> for ControlHandle

Source§

fn from(control: &TextBox) -> Self

Converts to this type from the input type.
Source§

impl From<&mut TextBox> for ControlHandle

Source§

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

Converts to this type from the input type.
Source§

impl PartialEq for TextBox

Source§

fn eq(&self, other: &TextBox) -> 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 TextBox

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<TextBox> for ControlHandle

Source§

fn eq(&self, other: &TextBox) -> 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 StructuralPartialEq for TextBox

Auto Trait Implementations§

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.