summaryrefslogtreecommitdiffstats
path: root/examples/modal
diff options
context:
space:
mode:
authorLibravatar Cory Forsstrom <cforsstrom18@gmail.com>2023-02-18 13:49:11 -0800
committerLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2023-06-14 09:27:28 +0200
commitf608056c5029727a9523e7a245b7118eb48caa5f (patch)
tree65873f0c150d10989d91471a99ae96b28524ca43 /examples/modal
parent0a56ffb5d6260832d27c2cae70d4b8536e000001 (diff)
downloadiced-f608056c5029727a9523e7a245b7118eb48caa5f.tar.gz
iced-f608056c5029727a9523e7a245b7118eb48caa5f.tar.bz2
iced-f608056c5029727a9523e7a245b7118eb48caa5f.zip
Add nested picklist to modal example
Diffstat (limited to 'examples/modal')
-rw-r--r--examples/modal/src/main.rs57
1 files changed, 55 insertions, 2 deletions
diff --git a/examples/modal/src/main.rs b/examples/modal/src/main.rs
index 5c43c203..7fcbbfe4 100644
--- a/examples/modal/src/main.rs
+++ b/examples/modal/src/main.rs
@@ -3,11 +3,13 @@ use iced::keyboard;
use iced::subscription::{self, Subscription};
use iced::theme;
use iced::widget::{
- self, button, column, container, horizontal_space, row, text, text_input,
+ self, button, column, container, horizontal_space, pick_list, row, text,
+ text_input,
};
use iced::{Alignment, Application, Command, Element, Event, Length, Settings};
-use self::modal::Modal;
+use modal::Modal;
+use std::fmt;
pub fn main() -> iced::Result {
App::run(Settings::default())
@@ -18,6 +20,7 @@ struct App {
show_modal: bool,
email: String,
password: String,
+ plan: Plan,
}
#[derive(Debug, Clone)]
@@ -26,6 +29,7 @@ enum Message {
HideModal,
Email(String),
Password(String),
+ Plan(Plan),
Submit,
Event(Event),
}
@@ -66,6 +70,10 @@ impl Application for App {
self.password = password;
Command::none()
}
+ Message::Plan(plan) => {
+ self.plan = plan;
+ Command::none()
+ }
Message::Submit => {
if !self.email.is_empty() && !self.password.is_empty() {
self.hide_modal();
@@ -149,6 +157,16 @@ impl Application for App {
.padding(5),
]
.spacing(5),
+ column![
+ text("Plan").size(12),
+ pick_list(
+ Plan::ALL,
+ Some(self.plan),
+ Message::Plan
+ )
+ .padding(5),
+ ]
+ .spacing(5),
button(text("Submit")).on_press(Message::HideModal),
]
.spacing(10)
@@ -176,6 +194,29 @@ impl App {
}
}
+#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
+enum Plan {
+ #[default]
+ Basic,
+ Pro,
+ Enterprise,
+}
+
+impl Plan {
+ pub const ALL: &[Self] = &[Self::Basic, Self::Pro, Self::Enterprise];
+}
+
+impl fmt::Display for Plan {
+ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
+ match self {
+ Plan::Basic => "Basic",
+ Plan::Pro => "Pro",
+ Plan::Enterprise => "Enterprise",
+ }
+ .fmt(f)
+ }
+}
+
mod modal {
use iced::advanced::layout::{self, Layout};
use iced::advanced::overlay;
@@ -469,6 +510,18 @@ mod modal {
renderer,
)
}
+
+ fn overlay<'c>(
+ &'c mut self,
+ layout: Layout<'_>,
+ renderer: &Renderer,
+ ) -> Option<overlay::Element<'c, Message, Renderer>> {
+ self.content.as_widget_mut().overlay(
+ self.tree,
+ layout.children().next().unwrap(),
+ renderer,
+ )
+ }
}
impl<'a, Message, Renderer> From<Modal<'a, Message, Renderer>>