Skip to content

Commit 781138a

Browse files
authored
Remove ViewArgument (#1666)
Motivated by #1638 (comment) this PR basically reverts #1444.
1 parent efeb5bf commit 781138a

126 files changed

Lines changed: 1376 additions & 2042 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

placehero/src/avatars.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use std::sync::Arc;
66

77
use xilem::core::one_of::Either;
88
use xilem::core::{
9-
MessageProxy, MessageResult, NoElement, Resource, View, ViewArgument, fork, map_message_result,
9+
MessageProxy, MessageResult, NoElement, Resource, View, fork, map_message_result,
1010
on_action_with_context, provides, with_context,
1111
};
1212
use xilem::masonry::layout::AsUnit;
@@ -45,7 +45,7 @@ impl Avatars {
4545
///
4646
/// Requires that this View is within a [`Self::provide`] call.
4747
// TODO: ArcStr for URL?
48-
pub(crate) fn avatar<State: ViewArgument, Action: 'static>(
48+
pub(crate) fn avatar<State: 'static, Action: 'static>(
4949
url: String,
5050
) -> impl WidgetView<State, Action> + use<State, Action> {
5151
with_context(move |this: &mut Self, _| {
@@ -84,7 +84,7 @@ impl Avatars {
8484
) -> impl WidgetView<State, Action, Element = Child::Element>
8585
where
8686
Child: WidgetView<State, Action>,
87-
State: ViewArgument,
87+
State: 'static,
8888
Action: 'static,
8989
{
9090
provides(
@@ -99,7 +99,7 @@ impl Avatars {
9999
fn worker<State, Action>()
100100
-> impl View<State, Action, ViewCtx, Element = NoElement> + use<State, Action>
101101
where
102-
State: ViewArgument,
102+
State: 'static,
103103
Action: 'static,
104104
{
105105
map_message_result(

placehero/src/components.rs

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

44
use megalodon::entities::Status;
5-
use xilem::core::{Arg, ViewArgument};
65
use xilem::masonry::layout::AsUnit;
76
use xilem::style::Style;
87
use xilem::view::{
@@ -28,7 +27,7 @@ mod media;
2827
// TODO: Determine our UX for boosting/reblogging.
2928
// In particular, do we want to have the same design as "normal" Mastodon, where the
3029
// avatar for the booster is shown in the "child" avatar.
31-
fn base_status<State: ViewArgument>(
30+
fn base_status<State: 'static>(
3231
status: &Status,
3332
) -> impl FlexSequence<State, Navigation> + use<State> {
3433
// TODO: This really should be Arced or something.
@@ -75,7 +74,7 @@ fn base_status<State: ViewArgument>(
7574
label(format!("💬 {}", status.replies_count)).flex(1.0),
7675
label(format!("🔄 {}", status.reblogs_count)).flex(1.0),
7776
label(format!("⭐ {}", status.favourites_count)).flex(1.0),
78-
text_button("View Replies", move |_: Arg<'_, State>| {
77+
text_button("View Replies", move |_: &mut State| {
7978
Navigation::LoadContext(status_clone.clone())
8079
}),
8180
))

placehero/src/components/media.rs

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,7 @@ use std::{
99
use megalodon::entities::{Attachment, attachment::AttachmentType};
1010
use xilem::{
1111
Blob, ImageFormat, WidgetView,
12-
core::{
13-
ViewArgument,
14-
one_of::{OneOf, OneOf4},
15-
},
12+
core::one_of::{OneOf, OneOf4},
1613
masonry::peniko::{ImageAlphaType, ImageData},
1714
view::{ObjectFit, flex_col, image, prose},
1815
};
@@ -22,7 +19,7 @@ use crate::actions::Navigation;
2219
/// Render a single media attachment for use in a status.
2320
///
2421
/// This currently doesn't perform any caching.
25-
pub(crate) fn attachment<State: ViewArgument>(
22+
pub(crate) fn attachment<State: 'static>(
2623
attachment: &Attachment,
2724
) -> impl WidgetView<State, Navigation> + use<State> {
2825
match attachment.r#type {
@@ -41,7 +38,7 @@ pub(crate) fn attachment<State: ViewArgument>(
4138
/// This view currently does not cache the blurhash, or take any other steps to
4239
/// avoid recalculating the image.
4340
/// We haven't ran into this being a performance issue.
44-
fn maybe_blurhash<State: ViewArgument>(
41+
fn maybe_blurhash<State: 'static>(
4542
attachment: &Attachment,
4643
) -> Option<impl WidgetView<State, Navigation> + use<State>> {
4744
let start = Instant::now();
@@ -90,7 +87,7 @@ fn maybe_blurhash<State: ViewArgument>(
9087
}
9188

9289
/// Show some useful info for audio attachments.
93-
fn audio_attachment<State: ViewArgument>(
90+
fn audio_attachment<State: 'static>(
9491
attachment: &Attachment,
9592
) -> impl WidgetView<State, Navigation> + use<State> {
9693
flex_col((
@@ -106,7 +103,7 @@ fn audio_attachment<State: ViewArgument>(
106103
}
107104

108105
/// Show some useful info for audio attachments.
109-
fn video_attachment<State: ViewArgument>(
106+
fn video_attachment<State: 'static>(
110107
attachment: &Attachment,
111108
) -> impl WidgetView<State, Navigation> + use<State> {
112109
flex_col((
@@ -122,7 +119,7 @@ fn video_attachment<State: ViewArgument>(
122119
}
123120

124121
/// Show some useful info for audio attachments.
125-
fn image_attachment<State: ViewArgument>(
122+
fn image_attachment<State: 'static>(
126123
attachment: &Attachment,
127124
) -> impl WidgetView<State, Navigation> + use<State> {
128125
flex_col((

placehero/src/components/thread.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
use megalodon::entities::{Context, Status};
55
use xilem::WidgetView;
6-
use xilem::core::Edit;
76
use xilem::masonry::layout::AsUnit;
87
use xilem::masonry::util::debug_panic;
98
use xilem::palette::css;
@@ -25,7 +24,7 @@ pub(crate) fn thread(
2524
// The hard part there would be locking the scroll properly (i.e. once the thread loads)
2625
thread: &Context,
2726
// TODO: Think about allowing composing a reply.
28-
) -> impl WidgetView<Edit<Placehero>, Navigation> + use<> {
27+
) -> impl WidgetView<Placehero, Navigation> + use<> {
2928
let mut ancestor_views = Vec::new();
3029
let mut previous_parent = None;
3130
for ancestor in &thread.ancestors {
@@ -72,7 +71,7 @@ pub(crate) fn thread(
7271
///
7372
/// These are rendered without a containing box, and with an adjoining "reply indicator"
7473
/// (which is currently known to be terrible!).
75-
fn thread_ancestor(status: &Status) -> impl WidgetView<Edit<Placehero>, Navigation> + use<> {
74+
fn thread_ancestor(status: &Status) -> impl WidgetView<Placehero, Navigation> + use<> {
7675
sized_box(flex_row((
7776
// An awful left-side border.
7877
flex_col(())

placehero/src/components/timeline.rs

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
use megalodon::Megalodon;
55
use megalodon::entities::{Account, Status};
66
use megalodon::megalodon::GetAccountStatusesInputOptions;
7+
use xilem::core::fork;
78
use xilem::core::one_of::{OneOf, OneOf3};
8-
use xilem::core::{Edit, fork};
99
use xilem::masonry::core::ArcStr;
1010
use xilem::masonry::layout::AsUnit;
1111
use xilem::palette::css;
@@ -59,10 +59,7 @@ impl Timeline {
5959
}
6060
}
6161

62-
pub(crate) fn view(
63-
&mut self,
64-
mastodon: Mastodon,
65-
) -> impl WidgetView<Edit<Self>, Navigation> + use<> {
62+
pub(crate) fn view(&mut self, mastodon: Mastodon) -> impl WidgetView<Self, Navigation> + use<> {
6663
// We clone the relevant user id for use in `worker_raw`
6764
// (We plan for the function which makes the future to have access to the app state, but that hasn't happened yet)
6865
let user = self.user_id.clone();
@@ -183,9 +180,7 @@ impl Timeline {
183180
// I think you want the same thing, but without the box, and without any "this is a reply" indicator.
184181
// It also wouldn't need to handle reblogs (the API doesn't provide any way to make a reply status which is a reblog).
185182
// N.b. API wise, there's no reason that you can't reply to a "reblog" status. TODO: Confirm this
186-
pub(crate) fn timeline_status(
187-
status: &Status,
188-
) -> impl WidgetView<Edit<Timeline>, Navigation> + use<> {
183+
pub(crate) fn timeline_status(status: &Status) -> impl WidgetView<Timeline, Navigation> + use<> {
189184
let (info_line, primary_status) = if let Some(reblog) = status.reblog.as_ref() {
190185
(
191186
Some(prose(format!("🔄 {} boosted", status.account.display_name))),

placehero/src/lib.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ use megalodon::entities::{Context, Instance, Status};
2525
use megalodon::error::{Kind, OwnError};
2626
use megalodon::{Megalodon, mastodon};
2727
use xilem::core::one_of::{Either, OneOf, OneOf3, OneOf6};
28-
use xilem::core::{Edit, NoElement, View, fork, lens, map_action, map_state};
28+
use xilem::core::{NoElement, View, fork, lens, map_action, map_state};
2929
use xilem::masonry::layout::AsUnit;
3030
use xilem::style::Style;
3131
use xilem::tokio::sync::mpsc::{UnboundedReceiver, UnboundedSender};
@@ -84,7 +84,7 @@ enum MainState {
8484
New(PlaceheroWithLogin),
8585
}
8686

87-
fn select_app(state: &mut MainState) -> impl WidgetView<Edit<MainState>> + use<> {
87+
fn select_app(state: &mut MainState) -> impl WidgetView<MainState> + use<> {
8888
match state {
8989
MainState::Selecting => OneOf3::A(
9090
flex_col((
@@ -104,13 +104,13 @@ fn select_app(state: &mut MainState) -> impl WidgetView<Edit<MainState>> + use<>
104104
))
105105
.main_axis_alignment(MainAxisAlignment::Center),
106106
),
107-
MainState::Old(_) => OneOf::B(lens(app_logic, |state: &mut MainState, ()| {
107+
MainState::Old(_) => OneOf::B(lens(app_logic, |state: &mut MainState| {
108108
let MainState::Old(placehero) = state else {
109109
unreachable!()
110110
};
111111
placehero
112112
})),
113-
MainState::New(_) => OneOf::C(lens(login_flow::app_logic, |state: &mut MainState, ()| {
113+
MainState::New(_) => OneOf::C(lens(login_flow::app_logic, |state: &mut MainState| {
114114
let MainState::New(placehero) = state else {
115115
unreachable!()
116116
};
@@ -163,7 +163,7 @@ impl Default for Placehero {
163163
}
164164

165165
impl Placehero {
166-
fn sidebar(&mut self) -> impl WidgetView<Edit<Self>, Navigation> + use<> {
166+
fn sidebar(&mut self) -> impl WidgetView<Self, Navigation> + use<> {
167167
if let Some(instance) = &self.instance {
168168
let back = if self.show_context.is_some() {
169169
// TODO: Make the ⬅️ arrow not be available to screen readers.
@@ -200,7 +200,7 @@ impl Placehero {
200200
}
201201
}
202202

203-
fn main_view(&mut self) -> impl WidgetView<Edit<Self>, Navigation> + use<> {
203+
fn main_view(&mut self) -> impl WidgetView<Self, Navigation> + use<> {
204204
if let Some(show_context) = self.show_context.as_ref() {
205205
if let Some(context) = self.context.as_ref() {
206206
// TODO: Display the status until the entire thread loads; this is hard because
@@ -224,15 +224,15 @@ impl Placehero {
224224
// In the current edition of the app, the timeline is never removed
225225
// If it ever is, we'll need to be more careful here.
226226
// The patterns are still in flux.
227-
|this: &mut Self, ()| this.timeline.as_mut().unwrap(),
227+
|this: &mut Self| this.timeline.as_mut().unwrap(),
228228
))
229229
} else {
230230
OneOf::F(prose("No statuses yet loaded"))
231231
}
232232
}
233233
}
234234

235-
fn app_logic(app_state: &mut Placehero) -> impl WidgetView<Edit<Placehero>> + use<> {
235+
fn app_logic(app_state: &mut Placehero) -> impl WidgetView<Placehero> + use<> {
236236
Avatars::provide(fork(
237237
map_action(
238238
split(app_state.sidebar(), app_state.main_view()).split_point(0.2),
@@ -276,7 +276,7 @@ fn app_logic(app_state: &mut Placehero) -> impl WidgetView<Edit<Placehero>> + us
276276

277277
fn load_contexts(
278278
mastodon: Mastodon,
279-
) -> impl View<Edit<Placehero>, (), ViewCtx, Element = NoElement> + use<> {
279+
) -> impl View<Placehero, (), ViewCtx, Element = NoElement> + use<> {
280280
worker_raw(
281281
move |result, mut recv: UnboundedReceiver<String>| {
282282
let mastodon = mastodon.clone();
@@ -320,7 +320,7 @@ fn load_contexts(
320320

321321
fn load_instance(
322322
mastodon: Mastodon,
323-
) -> impl View<Edit<Placehero>, (), ViewCtx, Element = NoElement> + use<> {
323+
) -> impl View<Placehero, (), ViewCtx, Element = NoElement> + use<> {
324324
task_raw(
325325
move |result, _| {
326326
let mastodon = mastodon.clone();
@@ -345,7 +345,7 @@ fn load_instance(
345345

346346
fn load_account(
347347
mastodon: Mastodon,
348-
) -> impl View<Edit<Placehero>, (), ViewCtx, Element = NoElement> + use<> {
348+
) -> impl View<Placehero, (), ViewCtx, Element = NoElement> + use<> {
349349
worker_raw(
350350
move |result, mut recv: UnboundedReceiver<String>| {
351351
let mastodon = mastodon.clone();

placehero/src/login_flow.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
66
use xilem::{
77
WidgetView,
8-
core::{Edit, one_of::Either},
8+
core::one_of::Either,
99
view::{CrossAxisAlignment, FlexExt, flex_col, label, prose},
1010
};
1111

@@ -27,7 +27,7 @@ impl PlaceheroWithLogin {
2727

2828
pub(crate) fn app_logic(
2929
state: &mut PlaceheroWithLogin,
30-
) -> impl WidgetView<Edit<PlaceheroWithLogin>> + use<> {
30+
) -> impl WidgetView<PlaceheroWithLogin> + use<> {
3131
let Some(_login) = &mut state.login else {
3232
return Either::A(flex_col((
3333
prose("Error: Placehero not ran using cargo run.")

xilem/README.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,10 @@ A simple incrementing counter application looks like:
7878
use winit::error::EventLoopError;
7979
use xilem::view::{text_button, flex_col, label};
8080
use xilem::{EventLoop, WindowOptions, WidgetView, Xilem};
81-
use xilem::core::Edit;
8281

8382
struct Counter(i32);
8483

85-
fn app_logic(data: &mut Counter) -> impl WidgetView<Edit<Counter>> + use<> {
84+
fn app_logic(data: &mut Counter) -> impl WidgetView<Counter> + use<> {
8685
flex_col((
8786
label(format!("{}", data.0)),
8887
text_button("increment", |data: &mut Counter| data.0 += 1),
@@ -143,7 +142,7 @@ This is new syntax in the 2024 edition, and so it might be unfamiliar.
143142
Here's a snippet from the Xilem examples:
144143

145144
```rust
146-
fn app_logic(data: &mut EmojiPagination) -> impl WidgetView<Edit<EmojiPagination>> + use<> {
145+
fn app_logic(data: &mut EmojiPagination) -> impl WidgetView<EmojiPagination> + use<> {
147146
// ...
148147
}
149148
```

xilem/examples/calc.rs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ use xilem::view::{
1313
FlexSequence, FlexSpacer, GridExt, GridSequence, button, flex_row, grid, label, text_button,
1414
};
1515
use xilem::{Color, EventLoop, EventLoopBuilder, WidgetView, WindowOptions, Xilem, palette};
16-
use xilem_core::{Edit, ViewArgument};
1716

1817
#[derive(Copy, Clone)]
1918
enum MathOperator {
@@ -191,7 +190,7 @@ impl Calculator {
191190
}
192191
}
193192

194-
fn num_row(nums: [&'static str; 3], row: i32) -> impl GridSequence<Edit<Calculator>> {
193+
fn num_row(nums: [&'static str; 3], row: i32) -> impl GridSequence<Calculator> {
195194
let mut views: Vec<_> = vec![];
196195
for (i, num) in nums.iter().enumerate() {
197196
views.push(digit_button(num).grid_pos(i32::try_from(i).unwrap(), row));
@@ -201,7 +200,7 @@ fn num_row(nums: [&'static str; 3], row: i32) -> impl GridSequence<Edit<Calculat
201200

202201
const DISPLAY_FONT_SIZE: f32 = 30.;
203202
const GRID_GAP: Length = Length::const_px(2.);
204-
fn app_logic(data: &mut Calculator) -> impl WidgetView<Edit<Calculator>> + use<> {
203+
fn app_logic(data: &mut Calculator) -> impl WidgetView<Calculator> + use<> {
205204
grid(
206205
(
207206
// Display
@@ -253,7 +252,7 @@ fn app_logic(data: &mut Calculator) -> impl WidgetView<Edit<Calculator>> + use<>
253252
}
254253

255254
/// Creates a horizontal centered flex row designed for the display portion of the calculator.
256-
fn centered_flex_row<State: ViewArgument, Seq: FlexSequence<State> + Send + Sync + 'static>(
255+
fn centered_flex_row<State: 'static, Seq: FlexSequence<State> + Send + Sync + 'static>(
257256
sequence: Seq,
258257
) -> impl WidgetView<State, ()> {
259258
flex_row(sequence)
@@ -264,15 +263,15 @@ fn centered_flex_row<State: ViewArgument, Seq: FlexSequence<State> + Send + Sync
264263

265264
/// Returns a label intended to be used in the calculator's top display.
266265
/// The default text size is out of proportion for this use case.
267-
fn display_label(text: &str) -> impl WidgetView<Edit<Calculator>> + use<> {
266+
fn display_label(text: &str) -> impl WidgetView<Calculator> + use<> {
268267
label(text).text_size(DISPLAY_FONT_SIZE)
269268
}
270269

271270
/// Returns one button
272271
fn one_button(
273-
content: impl WidgetView<Edit<Calculator>>,
272+
content: impl WidgetView<Calculator>,
274273
callback: impl Fn(&mut Calculator) + Send + Sync + 'static,
275-
) -> impl WidgetView<Edit<Calculator>> {
274+
) -> impl WidgetView<Calculator> {
276275
const BLUE: Color = Color::from_rgb8(0x00, 0x8d, 0xdd);
277276
button(content, callback)
278277
.background_color(BLUE)
@@ -283,7 +282,7 @@ fn one_button(
283282

284283
/// Returns a button that triggers the calculator's operator handler,
285284
/// `on_entered_operator()`.
286-
fn operator_button(math_operator: MathOperator) -> impl WidgetView<Edit<Calculator>> {
285+
fn operator_button(math_operator: MathOperator) -> impl WidgetView<Calculator> {
287286
one_button(
288287
label(math_operator.as_str()),
289288
move |data: &mut Calculator| {
@@ -293,7 +292,7 @@ fn operator_button(math_operator: MathOperator) -> impl WidgetView<Edit<Calculat
293292
}
294293

295294
/// A button which adds `digit` to the current input when pressed
296-
fn digit_button(digit: &'static str) -> impl WidgetView<Edit<Calculator>> {
295+
fn digit_button(digit: &'static str) -> impl WidgetView<Calculator> {
297296
const GRAY: Color = Color::from_rgb8(0x3a, 0x3a, 0x3a);
298297

299298
text_button(digit, |data: &mut Calculator| {

0 commit comments

Comments
 (0)