ferrix_app/modals.rs
1/* modals.rs
2 *
3 * Copyright 2025 Michail Krasnov <mskrasnov07@ya.ru>
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <https://www.gnu.org/licenses/>.
17 *
18 * SPDX-License-Identifier: GPL-3.0-or-later
19 */
20
21use iced::Alignment::Center;
22use iced::widget::text::IntoFragment;
23use iced::widget::{button, column, container, row, space, stack, text};
24use iced::{Color, Element, Padding};
25
26use crate::fl;
27use crate::messages::{ButtonsMessage, Message};
28
29pub fn toast<'a>(
30 base: impl Into<Element<'a, Message>>,
31 content: impl IntoFragment<'a>,
32) -> Element<'a, Message> {
33 let toast = container(
34 row![
35 text(content).style(|t: &iced::Theme| text::Style {
36 color: Some(if t.extended_palette().is_dark {
37 t.palette().text
38 } else {
39 Color::WHITE
40 })
41 }),
42 button(text(fl!("toast-close")))
43 .on_press(Message::Buttons(ButtonsMessage::ShowToastToggle))
44 .style(button::subtle)
45 .padding(2),
46 ]
47 .align_y(Center)
48 .spacing(8),
49 )
50 .style(|t| container::Style {
51 background: Some(
52 Color {
53 a: 0.9,
54 ..Color::BLACK
55 }
56 .into(),
57 ),
58 ..container::rounded_box(t)
59 })
60 .padding(5);
61
62 stack![
63 base.into(),
64 column![
65 space::vertical(),
66 row![space::horizontal(), toast, space::horizontal()]
67 .padding(Padding::new(0.).bottom(8.)),
68 ],
69 ]
70 .into()
71}