Skip to content

Commit 2006cb2

Browse files
committed
Use nightly feature arbitrary_self_types
1 parent 17aea51 commit 2006cb2

File tree

20 files changed

+376
-373
lines changed

20 files changed

+376
-373
lines changed

masonry_core/src/core/widget_mut.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// SPDX-License-Identifier: Apache-2.0
33

44
use std::any::TypeId;
5+
use std::ops::Receiver;
56

67
use anymap3::Entry;
78

@@ -33,6 +34,10 @@ pub struct WidgetMut<'a, W: Widget + ?Sized> {
3334
pub ctx: MutateCtx<'a>,
3435
}
3536

37+
impl<W: Widget + ?Sized> Receiver for WidgetMut<'_, W> {
38+
type Target = W;
39+
}
40+
3641
impl<W: Widget + ?Sized> Drop for WidgetMut<'_, W> {
3742
fn drop(&mut self) {
3843
// If this `WidgetMut` is a reborrow, a parent non-reborrow `WidgetMut`

masonry_core/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
reason = "Potentially controversial code style"
4141
)]
4242
#![expect(clippy::single_match, reason = "General policy not decided")]
43+
#![feature(arbitrary_self_types)]
4344

4445
// TODO - Add logo
4546

masonry_core/src/widgets/button.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,13 +89,13 @@ impl Button {
8989
// --- MARK: WIDGETMUT ---
9090
impl Button {
9191
/// Set the text.
92-
pub fn set_text(this: &mut WidgetMut<'_, Self>, new_text: impl Into<ArcStr>) {
93-
Label::set_text(&mut Self::label_mut(this), new_text);
92+
pub fn set_text(self: &mut WidgetMut<'_, Self>, new_text: impl Into<ArcStr>) {
93+
Label::set_text(&mut self.label_mut(), new_text);
9494
}
9595

9696
/// Get a mutable reference to the label.
97-
pub fn label_mut<'t>(this: &'t mut WidgetMut<'_, Self>) -> WidgetMut<'t, Label> {
98-
this.ctx.get_mut(&mut this.widget.label)
97+
pub fn label_mut<'t>(self: &'t mut WidgetMut<'_, Self>) -> WidgetMut<'t, Label> {
98+
self.ctx.get_mut(&mut self.widget.label)
9999
}
100100
}
101101

masonry_core/src/widgets/checkbox.rs

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -47,22 +47,22 @@ impl Checkbox {
4747
// --- MARK: WIDGETMUT ---
4848
impl Checkbox {
4949
/// Check or uncheck the box.
50-
pub fn set_checked(this: &mut WidgetMut<'_, Self>, checked: bool) {
51-
this.widget.checked = checked;
50+
pub fn set_checked(self: &mut WidgetMut<'_, Self>, checked: bool) {
51+
self.widget.checked = checked;
5252
// Checked state impacts appearance and accessibility node
53-
this.ctx.request_render();
53+
self.ctx.request_render();
5454
}
5555

5656
/// Set the text.
5757
///
5858
/// We enforce this to be an `ArcStr` to make the allocation explicit.
59-
pub fn set_text(this: &mut WidgetMut<'_, Self>, new_text: ArcStr) {
60-
Label::set_text(&mut Self::label_mut(this), new_text);
59+
pub fn set_text(self: &mut WidgetMut<'_, Self>, new_text: ArcStr) {
60+
Label::set_text(&mut self.label_mut(), new_text);
6161
}
6262

6363
/// Get a mutable reference to the label.
64-
pub fn label_mut<'t>(this: &'t mut WidgetMut<'_, Self>) -> WidgetMut<'t, Label> {
65-
this.ctx.get_mut(&mut this.widget.label)
64+
pub fn label_mut<'t>(self: &'t mut WidgetMut<'_, Self>) -> WidgetMut<'t, Label> {
65+
self.ctx.get_mut(&mut self.widget.label)
6666
}
6767
}
6868

@@ -312,15 +312,12 @@ mod tests {
312312

313313
harness.edit_root_widget(|mut checkbox| {
314314
let mut checkbox = checkbox.downcast::<Checkbox>();
315-
Checkbox::set_checked(&mut checkbox, true);
316-
Checkbox::set_text(
317-
&mut checkbox,
318-
ArcStr::from("The quick brown fox jumps over the lazy dog"),
319-
);
320-
321-
let mut label = Checkbox::label_mut(&mut checkbox);
322-
Label::set_brush(&mut label, PRIMARY_LIGHT);
323-
Label::insert_style(&mut label, StyleProperty::FontSize(20.0));
315+
checkbox.set_checked(true);
316+
checkbox.set_text("The quick brown fox jumps over the lazy dog".into());
317+
318+
let mut label = checkbox.label_mut();
319+
label.set_brush(PRIMARY_LIGHT);
320+
label.insert_style(StyleProperty::FontSize(20.0));
324321
});
325322

326323
harness.render()

0 commit comments

Comments
 (0)