[−][src]Struct orbtk_widgets::behaviors::TextBehavior
The TextBehavior widget shares the same logic of handling text input between tex-related widgets.
Attaching to a widget makes it able to handle text input like:
- input characters by keyboard
- select all text with Ctrl+A key combination
- delete selected text with Backspace or Delete
- move cursor by the left or right arrow keys or clicking with mouse
- delete characters by pressing the Backspace or the Delete key
- run on_activate() callback on pressing the Enter key
TextBehavior needs the following prerequisites to able to work:
-
a target: the
Entity
of the target widget -
and must inherit the following properties from its target:
- focused
- font
- font_size
- lost_focus_on_activation
- request_focus
- text
- text_selection
Example
use orbtk::prelude::* widget!(MyInput { // essential properties TextBehavior needs to inherit focused: bool, font: String, font_size: f64, lost_focus_on_activation: bool, request_focus: bool, text_selection: TextSelection }); impl Template for MyInput { fn template(self, id: Entity, ctx: &mut BuildContext) -> Self { // Cursor depends on a TextBlock let text_block = TextBlock::new() .text(id) .water_mark(id) .font(id) .font_size(id) .build(ctx); let cursor = Cursor::new() // use .0 because Entity wraps an u32 .text_block(text_block.0) .focused(id) .text_selection(id) .build(ctx); let text_behavior = TextBehavior::new() .cursor(cursor.0) .focused(id) .font(id) .font_size(id) .lost_focus_on_activation(id) .target(id.0) .request_focus(id) .text(id) .text_selection(id) .build(ctx); self.child(cursor) .child(text_behavior) }
Implementations
impl TextBehavior
[src]
pub fn get<'a>(ctx: WidgetContainer<'a>) -> TextBehaviorCtx<'a>
[src]
Gets a widget context that wraps the given widgets an provides access to the its properties.
impl TextBehavior
[src]
pub fn id(self, id: impl Into<String>) -> Self
[src]
Sets the id selector.
pub fn style(self, style: impl Into<String>) -> Self
[src]
Sets the style selector (replaces the old selector property).
pub fn position(self, position: impl IntoPropertySource<Point>) -> Self
[src]
Sets or shares the position of the widget. (Be careful the position could be adjusted by layouts).
pub fn constraint(self, constraint: impl IntoPropertySource<Constraint>) -> Self
[src]
Sets or shares the constraint property.
pub fn on_changed_filter(self, filter: impl IntoPropertySource<Filter>) -> Self
[src]
Sets or shares the filter for the on_changed property callback.
pub fn v_align(self, v_align: impl IntoPropertySource<Alignment>) -> Self
[src]
Sets or shares the vertical alignment property.
pub fn h_align(self, h_align: impl IntoPropertySource<Alignment>) -> Self
[src]
Sets or shares the horizontal alignment property.
pub fn vertical_alignment(
self,
vertical_alignment: impl IntoPropertySource<Alignment>
) -> Self
[src]
self,
vertical_alignment: impl IntoPropertySource<Alignment>
) -> Self
Use v_align instead
Sets or shares the vertical alignment property.
pub fn horizontal_alignment(
self,
horizontal_alignment: impl IntoPropertySource<Alignment>
) -> Self
[src]
self,
horizontal_alignment: impl IntoPropertySource<Alignment>
) -> Self
Use h_align instead
Sets or shares the horizontal alignment property.
pub fn visibility(self, visibility: impl IntoPropertySource<Visibility>) -> Self
[src]
Sets or shares the visibility property.
pub fn margin(self, margin: impl IntoPropertySource<Thickness>) -> Self
[src]
Sets or shares the margin property.
pub fn enabled(self, enabled: impl IntoPropertySource<bool>) -> Self
[src]
Sets or shares the enabled property.
pub fn clip(self, clip: impl IntoPropertySource<bool>) -> Self
[src]
Sets or shares the clip property.
pub fn opacity(self, opacity: impl IntoPropertySource<f32>) -> Self
[src]
Sets or shares the opacity property.
pub fn width(self, width: impl Into<f64>) -> Self
[src]
Inserts a new width.
pub fn height(self, height: impl Into<f64>) -> Self
[src]
Inserts a new height.
pub fn size(self, width: impl Into<f64>, height: impl Into<f64>) -> Self
[src]
Inserts a new size.
pub fn min_width(self, min_width: impl Into<f64>) -> Self
[src]
Inserts a new min_width.
pub fn min_height(self, min_height: impl Into<f64>) -> Self
[src]
Inserts a new min_height.
pub fn min_size(
self,
min_width: impl Into<f64>,
min_height: impl Into<f64>
) -> Self
[src]
self,
min_width: impl Into<f64>,
min_height: impl Into<f64>
) -> Self
Inserts a new min_size.
pub fn max_width(self, max_width: impl Into<f64>) -> Self
[src]
Inserts a new max_width.
pub fn max_height(self, max_height: impl Into<f64>) -> Self
[src]
Inserts a new max_height.
pub fn max_size(
self,
max_width: impl Into<f64>,
max_height: impl Into<f64>
) -> Self
[src]
self,
max_width: impl Into<f64>,
max_height: impl Into<f64>
) -> Self
Inserts a new min_size.
pub fn name<P: Into<String>>(self, name: P) -> Self
[src]
Sets the debug name of the widget.
pub fn cursor<P: IntoPropertySource<u32>>(self, cursor: P) -> Self
[src]
Sets or shares the entity of the Cursor widget property.
pub fn focused<P: IntoPropertySource<bool>>(self, focused: P) -> Self
[src]
Sets or shares the focused property.
pub fn font<P: IntoPropertySource<String>>(self, font: P) -> Self
[src]
Sets or shares the font property.
pub fn font_size<P: IntoPropertySource<f64>>(self, font_size: P) -> Self
[src]
Sets or shares the font size property.
pub fn lost_focus_on_activation<P: IntoPropertySource<bool>>(
self,
lost_focus_on_activation: P
) -> Self
[src]
self,
lost_focus_on_activation: P
) -> Self
Sets or shares ta value that describes if the widget should lost focus on activation (when Enter pressed).
pub fn target<P: IntoPropertySource<u32>>(self, target: P) -> Self
[src]
Sets or shares the entity of the target widget.
pub fn request_focus<P: IntoPropertySource<bool>>(
self,
request_focus: P
) -> Self
[src]
self,
request_focus: P
) -> Self
Sets or shares the request_focus property. Used to request focus from outside.Set to true
to request focus.
pub fn text<P: IntoPropertySource<String16>>(self, text: P) -> Self
[src]
Sets or shares the text property.
pub fn text_selection<P: IntoPropertySource<TextSelection>>(
self,
text_selection: P
) -> Self
[src]
self,
text_selection: P
) -> Self
Sets or shares the text selection property.
Trait Implementations
impl ActivateHandler for TextBehavior
[src]
fn on_activate<H>(self, handler: H) -> Self where
H: 'static + Fn(&mut StatesContext<'_>, Entity),
[src]
H: 'static + Fn(&mut StatesContext<'_>, Entity),
impl ChangedHandler for TextBehavior
[src]
fn on_changed<H>(self, handler: H) -> Self where
H: 'static + Fn(&mut StatesContext<'_>, Entity, &str),
[src]
H: 'static + Fn(&mut StatesContext<'_>, Entity, &str),
impl Default for TextBehavior
[src]
fn default() -> TextBehavior
[src]
impl KeyDownHandler for TextBehavior
[src]
fn on_key_down<H>(self, handler: H) -> Self where
H: 'static + Fn(&mut StatesContext<'_>, KeyEvent) -> bool,
[src]
H: 'static + Fn(&mut StatesContext<'_>, KeyEvent) -> bool,
fn on_key_down_key<H>(self, key: Key, handler: H) -> Self where
H: 'static + Fn() -> bool,
[src]
H: 'static + Fn() -> bool,
impl Template for TextBehavior
[src]
fn template(self, id: Entity, ctx: &mut BuildContext<'_>) -> Self
[src]
fn render_object(&self) -> Box<dyn RenderObject + 'static>
[src]
fn layout(&self) -> Box<dyn Layout + 'static>
[src]
impl Widget for TextBehavior
[src]
fn new() -> Self
[src]
Creates a new widget.
fn attach<P: Component + Debug>(self, property: AttachedProperty<P>) -> Self
[src]
fn insert_handler(self, handler: impl Into<Rc<dyn EventHandler>>) -> Self
[src]
fn child(self, child: Entity) -> Self
[src]
fn build(self, ctx: &mut BuildContext<'_>) -> Entity
[src]
fn create() -> Self
[src]
Auto Trait Implementations
impl !RefUnwindSafe for TextBehavior
impl !Send for TextBehavior
impl !Sync for TextBehavior
impl Unpin for TextBehavior
impl !UnwindSafe for TextBehavior
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<E> Component for E where
E: Any,
[src]
E: Any,
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> SetParameter for T
fn set<T>(&mut self, value: T) -> <T as Parameter<Self>>::Result where
T: Parameter<Self>,
T: Parameter<Self>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,