Implement Container widget

Remove `align_self` and `justify_content` methods
This commit is contained in:
Héctor Ramón Jiménez 2019-11-11 05:26:08 +01:00
parent bfe19193b9
commit ceb02f4a36
25 changed files with 310 additions and 205 deletions

View file

@ -1,6 +1,6 @@
use iced::{
scrollable, text::HorizontalAlignment, text_input, Align, Application,
Checkbox, Color, Column, Element, Scrollable, Text, TextInput,
scrollable, text::HorizontalAlignment, text_input, Application, Checkbox,
Color, Column, Container, Element, Length, Scrollable, Text, TextInput,
};
pub fn main() {
@ -78,7 +78,6 @@ impl Application for Todos {
let content = Column::new()
.max_width(800)
.align_self(Align::Center)
.spacing(20)
.push(title)
.push(input)
@ -86,7 +85,7 @@ impl Application for Todos {
Scrollable::new(&mut self.scroll)
.padding(40)
.push(content)
.push(Container::new(content).width(Length::Fill).center_x())
.into()
}
}

View file

@ -1,7 +1,7 @@
use iced::{
button, scrollable, slider, text::HorizontalAlignment, text_input, Align,
Application, Background, Button, Checkbox, Color, Column, Element, Image,
Justify, Length, Radio, Row, Scrollable, Slider, Text, TextInput,
Application, Background, Button, Checkbox, Color, Column, Container,
Element, Image, Length, Radio, Row, Scrollable, Slider, Text, TextInput,
};
pub fn main() {
@ -78,7 +78,7 @@ impl Application for Tour {
);
}
let element: Element<_> = Column::new()
let content: Element<_> = Column::new()
.max_width(540)
.spacing(20)
.padding(20)
@ -86,20 +86,18 @@ impl Application for Tour {
.push(controls)
.into();
let element = if self.debug {
element.explain(Color::BLACK)
let content = if self.debug {
content.explain(Color::BLACK)
} else {
element
content
};
Column::new()
let scrollable = Scrollable::new(scroll)
.push(Container::new(content).width(Length::Fill).center_x());
Container::new(scrollable)
.height(Length::Fill)
.justify_content(Justify::Center)
.push(
Scrollable::new(scroll)
.align_items(Align::Center)
.push(element),
)
.center_y()
.into()
}
}
@ -340,10 +338,7 @@ impl<'a> Step {
}
fn container(title: &str) -> Column<'a, StepMessage> {
Column::new()
.spacing(20)
.align_items(Align::Stretch)
.push(Text::new(title).size(50))
Column::new().spacing(20).push(Text::new(title).size(50))
}
fn welcome() -> Column<'a, StepMessage> {
@ -646,19 +641,22 @@ impl<'a> Step {
}
}
fn ferris(width: u16) -> Image {
// This should go away once we unify resource loading on native
// platforms
if cfg!(target_arch = "wasm32") {
Image::new("resources/ferris.png")
} else {
Image::new(format!(
"{}/examples/resources/ferris.png",
env!("CARGO_MANIFEST_DIR")
))
}
.width(Length::Units(width))
.align_self(Align::Center)
fn ferris<'a>(width: u16) -> Container<'a, StepMessage> {
Container::new(
// This should go away once we unify resource loading on native
// platforms
if cfg!(target_arch = "wasm32") {
Image::new("resources/ferris.png")
} else {
Image::new(format!(
"{}/examples/resources/ferris.png",
env!("CARGO_MANIFEST_DIR")
))
}
.width(Length::Units(width)),
)
.width(Length::Fill)
.center_x()
}
fn button<'a, Message>(