diff options
author | 2021-02-24 00:59:29 +0100 | |
---|---|---|
committer | 2021-02-24 00:59:29 +0100 | |
commit | 2736e4ca35f17a92768f0be682acf6da3b574cb6 (patch) | |
tree | c2525b87ea5d50d1241caa5c3d9e59f396418b3f | |
parent | 5e2743361bf0a2e10c0e14638a9b2818c9e5e364 (diff) | |
download | iced-2736e4ca35f17a92768f0be682acf6da3b574cb6.tar.gz iced-2736e4ca35f17a92768f0be682acf6da3b574cb6.tar.bz2 iced-2736e4ca35f17a92768f0be682acf6da3b574cb6.zip |
Hide `Text` as an implementation detail of `Tooltip`
-rw-r--r-- | examples/tooltip/src/main.rs | 6 | ||||
-rw-r--r-- | native/src/widget/tooltip.rs | 30 |
2 files changed, 25 insertions, 11 deletions
diff --git a/examples/tooltip/src/main.rs b/examples/tooltip/src/main.rs index b10b8b50..d6c8b8e1 100644 --- a/examples/tooltip/src/main.rs +++ b/examples/tooltip/src/main.rs @@ -110,11 +110,11 @@ fn tooltip<'a>( .on_press(Message) .width(Length::Fill) .height(Length::Fill), - Text::new("Tooltip"), + "Tooltip", position, ) - .gap(10) - .padding(20) + .gap(5) + .padding(10) .style(style::Tooltip) .into() } diff --git a/native/src/widget/tooltip.rs b/native/src/widget/tooltip.rs index 56559827..ab07868c 100644 --- a/native/src/widget/tooltip.rs +++ b/native/src/widget/tooltip.rs @@ -30,12 +30,12 @@ where /// [`Tooltip`]: struct.Tooltip.html pub fn new( content: impl Into<Element<'a, Message, Renderer>>, - tooltip: Text<Renderer>, + tooltip: impl ToString, position: Position, ) -> Self { Tooltip { content: content.into(), - tooltip, + tooltip: Text::new(tooltip.to_string()), position, style: Default::default(), gap: 0, @@ -43,12 +43,17 @@ where } } - /// Sets the style of the [`Tooltip`]. - pub fn style( - mut self, - style: impl Into<<Renderer as container::Renderer>::Style>, - ) -> Self { - self.style = style.into(); + /// Sets the size of the text of the [`Tooltip`]. + pub fn size(mut self, size: u16) -> Self { + self.tooltip = self.tooltip.size(size); + self + } + + /// Sets the font of the [`Tooltip`]. + /// + /// [`Font`]: Renderer::Font + pub fn font(mut self, font: impl Into<Renderer::Font>) -> Self { + self.tooltip = self.tooltip.font(font); self } @@ -63,6 +68,15 @@ where self.padding = padding; self } + + /// Sets the style of the [`Tooltip`]. + pub fn style( + mut self, + style: impl Into<<Renderer as container::Renderer>::Style>, + ) -> Self { + self.style = style.into(); + self + } } /// The position of the tooltip. Defaults to following the cursor. |