Skip to main content

Label

Struct Label 

Source
pub struct Label { /* private fields */ }

Implementations§

Source§

impl Label

Source

pub fn new(text: impl Display) -> Self

Examples found in repository?
examples/start.rs (line 36)
27    fn new() -> Self {
28        let mut this = Self {
29            counter: 0,
30            common: WidgetCommon::new(),
31        };
32        let mut button = Button::new("another button");
33        button.on_triggered(this.callback(|this, _event| {
34            this.counter += 1;
35            println!("counter: {}", this.counter);
36            let label = Label::new(format!("counter: {}", this.counter))
37                .with_window(Window::default_attributes().with_title("example"))
38                .boxed();
39            this.common_mut().add_child(label, Default::default());
40            Ok(())
41        }));
42        this.common_mut()
43            .add_child(button.boxed(), Default::default());
44        this
45    }
46}
47
48impl Widget for AnotherWidget {
49    impl_widget_common!();
50
51    fn recalculate_size_hint_x(&mut self, mode: SizeHintMode) -> Result<i32> {
52        Ok(self.common_mut().children[0].widget.size_hint_x(mode))
53    }
54    fn recalculate_size_x_fixed(&mut self) -> bool {
55        self.common_mut().children[0].widget.size_x_fixed()
56    }
57    fn recalculate_size_hint_y(&mut self, size_x: i32, mode: SizeHintMode) -> Result<i32> {
58        Ok(self.common_mut().children[0]
59            .widget
60            .size_hint_y(size_x, mode))
61    }
62    fn recalculate_size_y_fixed(&mut self) -> bool {
63        self.common_mut().children[0].widget.size_y_fixed()
64    }
65    fn handle_layout(&mut self, event: LayoutEvent) -> Result<()> {
66        self.common.set_child_rect(
67            0,
68            event
69                .new_rect_in_window()
70                .map(|r| Rect::from_pos_size(Default::default(), r.size)),
71        )
72    }
73}
74
75struct RootWidget {
76    common: WidgetCommon,
77    button_id: WidgetId<Button>,
78    column2_id: WidgetId<Column>,
79    button21_id: WidgetId<Button>,
80    button22_id: WidgetId<Button>,
81    flag_column: bool,
82    flag_button21: bool,
83    i: i32,
84    label2_id: WidgetId<Label>,
85}
86
87impl RootWidget {
88    fn new() -> Self {
89        let mut common = WidgetCommon::new();
90        let mut root = Column::new();
91
92        root.add_child(TextInput::new("Hello, Rust! 🦀😂\n").boxed());
93        root.add_child(TextInput::new("Hebrew name Sarah: שרה.").boxed());
94
95        /*
96        let btn = Button::new("btn1")
97            .with_icon(icon)
98            .with_alignment(Al::Right)
99            .with_on_clicked(slot)
100            .split_id()
101            .boxed();
102        root.add(btn.widget);
103
104        Self {
105            btn_id: btn.id,
106        }
107
108
109        */
110
111        let btn1 = Button::new("btn1")
112            .with_auto_repeat(true)
113            .with_on_triggered(
114                common
115                    .id
116                    .callback(|this: &mut Self, event| this.button_clicked(event, 1)),
117            )
118            .with_id();
119
120        root.add_child(btn1.widget.boxed());
121
122        root.add_child(
123            Button::new("btn2")
124                .with_on_triggered(
125                    common
126                        .id
127                        .callback(|this: &mut Self, event| this.button_clicked(event, 2)),
128                )
129                .boxed(),
130        );
131
132        let button21 = Button::new("btn21")
133            .with_on_triggered(common.id.callback(|_: &mut Self, _| {
134                println!("click!");
135                Ok(())
136            }))
137            .with_id();
138
139        let button22 = Button::new("btn22").with_id();
140
141        let column2 = Column::new()
142            .with_child(button21.widget.boxed())
143            .with_child(button22.widget.boxed())
144            .with_id();
145        root.add_child(column2.widget.boxed());
146
147        let btn3 = AnotherWidget::new().boxed();
148        root.add_child(btn3);
149
150        // root.add_child(
151        //     ScrollBar::new()
152        //         .with_axis(Axis::Y)
153        //         .with_on_value_changed(ctx.callback(|this, ctx, value| {
154        //             ctx.widget(this.label2_id)?
155        //                 .set_text(format!("value={value}"));
156        //             Ok(())
157        //         }))
158        //         .boxed(),
159        // );
160        let label2 = Label::new("ok").with_id();
161        root.add_child(label2.widget.boxed());
162
163        let mut content = Column::new();
164        for i in 1..=80 {
165            content.add_child(Button::new(format!("btn{i}")).boxed());
166        }
167
168        root.add_child(ScrollArea::new(content.boxed()).boxed());
169
170        common.add_child(
171            PaddingBox::new(root.boxed())
172                .with_window(Window::default_attributes().with_title("example"))
173                .boxed(),
174            Default::default(),
175        );
176        add_interval(
177            Duration::from_secs(2),
178            common.id.callback(|this: &mut Self, _| this.inc()),
179        );
180
181        RootWidget {
182            common,
183            button_id: btn1.id,
184            column2_id: column2.id,
185            button21_id: button21.id,
186            button22_id: button22.id,
187            flag_column: true,
188            flag_button21: true,
189            i: 0,
190            label2_id: label2.id,
191        }
192    }
Source

pub fn set_text(&mut self, text: impl Display)

Trait Implementations§

Source§

impl Widget for Label

Source§

fn common(&self) -> &WidgetCommon

Source§

fn common_mut(&mut self) -> &mut WidgetCommon

Source§

fn handle_draw(&mut self, event: DrawEvent) -> Result<()>

Source§

fn recalculate_size_hint_x(&mut self, _mode: SizeHintMode) -> Result<i32>

Source§

fn recalculate_size_hint_y( &mut self, _size_x: i32, _mode: SizeHintMode, ) -> Result<i32>

Source§

fn handle_mouse_input(&mut self, event: MouseInputEvent) -> Result<bool>

Source§

fn handle_mouse_enter(&mut self, event: MouseEnterEvent) -> Result<bool>

Source§

fn handle_mouse_move(&mut self, event: MouseMoveEvent) -> Result<bool>

Source§

fn handle_mouse_leave(&mut self, event: MouseLeaveEvent) -> Result<()>

Source§

fn handle_keyboard_input(&mut self, event: KeyboardInputEvent) -> Result<bool>

Source§

fn handle_ime(&mut self, event: ImeEvent) -> Result<bool>

Source§

fn handle_layout(&mut self, _event: LayoutEvent) -> Result<()>

Source§

fn handle_widget_scope_change( &mut self, event: WidgetScopeChangeEvent, ) -> Result<()>

Source§

fn handle_focus_in(&mut self, event: FocusInEvent) -> Result<()>

Source§

fn handle_focus_out(&mut self, event: FocusOutEvent) -> Result<()>

Source§

fn handle_window_focus_change( &mut self, event: WindowFocusChangeEvent, ) -> Result<()>

Source§

fn handle_accessible_action( &mut self, event: AccessibleActionEvent, ) -> Result<()>

Source§

fn handle_event(&mut self, event: Event) -> Result<bool>

Source§

fn recalculate_size_x_fixed(&mut self) -> bool

Source§

fn recalculate_size_y_fixed(&mut self) -> bool

Source§

fn accessible_node(&mut self) -> Option<NodeBuilder>

Auto Trait Implementations§

§

impl !RefUnwindSafe for Label

§

impl !Send for Label

§

impl !Sync for Label

§

impl !UnwindSafe for Label

§

impl Freeze for Label

§

impl Unpin for Label

§

impl UnsafeUnpin 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> ArchivePointee for T

Source§

type ArchivedMetadata = ()

The archived version of the pointer metadata for this type.
Source§

fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata, ) -> <T as Pointee>::Metadata

