pub struct TextBox {Show 19 fields
pub widget: Widget,
pub caret_position: InheritableVariable<Position>,
pub caret_visible: InheritableVariable<bool>,
pub blink_timer: InheritableVariable<f32>,
pub blink_interval: InheritableVariable<f32>,
pub formatted_text: RefCell<FormattedText>,
pub selection_range: InheritableVariable<Option<SelectionRange>>,
pub selecting: bool,
pub before_click_position: Position,
pub has_focus: bool,
pub caret_brush: InheritableVariable<Brush>,
pub selection_brush: InheritableVariable<Brush>,
pub filter: Option<Arc<Mutex<RawMutex, dyn FnMut(char) -> bool + Send>>>,
pub commit_mode: InheritableVariable<TextCommitMode>,
pub multiline: InheritableVariable<bool>,
pub editable: InheritableVariable<bool>,
pub view_position: InheritableVariable<Matrix<f32, Const<2>, Const<1>, ArrayStorage<f32, 2, 1>>>,
pub skip_chars: InheritableVariable<Vec<char>>,
pub recent: Vec<char>,
}
Expand description
TextBox is a text widget that allows you to edit text and create specialized input fields. It has various options like word wrapping, text alignment, and so on.
§How to create
An instance of the TextBox widget could be created like so:
fn create_text_box(ui: &mut UserInterface, text: &str) -> Handle<UiNode> {
TextBoxBuilder::new(WidgetBuilder::new())
.with_text(text)
.build(&mut ui.build_ctx())
}
§Text alignment and word wrapping
There are various text alignment options for both vertical and horizontal axes. Typical alignment values are:
HorizontalAlignment::Left
, HorizontalAlignment::Center
, HorizontalAlignment::Right
for horizontal axis,
and VerticalAlignment::Top
, VerticalAlignment::Center
, VerticalAlignment::Bottom
for vertical axis.
An instance of centered text could be created like so:
fn create_centered_text(ui: &mut UserInterface, text: &str) -> Handle<UiNode> {
TextBoxBuilder::new(WidgetBuilder::new())
.with_horizontal_text_alignment(HorizontalAlignment::Center)
.with_vertical_text_alignment(VerticalAlignment::Center)
.with_text(text)
.build(&mut ui.build_ctx())
}
Long text is usually needs to wrap on available bounds, there are three possible options for word wrapping:
WrapMode::NoWrap
, WrapMode::Letter
, WrapMode::Word
. An instance of text with word-based wrapping could be
created like so:
fn create_text_with_word_wrap(ui: &mut UserInterface, text: &str) -> Handle<UiNode> {
TextBoxBuilder::new(WidgetBuilder::new())
.with_wrap(WrapMode::Word)
.with_text(text)
.build(&mut ui.build_ctx())
}
§Fonts and colors
To set a color of the text just use WidgetBuilder::with_foreground
while building the text instance:
fn create_text(ui: &mut UserInterface, text: &str) -> Handle<UiNode> {
// vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
TextBoxBuilder::new(WidgetBuilder::new().with_foreground(Brush::Solid(Color::RED).into()))
.with_text(text)
.build(&mut ui.build_ctx())
}
By default, text is created with default font, however it is possible to set any custom font:
fn create_text(ui: &mut UserInterface, resource_manager: &ResourceManager, text: &str) -> Handle<UiNode> {
TextBoxBuilder::new(WidgetBuilder::new())
.with_font(resource_manager.request::<Font>("path/to/your/font.ttf"))
.with_text(text)
.with_font_size(20.0f32.into())
.build(&mut ui.build_ctx())
}
Please refer to FontResource
to learn more about fonts.
§Font size
Use TextBoxBuilder::with_font_size
or send TextMessage::font_size
to your TextBox widget instance
to set the font size of it.
§Messages
TextBox widget accepts the following list of messages:
TextBoxMessage::SelectionBrush
- change the brush that is used to highlight selection.TextBoxMessage::CaretBrush
- changes the brush of the caret (small blinking vertical line).TextBoxMessage::TextCommitMode
- changes the text commit mode.TextBoxMessage::Multiline
- makes the TextBox either multiline (true
) or single line (false
)TextBoxMessage::Editable
- enables or disables editing of the text.
Important: Please keep in mind, that TextBox widget also accepts TextMessage
s. An example of changing text at
runtime could be something like this:
fn request_change_text(ui: &UserInterface, text_box_widget_handle: Handle<UiNode>, text: &str) {
ui.send_message(TextMessage::text(
text_box_widget_handle,
MessageDirection::ToWidget,
text.to_owned(),
))
}
Please keep in mind, that like any other situation when you “changing” something via messages, you should remember
that the change is not immediate. The change will be applied on ui.poll_message(..)
call somewhere in your
code.
§Shortcuts
There are number of default shortcuts that can be used to speed up text editing:
Ctrl+A
- select allCtrl+C
- copy selected textCtrl+V
- paste text from clipboardCtrl+Home
- move caret to the beginning of the textCtrl+End
- move caret to the beginning of the textShift+Home
- select everything from current caret position until the beginning of current lineShift+End
- select everything from current caret position until the end of current lineArrows
- move caret accordinglyDelete
- deletes next characterBackspace
- deletes previous characterEnter
- new line (if multiline mode is set) orcommit
message
§Multiline Text Box
By default, text box will not add new line character to the text if you press Enter
on keyboard. To enable this
functionality use TextBoxBuilder::with_multiline
§Read-only Mode
You can enable or disable content editing by using read-only mode. Use TextBoxBuilder::with_editable
at build stage.
§Mask Character
You can specify replacement character for every other characters, this is useful option for password fields. Use
TextBoxBuilder::with_mask_char
at build stage. For example, you can set replacement character to asterisk *
using
.with_mask_char(Some('*'))
§Text Commit Mode
In many situations you don’t need the text box to send new text
message every new character, you either want this
message if Enter
key is pressed or TextBox has lost keyboard focus (or both). There is TextBoxBuilder::with_text_commit_mode
on builder specifically for that purpose. Use one of the following modes:
TextCommitMode::Immediate
- text box will immediately sendTextMessage::Text
message after any change.TextCommitMode::LostFocus
- text box will sendTextMessage::Text
message only when it loses focus.TextCommitMode::LostFocusPlusEnter
- text box will sendTextMessage::Text
message when it loses focus or if Enter key was pressed. This is default behavior. In case of multiline text box hitting Enter key won’t commit text!
§Filtering
It is possible specify custom input filter, it can be useful if you’re creating special input fields like numerical or phone number. A filter can be specified at build stage like so:
fn create_text_box(ui: &mut UserInterface) -> Handle<UiNode> {
TextBoxBuilder::new(WidgetBuilder::new())
// Specify a filter that will pass only digits.
.with_filter(Arc::new(Mutex::new(|c: char| c.is_ascii_digit())))
.build(&mut ui.build_ctx())
}
§Style
You can change brush of caret by using TextBoxBuilder::with_caret_brush
and also selection brush by using
TextBoxBuilder::with_selection_brush
, it could be useful if you don’t like default colors.
Fields§
§widget: Widget
Base widget of the text box.
caret_position: InheritableVariable<Position>
Current position of the caret in the text box.
caret_visible: InheritableVariable<bool>
Whether the caret is visible or not.
blink_timer: InheritableVariable<f32>
Internal blinking timer.
blink_interval: InheritableVariable<f32>
Blinking interval in seconds.
formatted_text: RefCell<FormattedText>
Formatted text that stores actual text and performs its layout. See FormattedText
docs for more info.
selection_range: InheritableVariable<Option<SelectionRange>>
Current selection range.
selecting: bool
true
if the text box is in selection mode.
before_click_position: Position
Stores the location of the caret before it was moved by mouse click.
has_focus: bool
true
if the text box is focused.
caret_brush: InheritableVariable<Brush>
Current caret brush of the text box.
selection_brush: InheritableVariable<Brush>
Current selection brush of the text box.
filter: Option<Arc<Mutex<RawMutex, dyn FnMut(char) -> bool + Send>>>
Current character filter of the text box.
commit_mode: InheritableVariable<TextCommitMode>
Current text commit mode of the text box.
multiline: InheritableVariable<bool>
true
if the the multiline mode is active.
editable: InheritableVariable<bool>
true
if the text box is editable.
view_position: InheritableVariable<Matrix<f32, Const<2>, Const<1>, ArrayStorage<f32, 2, 1>>>
Position of the local “camera” (viewing rectangle) of the text box.
skip_chars: InheritableVariable<Vec<char>>
A list of custom characters that will be treated as whitespace.
recent: Vec<char>
Stored copy of most recent commit, when commit_mode
is TextCommitMode::Changed.
Implementations§
Source§impl TextBox
impl TextBox
pub const WIDGET: &'static str = "widget"
pub const CARET_POSITION: &'static str = "caret_position"
pub const CARET_VISIBLE: &'static str = "caret_visible"
pub const BLINK_TIMER: &'static str = "blink_timer"
pub const BLINK_INTERVAL: &'static str = "blink_interval"
pub const FORMATTED_TEXT: &'static str = "formatted_text"
pub const SELECTION_RANGE: &'static str = "selection_range"
pub const SELECTING: &'static str = "selecting"
pub const BEFORE_CLICK_POSITION: &'static str = "before_click_position"
pub const HAS_FOCUS: &'static str = "has_focus"
pub const CARET_BRUSH: &'static str = "caret_brush"
pub const SELECTION_BRUSH: &'static str = "selection_brush"
pub const COMMIT_MODE: &'static str = "commit_mode"
pub const MULTILINE: &'static str = "multiline"
pub const EDITABLE: &'static str = "editable"
pub const VIEW_POSITION: &'static str = "view_position"
pub const SKIP_CHARS: &'static str = "skip_chars"
Source§impl TextBox
impl TextBox
Sourcepub fn position_to_char_index_unclamped(
&self,
position: Position,
) -> Option<usize>
pub fn position_to_char_index_unclamped( &self, position: Position, ) -> Option<usize>
Maps input Position
to a linear position in character array.
The index returned is the index of the character after the position, which may be
out-of-bounds if thee position is at the end of the text.
You should check the index before trying to use it to fetch data from inner array of characters.
Sourcepub fn position_to_char_index_clamped(
&self,
position: Position,
) -> Option<usize>
pub fn position_to_char_index_clamped( &self, position: Position, ) -> Option<usize>
Maps input Position
to a linear position in character array.
The index returned is usually the index of the character after the position,
but if the position is at the end of a line then return the index of the character before the position.
In other words, the last two positions of each line are mapped to the same character index.
Output index will always be valid for fetching, if the method returned Some(index)
.
The index however cannot be used for text insertion, because it cannot point to a “place after last char”.
Sourcepub fn char_index_to_position(&self, i: usize) -> Option<Position>
pub fn char_index_to_position(&self, i: usize) -> Option<Position>
Maps linear character index (as in string) to its actual location in the text.
Sourcepub fn end_position(&self) -> Position
pub fn end_position(&self) -> Position
Returns end position of the text.
Sourcepub fn find_next_word(&self, from: Position) -> Position
pub fn find_next_word(&self, from: Position) -> Position
Returns a position of a next word after the caret in the text.
Sourcepub fn find_prev_word(&self, from: Position) -> Position
pub fn find_prev_word(&self, from: Position) -> Position
Returns a position of a next word before the caret in the text.
Sourcepub fn get_text_len(&self) -> usize
pub fn get_text_len(&self) -> usize
Returns current text length in characters.
Sourcepub fn caret_local_position(
&self,
) -> Matrix<f32, Const<2>, Const<1>, ArrayStorage<f32, 2, 1>>
pub fn caret_local_position( &self, ) -> Matrix<f32, Const<2>, Const<1>, ArrayStorage<f32, 2, 1>>
Returns current position the caret in the local coordinates.
Sourcepub fn is_valid_position(&self, position: Position) -> bool
pub fn is_valid_position(&self, position: Position) -> bool
Checks whether the input position is correct (in bounds) or not.
Sourcepub fn screen_pos_to_text_pos(
&self,
screen_point: Matrix<f32, Const<2>, Const<1>, ArrayStorage<f32, 2, 1>>,
) -> Option<Position>
pub fn screen_pos_to_text_pos( &self, screen_point: Matrix<f32, Const<2>, Const<1>, ArrayStorage<f32, 2, 1>>, ) -> Option<Position>
Tries to map screen space position to a position in the text.
Sourcepub fn vertical_alignment(&self) -> VerticalAlignment
pub fn vertical_alignment(&self) -> VerticalAlignment
Returns current vertical alignment of text box.
Sourcepub fn horizontal_alignment(&self) -> HorizontalAlignment
pub fn horizontal_alignment(&self) -> HorizontalAlignment
Returns current horizontal alignment of text box.
Methods from Deref<Target = Widget>§
pub const NAME: &'static str = "name"
pub const DESIRED_LOCAL_POSITION: &'static str = "desired_local_position"
pub const WIDTH: &'static str = "width"
pub const HEIGHT: &'static str = "height"
pub const MIN_SIZE: &'static str = "min_size"
pub const MAX_SIZE: &'static str = "max_size"
pub const BACKGROUND: &'static str = "background"
pub const FOREGROUND: &'static str = "foreground"
pub const ROW: &'static str = "row"
pub const COLUMN: &'static str = "column"
pub const VERTICAL_ALIGNMENT: &'static str = "vertical_alignment"
pub const HORIZONTAL_ALIGNMENT: &'static str = "horizontal_alignment"
pub const MARGIN: &'static str = "margin"
pub const VISIBILITY: &'static str = "visibility"
pub const HIT_TEST_VISIBILITY: &'static str = "hit_test_visibility"
pub const Z_INDEX: &'static str = "z_index"
pub const ALLOW_DRAG: &'static str = "allow_drag"
pub const ALLOW_DROP: &'static str = "allow_drop"
pub const DRAW_ON_TOP: &'static str = "draw_on_top"
pub const ENABLED: &'static str = "enabled"
pub const CURSOR: &'static str = "cursor"
pub const OPACITY: &'static str = "opacity"
pub const TOOLTIP: &'static str = "tooltip"
pub const TOOLTIP_TIME: &'static str = "tooltip_time"
pub const CONTEXT_MENU: &'static str = "context_menu"
pub const CLIP_TO_BOUNDS: &'static str = "clip_to_bounds"
pub const PREVIEW_MESSAGES: &'static str = "preview_messages"
pub const HANDLE_OS_EVENTS: &'static str = "handle_os_events"
pub const TAB_INDEX: &'static str = "tab_index"
pub const TAB_STOP: &'static str = "tab_stop"
pub const NEED_UPDATE: &'static str = "need_update"
pub const IGNORE_LAYOUT_ROUNDING: &'static str = "ignore_layout_rounding"
pub const ACCEPTS_INPUT: &'static str = "accepts_input"
pub const ID: &'static str = "id"
pub const RESOURCE: &'static str = "resource"
Sourcepub fn actual_local_size(
&self,
) -> Matrix<f32, Const<2>, Const<1>, ArrayStorage<f32, 2, 1>>
pub fn actual_local_size( &self, ) -> Matrix<f32, Const<2>, Const<1>, ArrayStorage<f32, 2, 1>>
Returns the actual size of the widget after the full layout cycle.
Sourcepub fn actual_initial_size(
&self,
) -> Matrix<f32, Const<2>, Const<1>, ArrayStorage<f32, 2, 1>>
pub fn actual_initial_size( &self, ) -> Matrix<f32, Const<2>, Const<1>, ArrayStorage<f32, 2, 1>>
Returns size of the widget without any layout or rendering transform applied.
Sourcepub fn actual_global_size(
&self,
) -> Matrix<f32, Const<2>, Const<1>, ArrayStorage<f32, 2, 1>>
pub fn actual_global_size( &self, ) -> Matrix<f32, Const<2>, Const<1>, ArrayStorage<f32, 2, 1>>
Returns the actual global size of the widget after the full layout cycle.
Sourcepub fn set_min_size(
&mut self,
value: Matrix<f32, Const<2>, Const<1>, ArrayStorage<f32, 2, 1>>,
) -> &mut Widget
pub fn set_min_size( &mut self, value: Matrix<f32, Const<2>, Const<1>, ArrayStorage<f32, 2, 1>>, ) -> &mut Widget
Sets the new minimum size of the widget.
Sourcepub fn set_min_width(&mut self, value: f32) -> &mut Widget
pub fn set_min_width(&mut self, value: f32) -> &mut Widget
Sets the new minimum width of the widget.
Sourcepub fn set_min_height(&mut self, value: f32) -> &mut Widget
pub fn set_min_height(&mut self, value: f32) -> &mut Widget
Sets the new minimum height of the widget.
Sourcepub fn min_size(
&self,
) -> Matrix<f32, Const<2>, Const<1>, ArrayStorage<f32, 2, 1>>
pub fn min_size( &self, ) -> Matrix<f32, Const<2>, Const<1>, ArrayStorage<f32, 2, 1>>
Sets the new minimum size of the widget.
Sourcepub fn min_height(&self) -> f32
pub fn min_height(&self) -> f32
Returns the minimum height of the widget.
Sourcepub fn is_drag_allowed(&self) -> bool
pub fn is_drag_allowed(&self) -> bool
Return true
if the dragging of the widget is allowed, false
- otherwise.
Sourcepub fn is_drop_allowed(&self) -> bool
pub fn is_drop_allowed(&self) -> bool
Return true
if the dropping of other widgets is allowed on this widget, false
- otherwise.
Sourcepub fn screen_to_local(
&self,
point: Matrix<f32, Const<2>, Const<1>, ArrayStorage<f32, 2, 1>>,
) -> Matrix<f32, Const<2>, Const<1>, ArrayStorage<f32, 2, 1>>
pub fn screen_to_local( &self, point: Matrix<f32, Const<2>, Const<1>, ArrayStorage<f32, 2, 1>>, ) -> Matrix<f32, Const<2>, Const<1>, ArrayStorage<f32, 2, 1>>
Maps the given point from screen to local widget’s coordinates. Could be used to transform mouse cursor position (which is in screen space) to local widget coordinates.
Sourcepub fn invalidate_layout(&self)
pub fn invalidate_layout(&self)
Invalidates layout of the widget. WARNING: Do not use this method, unless you understand what you’re doing, it will cause new layout pass for this widget which could be quite heavy and doing so on every frame for multiple widgets will cause severe performance issues.
Sourcepub fn invalidate_measure(&self)
pub fn invalidate_measure(&self)
Invalidates measurement results of the widget. WARNING: Do not use this method, unless you understand what you’re doing, it will cause new measurement pass for this widget which could be quite heavy and doing so on every frame for multiple widgets will cause severe performance issues.
Sourcepub fn invalidate_arrange(&self)
pub fn invalidate_arrange(&self)
Invalidates arrangement results of the widget. WARNING: Do not use this method, unless you understand what you’re doing, it will cause new arrangement pass for this widget which could be quite heavy and doing so on every frame for multiple widgets will cause severe performance issues.
Sourcepub fn is_hit_test_visible(&self) -> bool
pub fn is_hit_test_visible(&self) -> bool
Returns true
if the widget is able to participate in hit testing, false
- otherwise.
Sourcepub fn set_max_size(
&mut self,
value: Matrix<f32, Const<2>, Const<1>, ArrayStorage<f32, 2, 1>>,
) -> &mut Widget
pub fn set_max_size( &mut self, value: Matrix<f32, Const<2>, Const<1>, ArrayStorage<f32, 2, 1>>, ) -> &mut Widget
Sets the new maximum size of the widget.
Sourcepub fn max_size(
&self,
) -> Matrix<f32, Const<2>, Const<1>, ArrayStorage<f32, 2, 1>>
pub fn max_size( &self, ) -> Matrix<f32, Const<2>, Const<1>, ArrayStorage<f32, 2, 1>>
Returns current maximum size of the widget.
Sourcepub fn max_height(&self) -> f32
pub fn max_height(&self) -> f32
Return maximum height of the widget.
Sourcepub fn set_z_index(&mut self, z_index: usize) -> &mut Widget
pub fn set_z_index(&mut self, z_index: usize) -> &mut Widget
Sets new Z index for the widget. Z index defines the sorting (stable) index which will be used to “arrange” widgets in the correct order.
Sourcepub fn set_background(&mut self, brush: Brush) -> &mut Widget
pub fn set_background(&mut self, brush: Brush) -> &mut Widget
Sets the new background of the widget.
Sourcepub fn background(&self) -> Brush
pub fn background(&self) -> Brush
Returns current background of the widget.
Sourcepub fn set_foreground(&mut self, brush: Brush) -> &mut Widget
pub fn set_foreground(&mut self, brush: Brush) -> &mut Widget
Sets new foreground of the widget.
Sourcepub fn foreground(&self) -> Brush
pub fn foreground(&self) -> Brush
Returns current foreground of the widget.
Sourcepub fn is_draw_on_top(&self) -> bool
pub fn is_draw_on_top(&self) -> bool
Return true
if the widget is set to be drawn on top of every other, normally drawn, widgets, false
- otherwise.
Sourcepub fn set_height(&mut self, height: f32) -> &mut Widget
pub fn set_height(&mut self, height: f32) -> &mut Widget
Sets new height of the widget.
Sourcepub fn set_desired_local_position(
&mut self,
pos: Matrix<f32, Const<2>, Const<1>, ArrayStorage<f32, 2, 1>>,
) -> &mut Widget
pub fn set_desired_local_position( &mut self, pos: Matrix<f32, Const<2>, Const<1>, ArrayStorage<f32, 2, 1>>, ) -> &mut Widget
Sets the desired local position of the widget.
Sourcepub fn screen_position(
&self,
) -> Matrix<f32, Const<2>, Const<1>, ArrayStorage<f32, 2, 1>>
pub fn screen_position( &self, ) -> Matrix<f32, Const<2>, Const<1>, ArrayStorage<f32, 2, 1>>
Returns current screen-space position of the widget.
Sourcepub fn children(&self) -> &[Handle<UiNode>]
pub fn children(&self) -> &[Handle<UiNode>]
Returns a reference to the slice with the children widgets of this widget.
Sourcepub fn set_column(&mut self, column: usize) -> &mut Widget
pub fn set_column(&mut self, column: usize) -> &mut Widget
Sets new column of the widget. Columns are used only by crate::grid::Grid
widget.
Sourcepub fn column(&self) -> usize
pub fn column(&self) -> usize
Returns current column of the widget. Columns are used only by crate::grid::Grid
widget.
Sourcepub fn set_row(&mut self, row: usize) -> &mut Widget
pub fn set_row(&mut self, row: usize) -> &mut Widget
Sets new row of the widget. Rows are used only by crate::grid::Grid
widget.
Sourcepub fn row(&self) -> usize
pub fn row(&self) -> usize
Returns current row of the widget. Rows are used only by crate::grid::Grid
widget.
Sourcepub fn desired_size(
&self,
) -> Matrix<f32, Const<2>, Const<1>, ArrayStorage<f32, 2, 1>>
pub fn desired_size( &self, ) -> Matrix<f32, Const<2>, Const<1>, ArrayStorage<f32, 2, 1>>
Returns the desired size of the widget.
Sourcepub fn desired_local_position(
&self,
) -> Matrix<f32, Const<2>, Const<1>, ArrayStorage<f32, 2, 1>>
pub fn desired_local_position( &self, ) -> Matrix<f32, Const<2>, Const<1>, ArrayStorage<f32, 2, 1>>
Returns current desired local position of the widget.
Sourcepub fn screen_bounds(&self) -> Rect<f32>
pub fn screen_bounds(&self) -> Rect<f32>
Returns current screen-space bounds of the widget.
Sourcepub fn bounding_rect(&self) -> Rect<f32>
pub fn bounding_rect(&self) -> Rect<f32>
Returns local-space bounding rect of the widget.
Sourcepub fn visual_transform(
&self,
) -> &Matrix<f32, Const<3>, Const<3>, ArrayStorage<f32, 3, 3>>
pub fn visual_transform( &self, ) -> &Matrix<f32, Const<3>, Const<3>, ArrayStorage<f32, 3, 3>>
Returns current visual transform of the widget.
Sourcepub fn visual_scaling(
&self,
) -> Matrix<f32, Const<2>, Const<1>, ArrayStorage<f32, 2, 1>>
pub fn visual_scaling( &self, ) -> Matrix<f32, Const<2>, Const<1>, ArrayStorage<f32, 2, 1>>
Returns scaling along both axes.
Sourcepub fn visual_max_scaling(&self) -> f32
pub fn visual_max_scaling(&self) -> f32
Returns max uniform scaling of both axes.
Sourcepub fn render_transform(
&self,
) -> &Matrix<f32, Const<3>, Const<3>, ArrayStorage<f32, 3, 3>>
pub fn render_transform( &self, ) -> &Matrix<f32, Const<3>, Const<3>, ArrayStorage<f32, 3, 3>>
Returns current render transform of the widget.
Sourcepub fn layout_transform(
&self,
) -> &Matrix<f32, Const<3>, Const<3>, ArrayStorage<f32, 3, 3>>
pub fn layout_transform( &self, ) -> &Matrix<f32, Const<3>, Const<3>, ArrayStorage<f32, 3, 3>>
Returns current layout transform of the widget.
Sourcepub fn has_descendant(
&self,
node_handle: Handle<UiNode>,
ui: &UserInterface,
) -> bool
pub fn has_descendant( &self, node_handle: Handle<UiNode>, ui: &UserInterface, ) -> bool
Returns true
, if the widget has a descendant widget with the specified handle, false
- otherwise.
Sourcepub fn find_by_criteria_up<Func>(
&self,
ui: &UserInterface,
func: Func,
) -> Handle<UiNode>
pub fn find_by_criteria_up<Func>( &self, ui: &UserInterface, func: Func, ) -> Handle<UiNode>
Searches a node up on tree starting from the given root that matches a criteria defined by the given func.
Sourcepub fn handle_routed_message(
&mut self,
ui: &mut UserInterface,
msg: &mut UiMessage,
)
pub fn handle_routed_message( &mut self, ui: &mut UserInterface, msg: &mut UiMessage, )
Handles incoming WidgetMessage
s. This method must be called in crate::control::Control::handle_routed_message
of any derived widgets!
Sourcepub fn set_vertical_alignment(
&mut self,
vertical_alignment: VerticalAlignment,
) -> &mut Widget
pub fn set_vertical_alignment( &mut self, vertical_alignment: VerticalAlignment, ) -> &mut Widget
Sets new vertical alignment of the widget.
Sourcepub fn vertical_alignment(&self) -> VerticalAlignment
pub fn vertical_alignment(&self) -> VerticalAlignment
Returns current vertical alignment of the widget.
Sourcepub fn set_horizontal_alignment(
&mut self,
horizontal_alignment: HorizontalAlignment,
) -> &mut Widget
pub fn set_horizontal_alignment( &mut self, horizontal_alignment: HorizontalAlignment, ) -> &mut Widget
Sets new horizontal alignment of the widget.
Sourcepub fn horizontal_alignment(&self) -> HorizontalAlignment
pub fn horizontal_alignment(&self) -> HorizontalAlignment
Returns current horizontal alignment of the widget.
Sourcepub fn set_margin(&mut self, margin: Thickness) -> &mut Widget
pub fn set_margin(&mut self, margin: Thickness) -> &mut Widget
Sets new margin of the widget.
Sourcepub fn measure_override(
&self,
ui: &UserInterface,
available_size: Matrix<f32, Const<2>, Const<1>, ArrayStorage<f32, 2, 1>>,
) -> Matrix<f32, Const<2>, Const<1>, ArrayStorage<f32, 2, 1>>
pub fn measure_override( &self, ui: &UserInterface, available_size: Matrix<f32, Const<2>, Const<1>, ArrayStorage<f32, 2, 1>>, ) -> Matrix<f32, Const<2>, Const<1>, ArrayStorage<f32, 2, 1>>
Performs standard measurement of children nodes. It provides available size as a constraint and returns the maximum desired size across all children. As a result, this widget will have this size as its desired size to fit all the children nodes.
Sourcepub fn arrange_override(
&self,
ui: &UserInterface,
final_size: Matrix<f32, Const<2>, Const<1>, ArrayStorage<f32, 2, 1>>,
) -> Matrix<f32, Const<2>, Const<1>, ArrayStorage<f32, 2, 1>>
pub fn arrange_override( &self, ui: &UserInterface, final_size: Matrix<f32, Const<2>, Const<1>, ArrayStorage<f32, 2, 1>>, ) -> Matrix<f32, Const<2>, Const<1>, ArrayStorage<f32, 2, 1>>
Performs standard arrangement of the children nodes of the widget. It uses input final size to make a final bounding rectangle to arrange children. As a result, all the children nodes will be located at the top-left corner of this widget and stretched to fit its bounds.
Sourcepub fn is_arrange_valid(&self) -> bool
pub fn is_arrange_valid(&self) -> bool
Returns true
if the current results of arrangement of the widget are valid, false
- otherwise.
Sourcepub fn is_measure_valid(&self) -> bool
pub fn is_measure_valid(&self) -> bool
Returns true
if the current results of measurement of the widget are valid, false
- otherwise.
Sourcepub fn actual_local_position(
&self,
) -> Matrix<f32, Const<2>, Const<1>, ArrayStorage<f32, 2, 1>>
pub fn actual_local_position( &self, ) -> Matrix<f32, Const<2>, Const<1>, ArrayStorage<f32, 2, 1>>
Returns current actual local position of the widget. It is valid only after layout pass!
Sourcepub fn center(&self) -> Matrix<f32, Const<2>, Const<1>, ArrayStorage<f32, 2, 1>>
pub fn center(&self) -> Matrix<f32, Const<2>, Const<1>, ArrayStorage<f32, 2, 1>>
Returns center point of the widget. It is valid only after layout pass!
Sourcepub fn is_globally_visible(&self) -> bool
pub fn is_globally_visible(&self) -> bool
Returns true
of the widget is globally visible, which means that all its parents are visible as well
as this widget. It is valid only after the first update of the layout, otherwise if will be always false.
Sourcepub fn set_visibility(&mut self, visibility: bool) -> &mut Widget
pub fn set_visibility(&mut self, visibility: bool) -> &mut Widget
Sets new visibility of the widget.
Sourcepub fn request_update_visibility(&self)
pub fn request_update_visibility(&self)
Requests (via event queue, so the request is deferred) the update of the visibility of the widget.
Sourcepub fn visibility(&self) -> bool
pub fn visibility(&self) -> bool
Returns current visibility of the widget.
Sourcepub fn set_enabled(&mut self, enabled: bool) -> &mut Widget
pub fn set_enabled(&mut self, enabled: bool) -> &mut Widget
Enables or disables the widget. Disabled widgets does not interact with user and usually greyed out.
Sourcepub fn set_cursor(&mut self, cursor: Option<CursorIcon>)
pub fn set_cursor(&mut self, cursor: Option<CursorIcon>)
Sets new cursor of the widget.
Sourcepub fn cursor(&self) -> Option<CursorIcon>
pub fn cursor(&self) -> Option<CursorIcon>
Returns current cursor of the widget.
Sourcepub fn user_data_cloned<T>(&self) -> Option<T>where
T: Clone + 'static,
pub fn user_data_cloned<T>(&self) -> Option<T>where
T: Clone + 'static,
Tries to fetch user-defined data of the specified type T
.
Sourcepub fn clip_bounds(&self) -> Rect<f32>
pub fn clip_bounds(&self) -> Rect<f32>
Returns current clipping bounds of the widget. It is valid only after at least one layout pass.
Sourcepub fn set_opacity(&mut self, opacity: Option<f32>) -> &mut Widget
pub fn set_opacity(&mut self, opacity: Option<f32>) -> &mut Widget
Set new opacity of the widget. Opacity should be in [0.0..1.0]
range.
Sourcepub fn tooltip(&self) -> Option<RcUiNodeHandle>
pub fn tooltip(&self) -> Option<RcUiNodeHandle>
Returns current tooltip handle of the widget.
Sourcepub fn set_tooltip(&mut self, tooltip: Option<RcUiNodeHandle>) -> &mut Widget
pub fn set_tooltip(&mut self, tooltip: Option<RcUiNodeHandle>) -> &mut Widget
Sets new tooltip handle of the widget (if any).
Sourcepub fn tooltip_time(&self) -> f32
pub fn tooltip_time(&self) -> f32
Returns maximum available time to show the tooltip after the cursor was moved away from the widget.
Sourcepub fn set_tooltip_time(&mut self, tooltip_time: f32) -> &mut Widget
pub fn set_tooltip_time(&mut self, tooltip_time: f32) -> &mut Widget
Set the maximum available time to show the tooltip after the cursor was moved away from the widget.
Returns current context menu of the widget.
The context menu receives PopupMessage
s for being displayed, and so should support those.
Trait Implementations§
Source§impl ComponentProvider for TextBox
impl ComponentProvider for TextBox
Source§impl ConstructorProvider<UiNode, UserInterface> for TextBox
impl ConstructorProvider<UiNode, UserInterface> for TextBox
Source§impl Control for TextBox
impl Control for TextBox
Source§fn measure_override(
&self,
_: &UserInterface,
available_size: Matrix<f32, Const<2>, Const<1>, ArrayStorage<f32, 2, 1>>,
) -> Matrix<f32, Const<2>, Const<1>, ArrayStorage<f32, 2, 1>>
fn measure_override( &self, _: &UserInterface, available_size: Matrix<f32, Const<2>, Const<1>, ArrayStorage<f32, 2, 1>>, ) -> Matrix<f32, Const<2>, Const<1>, ArrayStorage<f32, 2, 1>>
fn on_visual_transform_changed(&self)
Source§fn draw(&self, drawing_context: &mut DrawingContext)
fn draw(&self, drawing_context: &mut DrawingContext)
Source§fn update(&mut self, dt: f32, _ui: &mut UserInterface)
fn update(&mut self, dt: f32, _ui: &mut UserInterface)
Source§fn handle_routed_message(
&mut self,
ui: &mut UserInterface,
message: &mut UiMessage,
)
fn handle_routed_message( &mut self, ui: &mut UserInterface, message: &mut UiMessage, )
Source§fn on_remove(&self, sender: &Sender<UiMessage>)
fn on_remove(&self, sender: &Sender<UiMessage>)
crate::widget::WidgetMessage::remove
.Source§fn arrange_override(
&self,
ui: &UserInterface,
final_size: Matrix<f32, Const<2>, Const<1>, ArrayStorage<f32, 2, 1>>,
) -> Matrix<f32, Const<2>, Const<1>, ArrayStorage<f32, 2, 1>>
fn arrange_override( &self, ui: &UserInterface, final_size: Matrix<f32, Const<2>, Const<1>, ArrayStorage<f32, 2, 1>>, ) -> Matrix<f32, Const<2>, Const<1>, ArrayStorage<f32, 2, 1>>
Source§fn post_draw(&self, drawing_context: &mut DrawingContext)
fn post_draw(&self, drawing_context: &mut DrawingContext)
Self::draw
, but it runs after all descendant widgets are rendered.Source§fn preview_message(&self, ui: &UserInterface, message: &mut UiMessage)
fn preview_message(&self, ui: &UserInterface, message: &mut UiMessage)
preview_message
used in a dropdown list:
dropdown list has two separate parts - a field with selected value and a popup for all possible
options. Visual parent of the popup in this case is the root canvas, but logical parent is the
dropdown list. Because of this fact, the field won’t receive any messages from popup, to solve
this we use preview_message
. This method is much more restrictive - it does not allow you to
modify a node and ui, you can either request changes by sending a message or use internal
mutability (Cell
, RefCell
, etc). Read moreSource§fn handle_os_event(
&mut self,
self_handle: Handle<UiNode>,
ui: &mut UserInterface,
event: &OsEvent,
)
fn handle_os_event( &mut self, self_handle: Handle<UiNode>, ui: &mut UserInterface, event: &OsEvent, )
handle_message
because os events
are not dispatched - they’ll be passed to this method in any case. Read moreSource§impl Reflect for TextBoxwhere
TextBox: 'static,
Widget: Reflect,
InheritableVariable<Position>: Reflect,
InheritableVariable<bool>: Reflect,
InheritableVariable<f32>: Reflect,
RefCell<FormattedText>: Reflect,
InheritableVariable<Option<SelectionRange>>: Reflect,
bool: Reflect,
Position: Reflect,
InheritableVariable<Brush>: Reflect,
InheritableVariable<TextCommitMode>: Reflect,
InheritableVariable<Matrix<f32, Const<2>, Const<1>, ArrayStorage<f32, 2, 1>>>: Reflect,
InheritableVariable<Vec<char>>: Reflect,
impl Reflect for TextBoxwhere
TextBox: 'static,
Widget: Reflect,
InheritableVariable<Position>: Reflect,
InheritableVariable<bool>: Reflect,
InheritableVariable<f32>: Reflect,
RefCell<FormattedText>: Reflect,
InheritableVariable<Option<SelectionRange>>: Reflect,
bool: Reflect,
Position: Reflect,
InheritableVariable<Brush>: Reflect,
InheritableVariable<TextCommitMode>: Reflect,
InheritableVariable<Matrix<f32, Const<2>, Const<1>, ArrayStorage<f32, 2, 1>>>: Reflect,
InheritableVariable<Vec<char>>: Reflect,
fn source_path() -> &'static str
fn type_name(&self) -> &'static str
fn doc(&self) -> &'static str
Source§fn assembly_name(&self) -> &'static str
fn assembly_name(&self) -> &'static str
#[derive(Reflect)]
) to ensure that this method will return correct assembly
name. In other words - there’s no guarantee, that any implementation other than proc-macro
will return a correct name of the assembly. Alternatively, you can use env!("CARGO_PKG_NAME")
as an implementation.Source§fn type_assembly_name() -> &'static str
fn type_assembly_name() -> &'static str
#[derive(Reflect)]
) to ensure that this method will return correct assembly
name. In other words - there’s no guarantee, that any implementation other than proc-macro
will return a correct name of the assembly. Alternatively, you can use env!("CARGO_PKG_NAME")
as an implementation.fn fields_info(&self, func: &mut dyn FnMut(&[FieldInfo<'_, '_>]))
fn into_any(self: Box<TextBox>) -> Box<dyn Any>
fn set( &mut self, value: Box<dyn Reflect>, ) -> Result<Box<dyn Reflect>, Box<dyn Reflect>>
fn as_any(&self, func: &mut dyn FnMut(&(dyn Any + 'static)))
fn as_any_mut(&mut self, func: &mut dyn FnMut(&mut (dyn Any + 'static)))
fn as_reflect(&self, func: &mut dyn FnMut(&(dyn Reflect + 'static)))
fn as_reflect_mut(&mut self, func: &mut dyn FnMut(&mut (dyn Reflect + 'static)))
fn fields(&self, func: &mut dyn FnMut(&[&(dyn Reflect + 'static)]))
fn fields_mut( &mut self, func: &mut dyn FnMut(&mut [&mut (dyn Reflect + 'static)]), )
fn field( &self, name: &str, func: &mut dyn FnMut(Option<&(dyn Reflect + 'static)>), )
fn field_mut( &mut self, name: &str, func: &mut dyn FnMut(Option<&mut (dyn Reflect + 'static)>), )
Source§fn set_field(
&mut self,
field: &str,
value: Box<dyn Reflect>,
func: &mut dyn FnMut(Result<Box<dyn Reflect>, Box<dyn Reflect>>),
)
fn set_field( &mut self, field: &str, value: Box<dyn Reflect>, func: &mut dyn FnMut(Result<Box<dyn Reflect>, Box<dyn Reflect>>), )
#[reflect(setter = ..)]
or falls back to
Reflect::field_mut
fn as_array(&self, func: &mut dyn FnMut(Option<&(dyn ReflectArray + 'static)>))
fn as_array_mut( &mut self, func: &mut dyn FnMut(Option<&mut (dyn ReflectArray + 'static)>), )
fn as_list(&self, func: &mut dyn FnMut(Option<&(dyn ReflectList + 'static)>))
fn as_list_mut( &mut self, func: &mut dyn FnMut(Option<&mut (dyn ReflectList + 'static)>), )
fn as_inheritable_variable( &self, func: &mut dyn FnMut(Option<&(dyn ReflectInheritableVariable + 'static)>), )
fn as_inheritable_variable_mut( &mut self, func: &mut dyn FnMut(Option<&mut (dyn ReflectInheritableVariable + 'static)>), )
fn as_hash_map( &self, func: &mut dyn FnMut(Option<&(dyn ReflectHashMap + 'static)>), )
fn as_hash_map_mut( &mut self, func: &mut dyn FnMut(Option<&mut (dyn ReflectHashMap + 'static)>), )
Source§impl Visit for TextBoxwhere
Widget: Visit,
InheritableVariable<Position>: Visit,
InheritableVariable<bool>: Visit,
InheritableVariable<f32>: Visit,
RefCell<FormattedText>: Visit,
InheritableVariable<Option<SelectionRange>>: Visit,
bool: Visit,
InheritableVariable<Brush>: Visit,
InheritableVariable<TextCommitMode>: Visit,
InheritableVariable<Matrix<f32, Const<2>, Const<1>, ArrayStorage<f32, 2, 1>>>: Visit,
InheritableVariable<Vec<char>>: Visit,
impl Visit for TextBoxwhere
Widget: Visit,
InheritableVariable<Position>: Visit,
InheritableVariable<bool>: Visit,
InheritableVariable<f32>: Visit,
RefCell<FormattedText>: Visit,
InheritableVariable<Option<SelectionRange>>: Visit,
bool: Visit,
InheritableVariable<Brush>: Visit,
InheritableVariable<TextCommitMode>: Visit,
InheritableVariable<Matrix<f32, Const<2>, Const<1>, ArrayStorage<f32, 2, 1>>>: Visit,
InheritableVariable<Vec<char>>: Visit,
Source§fn visit(&mut self, name: &str, visitor: &mut Visitor) -> Result<(), VisitError>
fn visit(&mut self, name: &str, visitor: &mut Visitor) -> Result<(), VisitError>
Auto Trait Implementations§
impl !Freeze for TextBox
impl !RefUnwindSafe for TextBox
impl Send for TextBox
impl !Sync for TextBox
impl Unpin for TextBox
impl !UnwindSafe for TextBox
Blanket Implementations§
Source§impl<T> AsyncTaskResult for T
impl<T> AsyncTaskResult for T
Source§impl<T> BaseControl for T
impl<T> BaseControl for T
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait>
(where Trait: Downcast
) to Box<dyn Any>
. Box<dyn Any>
can
then be further downcast
into Box<ConcreteType>
where ConcreteType
implements Trait
.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait>
(where Trait: Downcast
) to Rc<Any>
. Rc<Any>
can then be
further downcast
into Rc<ConcreteType>
where ConcreteType
implements Trait
.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &Any
’s vtable from &Trait
’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &mut Any
’s vtable from &mut Trait
’s.Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
Any
. Could be used to downcast a trait object
to a particular type.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
Any
. Could be used to downcast a trait object
to a particular type.fn into_any(self: Box<T>) -> Box<dyn Any>
Source§impl<T> FieldValue for Twhere
T: 'static,
impl<T> FieldValue for Twhere
T: 'static,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<R, P> ReadPrimitive<R> for P
impl<R, P> ReadPrimitive<R> for P
Source§fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
ReadEndian::read_from_little_endian()
.Source§impl<T> ReflectBase for Twhere
T: Reflect,
impl<T> ReflectBase for Twhere
T: Reflect,
fn as_any_raw(&self) -> &(dyn Any + 'static)
fn as_any_raw_mut(&mut self) -> &mut (dyn Any + 'static)
Source§impl<T> ResolvePath for Twhere
T: Reflect,
impl<T> ResolvePath for Twhere
T: Reflect,
fn resolve_path<'p>( &self, path: &'p str, func: &mut dyn FnMut(Result<&(dyn Reflect + 'static), ReflectPathError<'p>>), )
fn resolve_path_mut<'p>( &mut self, path: &'p str, func: &mut dyn FnMut(Result<&mut (dyn Reflect + 'static), ReflectPathError<'p>>), )
fn get_resolve_path<'p, T>(
&self,
path: &'p str,
func: &mut dyn FnMut(Result<&T, ReflectPathError<'p>>),
)where
T: Reflect,
fn get_resolve_path_mut<'p, T>(
&mut self,
path: &'p str,
func: &mut dyn FnMut(Result<&mut T, ReflectPathError<'p>>),
)where
T: Reflect,
Source§impl<T> ScriptMessagePayload for T
impl<T> ScriptMessagePayload for T
Source§fn as_any_ref(&self) -> &(dyn Any + 'static)
fn as_any_ref(&self) -> &(dyn Any + 'static)
self
as &dyn Any
Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
self
as &dyn Any
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self
from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self
is actually part of its subset T
(and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset
but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self
to the equivalent element of its superset.