Add non-chainable add_child to LinearLayout

This commit is contained in:
Alexandre Bury 2016-07-27 23:51:41 -07:00
parent bea7240271
commit c689a3ba7e

View File

@ -1,4 +1,5 @@
use XY; use XY;
use With;
use direction; use direction;
use view::View; use view::View;
use view::{Selector, SizeCache}; use view::{Selector, SizeCache};
@ -56,15 +57,20 @@ impl LinearLayout {
} }
/// Adds a child to the layout. /// Adds a child to the layout.
pub fn child<V: View + 'static>(mut self, view: V) -> Self { ///
/// Chainable variant.
pub fn child<V: View + 'static>(self, view: V) -> Self {
self.with(|s| s.add_child(view))
}
/// Adds a child to the layout.
pub fn add_child<V: View + 'static>(&mut self, view: V) {
self.children.push(Child { self.children.push(Child {
view: Box::new(view), view: Box::new(view),
size: Vec2::zero(), size: Vec2::zero(),
weight: 0, weight: 0,
}); });
self.invalidate(); self.invalidate();
self
} }
// Invalidate the view, to request a layout next time // Invalidate the view, to request a layout next time