Add push_maybe to Column and Row

This commit is contained in:
Héctor Ramón Jiménez 2024-02-15 02:38:07 +01:00
parent e57668d677
commit feab96f323
No known key found for this signature in database
GPG key ID: 7CC46565708259A7
9 changed files with 144 additions and 95 deletions

View file

@ -1,5 +1,6 @@
use iced::widget::qr_code::{self, QRCode};
use iced::widget::{column, container, pick_list, row, text, text_input};
use iced::widget::{
column, container, pick_list, qr_code, row, text, text_input,
};
use iced::{Alignment, Element, Length, Sandbox, Settings, Theme};
pub fn main() -> iced::Result {
@ -65,15 +66,16 @@ impl Sandbox for QRGenerator {
.spacing(10)
.align_items(Alignment::Center);
let mut content = column![title, input, choose_theme]
let content = column![title, input, choose_theme]
.push_maybe(
self.qr_code
.as_ref()
.map(|data| qr_code(data).cell_size(10)),
)
.width(700)
.spacing(20)
.align_items(Alignment::Center);
if let Some(qr_code) = self.qr_code.as_ref() {
content = content.push(QRCode::new(qr_code).cell_size(10));
}
container(content)
.width(Length::Fill)
.height(Length::Fill)