Converts some archived metadata to the pointer metadata for itself.
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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<F, W, T, D> Deserialize<With<T, W>, D> for F
where W: DeserializeWith<F, T, D>, D: Fallible + ?Sized, F: ?Sized,

Source§

fn deserialize( &self, deserializer: &mut D, ) -> Result<With<T, W>, <D as Fallible>::Error>

Deserializes using the given deserializer
Source§

impl<T> Downcast for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

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

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

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

Convert &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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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 more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Pointee for T

Source§

type Metadata = ()

The type for metadata in pointers and references to Self.
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<W> WidgetExt for W
where W: Widget + ?Sized,

Source§

fn id(&self) -> WidgetId<W>
where W: Sized,

Source§

fn with_window(self, attrs: WindowAttributes) -> W
where W: Sized,

Source§

fn callback<F, E>(&self, func: F) -> Callback<E>
where F: Fn(&mut W, E) -> Result<(), Error> + 'static, E: 'static, W: Sized,

Source§

fn dispatch(&mut self, event: Event) -> bool

Source§

fn update_accessible(&mut self)

Source§

fn size_hint_x(&mut self, mode: SizeHintMode) -> i32

Source§

fn size_hints_x(&mut self) -> SizeHints

Source§

fn size_hint_y(&mut self, size_x: i32, mode: SizeHintMode) -> i32

Source§

fn size_hints_y(&mut self, size_x: i32) -> SizeHints

Source§

fn size_hints_y_from_hints_x(&mut self, hints_x: SizeHints) -> SizeHints

Source§

fn size_x_fixed(&mut self) -> bool

Source§

fn size_y_fixed(&mut self) -> bool

Source§

fn set_scope(&mut self, scope: WidgetScope)

Source§

fn set_enabled(&mut self, enabled: bool)

Source§

fn set_visible(&mut self, visible: bool)

Source§

fn set_style(&mut self, style: Option<Style>) -> Result<(), Error>

Source§

fn boxed(self) -> Box<dyn Widget>
where W: Sized,

Source§

fn with_id(self) -> WidgetWithId<Self>
where Self: Sized,

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more