summaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2022-05-04 17:19:28 +0200
committerLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2022-05-04 17:19:28 +0200
commit27fdc707562d4e229f07ed9496ed5d64f4e108bc (patch)
tree8a87286f0ccd125df1c2b5c597c2d2805ceb27c5 /examples
parenta97c520c814a6d3cc538537791be39e0c3182d6d (diff)
parent02914e5e68d1fbaad53483cd32c74d9ac448d1eb (diff)
downloadiced-27fdc707562d4e229f07ed9496ed5d64f4e108bc.tar.gz
iced-27fdc707562d4e229f07ed9496ed5d64f4e108bc.tar.bz2
iced-27fdc707562d4e229f07ed9496ed5d64f4e108bc.zip
Merge branch 'master' into dev/system-information
Diffstat (limited to 'examples')
-rw-r--r--examples/pure/tooltip/Cargo.toml9
-rw-r--r--examples/pure/tooltip/src/main.rs93
2 files changed, 102 insertions, 0 deletions
diff --git a/examples/pure/tooltip/Cargo.toml b/examples/pure/tooltip/Cargo.toml
new file mode 100644
index 00000000..d84dfb37
--- /dev/null
+++ b/examples/pure/tooltip/Cargo.toml
@@ -0,0 +1,9 @@
+[package]
+name = "pure_tooltip"
+version = "0.1.0"
+authors = ["Héctor Ramón Jiménez <hector0193@gmail.com>", "Casper Rogild Storm"]
+edition = "2021"
+publish = false
+
+[dependencies]
+iced = { path = "../../..", features = ["pure"] }
diff --git a/examples/pure/tooltip/src/main.rs b/examples/pure/tooltip/src/main.rs
new file mode 100644
index 00000000..dbd83f5f
--- /dev/null
+++ b/examples/pure/tooltip/src/main.rs
@@ -0,0 +1,93 @@
+use iced::pure::{
+ button, container, tooltip, widget::tooltip::Position, Element, Sandbox,
+};
+use iced::{Length, Settings};
+
+pub fn main() -> iced::Result {
+ Example::run(Settings::default())
+}
+
+struct Example {
+ position: Position,
+}
+
+#[derive(Debug, Clone)]
+enum Message {
+ ChangePosition,
+}
+
+impl Sandbox for Example {
+ type Message = Message;
+
+ fn new() -> Self {
+ Self {
+ position: Position::Bottom,
+ }
+ }
+
+ fn title(&self) -> String {
+ String::from("Tooltip - Iced")
+ }
+
+ fn update(&mut self, message: Message) {
+ match message {
+ Message::ChangePosition => {
+ let position = match &self.position {
+ Position::FollowCursor => Position::Top,
+ Position::Top => Position::Bottom,
+ Position::Bottom => Position::Left,
+ Position::Left => Position::Right,
+ Position::Right => Position::FollowCursor,
+ };
+
+ self.position = position
+ }
+ }
+ }
+
+ fn view(&self) -> Element<Message> {
+ let tooltip = tooltip(
+ button("Press to change position")
+ .on_press(Message::ChangePosition),
+ position_to_text(self.position),
+ self.position,
+ )
+ .gap(10)
+ .style(style::Tooltip);
+
+ container(tooltip)
+ .width(Length::Fill)
+ .height(Length::Fill)
+ .center_x()
+ .center_y()
+ .into()
+ }
+}
+
+fn position_to_text<'a>(position: Position) -> &'a str {
+ match position {
+ Position::FollowCursor => "Follow Cursor",
+ Position::Top => "Top",
+ Position::Bottom => "Bottom",
+ Position::Left => "Left",
+ Position::Right => "Right",
+ }
+}
+
+mod style {
+ use iced::container;
+ use iced::Color;
+
+ pub struct Tooltip;
+
+ impl container::StyleSheet for Tooltip {
+ fn style(&self) -> container::Style {
+ container::Style {
+ text_color: Some(Color::from_rgb8(0xEE, 0xEE, 0xEE)),
+ background: Some(Color::from_rgb(0.11, 0.42, 0.87).into()),
+ border_radius: 12.0,
+ ..container::Style::default()
+ }
+ }
+ }
+}