1
1
mirror of https://github.com/wez/wezterm.git synced 2024-12-25 06:12:16 +03:00

internalizing boxing when creating widgets

This commit is contained in:
Wez Furlong 2018-07-28 12:28:10 -07:00
parent 612ac84454
commit bb609df317
4 changed files with 33 additions and 32 deletions

View File

@ -68,7 +68,7 @@ fn main() -> Result<(), Error> {
let mut buf = BufferedTerminal::new(new_terminal(caps)?)?;
buf.terminal().set_raw_mode()?;
let mut screen = Screen::new(Widget::new(Box::new(MainScreen::default())));
let mut screen = Screen::new(Widget::new(MainScreen::default()));
screen.render_to_screen(&mut buf)?;
buf.flush()?;

View File

@ -1574,7 +1574,7 @@ mod test {
DeviceAttribute::Code(DeviceAttributeCodes::NationalReplacementCharsets),
DeviceAttribute::Code(DeviceAttributeCodes::TechnicalCharacters),
DeviceAttribute::Code(DeviceAttributeCodes::AnsiColor),
]))
])),
)))]
);
}

View File

@ -538,7 +538,7 @@ mod test {
#[test]
fn single_widget_unspec() {
let widget = Widget::new(Box::new(UnspecWidget {}));
let widget = Widget::new(UnspecWidget {});
let mut layout = LayoutState::new();
layout.add_widget_recursive(&widget);
layout.update_constraints(40, 12, &widget).unwrap();
@ -551,14 +551,14 @@ mod test {
#[test]
fn two_children_pct() {
let root = Widget::new(Box::new(UnspecWidget {}));
let root = Widget::new(UnspecWidget {});
let a = Widget::new(Box::new(ConstrainedWidget::new(
let a = Widget::new(ConstrainedWidget::new(
Constraints::default().set_pct_width(50).clone(),
)));
let b = Widget::new(Box::new(ConstrainedWidget::new(
));
let b = Widget::new(ConstrainedWidget::new(
Constraints::default().set_pct_width(50).clone(),
)));
));
root.borrow_mut().add_child(&a);
root.borrow_mut().add_child(&b);
@ -583,17 +583,17 @@ mod test {
#[test]
fn three_children_pct() {
let root = Widget::new(Box::new(UnspecWidget {}));
let root = Widget::new(UnspecWidget {});
let a = Widget::new(Box::new(ConstrainedWidget::new(
let a = Widget::new(ConstrainedWidget::new(
Constraints::default().set_pct_width(20).clone(),
)));
let b = Widget::new(Box::new(ConstrainedWidget::new(
));
let b = Widget::new(ConstrainedWidget::new(
Constraints::default().set_pct_width(20).clone(),
)));
let c = Widget::new(Box::new(ConstrainedWidget::new(
));
let c = Widget::new(ConstrainedWidget::new(
Constraints::default().set_pct_width(20).clone(),
)));
));
root.borrow_mut().add_child(&a);
root.borrow_mut().add_child(&b);
@ -621,14 +621,14 @@ mod test {
#[test]
fn two_children_a_b() {
let root = Widget::new(Box::new(UnspecWidget {}));
let root = Widget::new(UnspecWidget {});
let a = Widget::new(Box::new(ConstrainedWidget::new(
let a = Widget::new(ConstrainedWidget::new(
Constraints::with_fixed_width_height(5, 2),
)));
let b = Widget::new(Box::new(ConstrainedWidget::new(
));
let b = Widget::new(ConstrainedWidget::new(
Constraints::with_fixed_width_height(3, 2),
)));
));
root.borrow_mut().add_child(&a);
root.borrow_mut().add_child(&b);
@ -653,14 +653,14 @@ mod test {
#[test]
fn two_children_b_a() {
let root = Widget::new(Box::new(UnspecWidget {}));
let root = Widget::new(UnspecWidget {});
let a = Widget::new(Box::new(ConstrainedWidget::new(
let a = Widget::new(ConstrainedWidget::new(
Constraints::with_fixed_width_height(5, 2),
)));
let b = Widget::new(Box::new(ConstrainedWidget::new(
));
let b = Widget::new(ConstrainedWidget::new(
Constraints::with_fixed_width_height(3, 2),
)));
));
root.borrow_mut().add_child(&b);
root.borrow_mut().add_child(&a);
@ -685,14 +685,14 @@ mod test {
#[test]
fn two_children_overflow() {
let root = Widget::new(Box::new(UnspecWidget {}));
let root = Widget::new(UnspecWidget {});
let a = Widget::new(Box::new(ConstrainedWidget::new(
let a = Widget::new(ConstrainedWidget::new(
Constraints::with_fixed_width_height(5, 2),
)));
let b = Widget::new(Box::new(ConstrainedWidget::new(
));
let b = Widget::new(ConstrainedWidget::new(
Constraints::with_fixed_width_height(3, 2),
)));
));
root.borrow_mut().add_child(&a);
root.borrow_mut().add_child(&b);
@ -719,7 +719,7 @@ mod test {
($name:ident, $constraint:expr, $width:expr, $height:expr, $coords:expr) => {
#[test]
fn $name() {
let widget = Widget::new(Box::new(ConstrainedWidget::new($constraint)));
let widget = Widget::new(ConstrainedWidget::new($constraint));
let mut layout = LayoutState::new();
layout.add_widget_recursive(&widget);
layout.update_constraints(100, 100, &widget).unwrap();

View File

@ -160,7 +160,8 @@ impl WidgetId {
}
impl Widget {
pub fn new(widget: Box<WidgetImpl>) -> WidgetHandle {
pub fn new<W: WidgetImpl + 'static>(widget: W) -> WidgetHandle {
let widget = Box::new(widget);
let (width, height) = (80, 24); //widget.get_size_constraints().deduce_initial_size();
let surface = Surface::new(width, height);
let coordinates = ParentRelativeCoords::new(0, 0);