pub struct Label { /* private fields */ }Implementations§
Source§impl Label
impl Label
Sourcepub fn new(text: impl Display) -> Self
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 }pub fn set_text(&mut self, text: impl Display)
Trait Implementations§
Source§impl Widget for Label
impl Widget for Label
fn common(&self) -> &WidgetCommon
fn common_mut(&mut self) -> &mut WidgetCommon
fn handle_draw(&mut self, event: DrawEvent) -> Result<()>
fn recalculate_size_hint_x(&mut self, _mode: SizeHintMode) -> Result<i32>
fn recalculate_size_hint_y( &mut self, _size_x: i32, _mode: SizeHintMode, ) -> Result<i32>
fn handle_mouse_input(&mut self, event: MouseInputEvent) -> Result<bool>
fn handle_mouse_enter(&mut self, event: MouseEnterEvent) -> Result<bool>
fn handle_mouse_move(&mut self, event: MouseMoveEvent) -> Result<bool>
fn handle_mouse_leave(&mut self, event: MouseLeaveEvent) -> Result<()>
fn handle_keyboard_input(&mut self, event: KeyboardInputEvent) -> Result<bool>
fn handle_ime(&mut self, event: ImeEvent) -> Result<bool>
fn handle_layout(&mut self, _event: LayoutEvent) -> Result<()>
fn handle_widget_scope_change( &mut self, event: WidgetScopeChangeEvent, ) -> Result<()>
fn handle_focus_in(&mut self, event: FocusInEvent) -> Result<()>
fn handle_focus_out(&mut self, event: FocusOutEvent) -> Result<()>
fn handle_window_focus_change( &mut self, event: WindowFocusChangeEvent, ) -> Result<()>
fn handle_accessible_action( &mut self, event: AccessibleActionEvent, ) -> Result<()>
fn handle_event(&mut self, event: Event) -> Result<bool>
fn recalculate_size_x_fixed(&mut self) -> bool
fn recalculate_size_y_fixed(&mut self) -> bool
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> ArchivePointee for T
impl<T> ArchivePointee for T
Source§type ArchivedMetadata = ()
type ArchivedMetadata = ()
The archived version of the pointer metadata for this type.
Source§fn pointer_metadata(
_: &<T as ArchivePointee>::ArchivedMetadata,
) -> <T as Pointee>::Metadata
fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata, ) -> <T as Pointee>::Metadata
Converts some archived metadata to the pointer metadata for itself.
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
Mutably borrows from an owned value. Read more
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<F, W, T, D> Deserialize<With<T, W>, D> for F
impl<F, W, T, D> Deserialize<With<T, W>, D> for F
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>
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>
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)
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)
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> 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>
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 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>
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