Take Cow in Text::new
This commit is contained in:
parent
f15bc3ca34
commit
ce3b89639d
6 changed files with 26 additions and 22 deletions
|
|
@ -469,7 +469,7 @@ const ICONS: Font = Font::External {
|
||||||
bytes: include_bytes!("../../todos/fonts/icons.ttf"),
|
bytes: include_bytes!("../../todos/fonts/icons.ttf"),
|
||||||
};
|
};
|
||||||
|
|
||||||
fn icon(unicode: char) -> Text {
|
fn icon(unicode: char) -> Text<'static> {
|
||||||
text(unicode.to_string())
|
text(unicode.to_string())
|
||||||
.font(ICONS)
|
.font(ICONS)
|
||||||
.width(Length::Units(20))
|
.width(Length::Units(20))
|
||||||
|
|
@ -477,11 +477,11 @@ fn icon(unicode: char) -> Text {
|
||||||
.size(20)
|
.size(20)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn edit_icon() -> Text {
|
fn edit_icon() -> Text<'static> {
|
||||||
icon('\u{F303}')
|
icon('\u{F303}')
|
||||||
}
|
}
|
||||||
|
|
||||||
fn delete_icon() -> Text {
|
fn delete_icon() -> Text<'static> {
|
||||||
icon('\u{F1F8}')
|
icon('\u{F1F8}')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -91,7 +91,7 @@ impl<'a, Message, Renderer> Element<'a, Message, Renderer> {
|
||||||
///
|
///
|
||||||
/// ```
|
/// ```
|
||||||
/// # mod counter {
|
/// # mod counter {
|
||||||
/// # type Text = iced_native::widget::Text<iced_native::renderer::Null>;
|
/// # type Text<'a> = iced_native::widget::Text<'a, iced_native::renderer::Null>;
|
||||||
/// #
|
/// #
|
||||||
/// # #[derive(Debug, Clone, Copy)]
|
/// # #[derive(Debug, Clone, Copy)]
|
||||||
/// # pub enum Message {}
|
/// # pub enum Message {}
|
||||||
|
|
|
||||||
|
|
@ -101,18 +101,18 @@ where
|
||||||
Renderer: crate::text::Renderer,
|
Renderer: crate::text::Renderer,
|
||||||
Renderer::Theme: widget::container::StyleSheet + widget::text::StyleSheet,
|
Renderer::Theme: widget::container::StyleSheet + widget::text::StyleSheet,
|
||||||
{
|
{
|
||||||
widget::Tooltip::new(content, tooltip, position)
|
widget::Tooltip::new(content, tooltip.to_string(), position)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Creates a new [`Text`] widget with the provided content.
|
/// Creates a new [`Text`] widget with the provided content.
|
||||||
///
|
///
|
||||||
/// [`Text`]: widget::Text
|
/// [`Text`]: widget::Text
|
||||||
pub fn text<Renderer>(text: impl ToString) -> widget::Text<Renderer>
|
pub fn text<'a, Renderer>(text: impl ToString) -> widget::Text<'a, Renderer>
|
||||||
where
|
where
|
||||||
Renderer: crate::text::Renderer,
|
Renderer: crate::text::Renderer,
|
||||||
Renderer::Theme: widget::text::StyleSheet,
|
Renderer::Theme: widget::text::StyleSheet,
|
||||||
{
|
{
|
||||||
widget::Text::new(text)
|
widget::Text::new(text.to_string())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Creates a new [`Checkbox`].
|
/// Creates a new [`Checkbox`].
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,8 @@ use crate::text;
|
||||||
use crate::widget::Tree;
|
use crate::widget::Tree;
|
||||||
use crate::{Element, Layout, Length, Point, Rectangle, Size, Widget};
|
use crate::{Element, Layout, Length, Point, Rectangle, Size, Widget};
|
||||||
|
|
||||||
|
use std::borrow::Cow;
|
||||||
|
|
||||||
pub use iced_style::text::{Appearance, StyleSheet};
|
pub use iced_style::text::{Appearance, StyleSheet};
|
||||||
|
|
||||||
/// A paragraph of text.
|
/// A paragraph of text.
|
||||||
|
|
@ -15,7 +17,7 @@ pub use iced_style::text::{Appearance, StyleSheet};
|
||||||
/// ```
|
/// ```
|
||||||
/// # use iced_native::Color;
|
/// # use iced_native::Color;
|
||||||
/// #
|
/// #
|
||||||
/// # type Text = iced_native::widget::Text<iced_native::renderer::Null>;
|
/// # type Text<'a> = iced_native::widget::Text<'a, iced_native::renderer::Null>;
|
||||||
/// #
|
/// #
|
||||||
/// Text::new("I <3 iced!")
|
/// Text::new("I <3 iced!")
|
||||||
/// .size(40)
|
/// .size(40)
|
||||||
|
|
@ -24,12 +26,12 @@ pub use iced_style::text::{Appearance, StyleSheet};
|
||||||
///
|
///
|
||||||
/// 
|
/// 
|
||||||
#[allow(missing_debug_implementations)]
|
#[allow(missing_debug_implementations)]
|
||||||
pub struct Text<Renderer>
|
pub struct Text<'a, Renderer>
|
||||||
where
|
where
|
||||||
Renderer: text::Renderer,
|
Renderer: text::Renderer,
|
||||||
Renderer::Theme: StyleSheet,
|
Renderer::Theme: StyleSheet,
|
||||||
{
|
{
|
||||||
content: String,
|
content: Cow<'a, str>,
|
||||||
size: Option<u16>,
|
size: Option<u16>,
|
||||||
width: Length,
|
width: Length,
|
||||||
height: Length,
|
height: Length,
|
||||||
|
|
@ -39,15 +41,15 @@ where
|
||||||
style: <Renderer::Theme as StyleSheet>::Style,
|
style: <Renderer::Theme as StyleSheet>::Style,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<Renderer> Text<Renderer>
|
impl<'a, Renderer> Text<'a, Renderer>
|
||||||
where
|
where
|
||||||
Renderer: text::Renderer,
|
Renderer: text::Renderer,
|
||||||
Renderer::Theme: StyleSheet,
|
Renderer::Theme: StyleSheet,
|
||||||
{
|
{
|
||||||
/// Create a new fragment of [`Text`] with the given contents.
|
/// Create a new fragment of [`Text`] with the given contents.
|
||||||
pub fn new<T: ToString>(label: T) -> Self {
|
pub fn new(content: impl Into<Cow<'a, str>>) -> Self {
|
||||||
Text {
|
Text {
|
||||||
content: label.to_string(),
|
content: content.into(),
|
||||||
size: None,
|
size: None,
|
||||||
font: Default::default(),
|
font: Default::default(),
|
||||||
width: Length::Shrink,
|
width: Length::Shrink,
|
||||||
|
|
@ -112,7 +114,7 @@ where
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<Message, Renderer> Widget<Message, Renderer> for Text<Renderer>
|
impl<'a, Message, Renderer> Widget<Message, Renderer> for Text<'a, Renderer>
|
||||||
where
|
where
|
||||||
Renderer: text::Renderer,
|
Renderer: text::Renderer,
|
||||||
Renderer::Theme: StyleSheet,
|
Renderer::Theme: StyleSheet,
|
||||||
|
|
@ -216,18 +218,18 @@ pub fn draw<Renderer>(
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, Message, Renderer> From<Text<Renderer>>
|
impl<'a, Message, Renderer> From<Text<'a, Renderer>>
|
||||||
for Element<'a, Message, Renderer>
|
for Element<'a, Message, Renderer>
|
||||||
where
|
where
|
||||||
Renderer: text::Renderer + 'a,
|
Renderer: text::Renderer + 'a,
|
||||||
Renderer::Theme: StyleSheet,
|
Renderer::Theme: StyleSheet,
|
||||||
{
|
{
|
||||||
fn from(text: Text<Renderer>) -> Element<'a, Message, Renderer> {
|
fn from(text: Text<'a, Renderer>) -> Element<'a, Message, Renderer> {
|
||||||
Element::new(text)
|
Element::new(text)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<Renderer> Clone for Text<Renderer>
|
impl<'a, Renderer> Clone for Text<'a, Renderer>
|
||||||
where
|
where
|
||||||
Renderer: text::Renderer,
|
Renderer: text::Renderer,
|
||||||
Renderer::Theme: StyleSheet,
|
Renderer::Theme: StyleSheet,
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,8 @@ use crate::{
|
||||||
Shell, Size, Vector, Widget,
|
Shell, Size, Vector, Widget,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
use std::borrow::Cow;
|
||||||
|
|
||||||
/// An element to display a widget over another.
|
/// An element to display a widget over another.
|
||||||
#[allow(missing_debug_implementations)]
|
#[allow(missing_debug_implementations)]
|
||||||
pub struct Tooltip<'a, Message, Renderer: text::Renderer>
|
pub struct Tooltip<'a, Message, Renderer: text::Renderer>
|
||||||
|
|
@ -21,7 +23,7 @@ where
|
||||||
Renderer::Theme: container::StyleSheet + widget::text::StyleSheet,
|
Renderer::Theme: container::StyleSheet + widget::text::StyleSheet,
|
||||||
{
|
{
|
||||||
content: Element<'a, Message, Renderer>,
|
content: Element<'a, Message, Renderer>,
|
||||||
tooltip: Text<Renderer>,
|
tooltip: Text<'a, Renderer>,
|
||||||
position: Position,
|
position: Position,
|
||||||
gap: u16,
|
gap: u16,
|
||||||
padding: u16,
|
padding: u16,
|
||||||
|
|
@ -42,12 +44,12 @@ where
|
||||||
/// [`Tooltip`]: struct.Tooltip.html
|
/// [`Tooltip`]: struct.Tooltip.html
|
||||||
pub fn new(
|
pub fn new(
|
||||||
content: impl Into<Element<'a, Message, Renderer>>,
|
content: impl Into<Element<'a, Message, Renderer>>,
|
||||||
tooltip: impl ToString,
|
tooltip: impl Into<Cow<'a, str>>,
|
||||||
position: Position,
|
position: Position,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
Tooltip {
|
Tooltip {
|
||||||
content: content.into(),
|
content: content.into(),
|
||||||
tooltip: Text::new(tooltip.to_string()),
|
tooltip: Text::new(tooltip),
|
||||||
position,
|
position,
|
||||||
gap: 0,
|
gap: 0,
|
||||||
padding: Self::DEFAULT_PADDING,
|
padding: Self::DEFAULT_PADDING,
|
||||||
|
|
|
||||||
|
|
@ -16,8 +16,8 @@ pub mod text {
|
||||||
pub use iced_native::widget::text::{Appearance, StyleSheet};
|
pub use iced_native::widget::text::{Appearance, StyleSheet};
|
||||||
|
|
||||||
/// A paragraph of text.
|
/// A paragraph of text.
|
||||||
pub type Text<Renderer = crate::Renderer> =
|
pub type Text<'a, Renderer = crate::Renderer> =
|
||||||
iced_native::widget::Text<Renderer>;
|
iced_native::widget::Text<'a, Renderer>;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub mod button {
|
pub mod button {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue