I completely agree with this. It is very useful to understand and use in design, but the use of the Widget trait makes it feel like you are required to implement the widget trait, or you aren’t able to render at all - which is actually quite opposite to how the rendering works.
I personally have been brought over to the side of Render just because when you see the render trait, you say “oh, that’s where the rendering happens”, instead of “that’s where the magic functionality of the widget happens”. Because the rendering in actually very straightforward.
The trait is there to provide a universal contract for calling renderable things in a backwards compatible way, and Widget isn’t very forwards compatible.
let mut form = Form::from_iter([
Label::new("Label 1:").boxed(),
TextBox::new("Text 1").boxed(),
Label::new("Label 2:").boxed(),
TextBox::new("Text 2").boxed(),
Label::new("Label 3:").boxed(),
TextBox::new("Text 3").boxed(),
]);
form.focus_first();
Which is then rendered:
impl WidgetRef for Form {
fn render_ref(&self, area: Rect, buf: &mut Buffer) {
let areas = Layout::vertical(vec![Constraint::Length(1); self.children.len()]).split(area);
for (child, area) in zip(self.children.iter(), areas.iter()) {
child.render_ref(*area, buf);
}
}
}
The ability to just slap form fields into a vec like this and be able to produce a rendered form is what I’m talking about when I suggest that WidgetRef is a useful abstaction. This wouldn’t be possible to build with the no Widget traits approach.
I think we can all agree that having a WidgetRef-like trait would be a good thing (as long as it isn’t required), but we are trying to decide on what the naming convention for it should be. If we were to change the name, it would take 5+ years to depreciate the old name, which means we can’t use the Wdget trait in a way that makes more current sense.
I think the rest of this discussion has been on whether Widgets are required to use the crate (they aren’t) and their existence confusing new users. (Personally I would like to see several examples without the Widget trait explaining the use cases for the Widget trait)
( I just wanted to say to everyone thanks for the engaging discussion and thanks for taking the time to articulate your thoughts and explore these ideas in so much detail! )