summaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón <hector0193@gmail.com>2019-11-14 06:46:50 +0100
committerLibravatar GitHub <noreply@github.com>2019-11-14 06:46:50 +0100
commitbc8d347736ec997ec0e0c401289e2bc09e212b8a (patch)
treeb98798c09a3aa914b7d0869fba0cfd3efff7754f /examples
parent839e039dbf2fb89dcb8c141503740777d2af2eb3 (diff)
parent73f3c900071f950ea914652ca3f0002c1e173f61 (diff)
downloadiced-bc8d347736ec997ec0e0c401289e2bc09e212b8a.tar.gz
iced-bc8d347736ec997ec0e0c401289e2bc09e212b8a.tar.bz2
iced-bc8d347736ec997ec0e0c401289e2bc09e212b8a.zip
Merge pull request #52 from hecrj/custom-layout-engine
Custom layout engine
Diffstat (limited to 'examples')
-rw-r--r--examples/scroll.rs11
-rw-r--r--examples/todos.rs9
-rw-r--r--examples/tour.rs64
3 files changed, 40 insertions, 44 deletions
diff --git a/examples/scroll.rs b/examples/scroll.rs
index 5a725f0c..50701879 100644
--- a/examples/scroll.rs
+++ b/examples/scroll.rs
@@ -1,6 +1,6 @@
use iced::{
- button, scrollable, Align, Application, Button, Column, Element, Image,
- Justify, Length, Scrollable, Text,
+ button, scrollable, Align, Application, Button, Container, Element, Image,
+ Length, Scrollable, Text,
};
pub fn main() {
@@ -65,11 +65,10 @@ impl Application for Example {
.border_radius(5),
);
- Column::new()
+ Container::new(content)
+ .width(Length::Fill)
.height(Length::Fill)
- .justify_content(Justify::Center)
- .padding(20)
- .push(content)
+ .center_y()
.into()
}
}
diff --git a/examples/todos.rs b/examples/todos.rs
index 5257fc12..7f37300b 100644
--- a/examples/todos.rs
+++ b/examples/todos.rs
@@ -1,6 +1,6 @@
use iced::{
- scrollable, text::HorizontalAlignment, text_input, Align, Application,
- Checkbox, Color, Column, Element, Length, Scrollable, Text, TextInput,
+ scrollable, text::HorizontalAlignment, text_input, Application, Checkbox,
+ Color, Column, Container, Element, Length, Scrollable, Text, TextInput,
};
pub fn main() {
@@ -77,8 +77,7 @@ impl Application for Todos {
);
let content = Column::new()
- .max_width(Length::Units(800))
- .align_self(Align::Center)
+ .max_width(800)
.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()
}
}
diff --git a/examples/tour.rs b/examples/tour.rs
index ac654a5e..3fd031b8 100644
--- a/examples/tour.rs
+++ b/examples/tour.rs
@@ -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,
+ button, scrollable, slider, text::HorizontalAlignment, text_input,
+ Application, Background, Button, Checkbox, Color, Column, Container,
+ Element, Image, Length, Radio, Row, Scrollable, Slider, Text, TextInput,
};
pub fn main() {
@@ -25,7 +25,7 @@ impl Tour {
scroll: scrollable::State::new(),
back_button: button::State::new(),
next_button: button::State::new(),
- debug: false,
+ debug: true,
}
}
}
@@ -78,28 +78,26 @@ impl Application for Tour {
);
}
- let element: Element<_> = Column::new()
- .max_width(Length::Units(540))
+ let content: Element<_> = Column::new()
+ .max_width(540)
.spacing(20)
.padding(20)
.push(steps.view(self.debug).map(Message::StepMessage))
.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>(