Add max_width to Column in iced_pure
This commit is contained in:
parent
4c61601aa3
commit
09c96a6d81
2 changed files with 23 additions and 2 deletions
|
|
@ -3,11 +3,18 @@ use iced::pure::widget::{
|
||||||
button, checkbox, column, container, row, scrollable, text, text_input,
|
button, checkbox, column, container, row, scrollable, text, text_input,
|
||||||
};
|
};
|
||||||
use iced::pure::{Application, Element, Text};
|
use iced::pure::{Application, Element, Text};
|
||||||
|
use iced::window;
|
||||||
use iced::{Command, Font, Length, Settings};
|
use iced::{Command, Font, Length, Settings};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
pub fn main() -> iced::Result {
|
pub fn main() -> iced::Result {
|
||||||
Todos::run(Settings::default())
|
Todos::run(Settings {
|
||||||
|
window: window::Settings {
|
||||||
|
size: (500, 800),
|
||||||
|
..window::Settings::default()
|
||||||
|
},
|
||||||
|
..Settings::default()
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
|
|
@ -184,6 +191,7 @@ impl Application for Todos {
|
||||||
|
|
||||||
let content = column()
|
let content = column()
|
||||||
.spacing(20)
|
.spacing(20)
|
||||||
|
.max_width(800)
|
||||||
.push(title)
|
.push(title)
|
||||||
.push(input)
|
.push(input)
|
||||||
.push(controls)
|
.push(controls)
|
||||||
|
|
|
||||||
|
|
@ -10,12 +10,14 @@ use iced_native::{
|
||||||
};
|
};
|
||||||
|
|
||||||
use std::any::{self, Any};
|
use std::any::{self, Any};
|
||||||
|
use std::u32;
|
||||||
|
|
||||||
pub struct Column<'a, Message, Renderer> {
|
pub struct Column<'a, Message, Renderer> {
|
||||||
spacing: u16,
|
spacing: u16,
|
||||||
padding: Padding,
|
padding: Padding,
|
||||||
width: Length,
|
width: Length,
|
||||||
height: Length,
|
height: Length,
|
||||||
|
max_width: u32,
|
||||||
align_items: Alignment,
|
align_items: Alignment,
|
||||||
children: Vec<Element<'a, Message, Renderer>>,
|
children: Vec<Element<'a, Message, Renderer>>,
|
||||||
}
|
}
|
||||||
|
|
@ -33,6 +35,7 @@ impl<'a, Message, Renderer> Column<'a, Message, Renderer> {
|
||||||
padding: Padding::ZERO,
|
padding: Padding::ZERO,
|
||||||
width: Length::Shrink,
|
width: Length::Shrink,
|
||||||
height: Length::Shrink,
|
height: Length::Shrink,
|
||||||
|
max_width: u32::MAX,
|
||||||
align_items: Alignment::Start,
|
align_items: Alignment::Start,
|
||||||
children,
|
children,
|
||||||
}
|
}
|
||||||
|
|
@ -58,6 +61,12 @@ impl<'a, Message, Renderer> Column<'a, Message, Renderer> {
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Sets the maximum width of the [`Column`].
|
||||||
|
pub fn max_width(mut self, max_width: u32) -> Self {
|
||||||
|
self.max_width = max_width;
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
pub fn align_items(mut self, align: Alignment) -> Self {
|
pub fn align_items(mut self, align: Alignment) -> Self {
|
||||||
self.align_items = align;
|
self.align_items = align;
|
||||||
self
|
self
|
||||||
|
|
@ -106,7 +115,10 @@ where
|
||||||
renderer: &Renderer,
|
renderer: &Renderer,
|
||||||
limits: &layout::Limits,
|
limits: &layout::Limits,
|
||||||
) -> layout::Node {
|
) -> layout::Node {
|
||||||
let limits = limits.width(self.width).height(self.height);
|
let limits = limits
|
||||||
|
.max_width(self.max_width)
|
||||||
|
.width(self.width)
|
||||||
|
.height(self.height);
|
||||||
|
|
||||||
flex::resolve(
|
flex::resolve(
|
||||||
flex::Axis::Vertical,
|
flex::Axis::Vertical,
|
||||||
|
|
@ -204,6 +216,7 @@ where
|
||||||
self.tag().hash(state);
|
self.tag().hash(state);
|
||||||
self.width.hash(state);
|
self.width.hash(state);
|
||||||
self.height.hash(state);
|
self.height.hash(state);
|
||||||
|
self.max_width.hash(state);
|
||||||
self.align_items.hash(state);
|
self.align_items.hash(state);
|
||||||
self.spacing.hash(state);
|
self.spacing.hash(state);
|
||||||
self.padding.hash(state);
|
self.padding.hash(state);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue