Rename text::IntoContent to IntoFragment
This commit is contained in:
parent
b8d5df2817
commit
34f799aa3d
2 changed files with 41 additions and 41 deletions
|
|
@ -21,7 +21,7 @@ where
|
||||||
Theme: Catalog,
|
Theme: Catalog,
|
||||||
Renderer: text::Renderer,
|
Renderer: text::Renderer,
|
||||||
{
|
{
|
||||||
content: Content<'a>,
|
fragment: Fragment<'a>,
|
||||||
size: Option<Pixels>,
|
size: Option<Pixels>,
|
||||||
line_height: LineHeight,
|
line_height: LineHeight,
|
||||||
width: Length,
|
width: Length,
|
||||||
|
|
@ -39,9 +39,9 @@ where
|
||||||
Renderer: text::Renderer,
|
Renderer: text::Renderer,
|
||||||
{
|
{
|
||||||
/// Create a new fragment of [`Text`] with the given contents.
|
/// Create a new fragment of [`Text`] with the given contents.
|
||||||
pub fn new(content: impl IntoContent<'a>) -> Self {
|
pub fn new(fragment: impl IntoFragment<'a>) -> Self {
|
||||||
Text {
|
Text {
|
||||||
content: content.into_content(),
|
fragment: fragment.into_fragment(),
|
||||||
size: None,
|
size: None,
|
||||||
line_height: LineHeight::default(),
|
line_height: LineHeight::default(),
|
||||||
font: None,
|
font: None,
|
||||||
|
|
@ -184,7 +184,7 @@ where
|
||||||
limits,
|
limits,
|
||||||
self.width,
|
self.width,
|
||||||
self.height,
|
self.height,
|
||||||
&self.content,
|
&self.fragment,
|
||||||
self.line_height,
|
self.line_height,
|
||||||
self.size,
|
self.size,
|
||||||
self.font,
|
self.font,
|
||||||
|
|
@ -367,66 +367,66 @@ impl Catalog for Theme {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The content of a [`Text`] widget.
|
/// A fragment of [`Text`].
|
||||||
///
|
///
|
||||||
/// This is just an alias to a string that may be either
|
/// This is just an alias to a string that may be either
|
||||||
/// borrowed or owned.
|
/// borrowed or owned.
|
||||||
pub type Content<'a> = Cow<'a, str>;
|
pub type Fragment<'a> = Cow<'a, str>;
|
||||||
|
|
||||||
/// A trait for converting a value to some text [`Content`].
|
/// A trait for converting a value to some text [`Fragment`].
|
||||||
pub trait IntoContent<'a> {
|
pub trait IntoFragment<'a> {
|
||||||
/// Converts the value to some text [`Content`].
|
/// Converts the value to some text [`Fragment`].
|
||||||
fn into_content(self) -> Content<'a>;
|
fn into_fragment(self) -> Fragment<'a>;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> IntoContent<'a> for &'a str {
|
impl<'a> IntoFragment<'a> for &'a str {
|
||||||
fn into_content(self) -> Content<'a> {
|
fn into_fragment(self) -> Fragment<'a> {
|
||||||
Content::Borrowed(self)
|
Fragment::Borrowed(self)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> IntoContent<'a> for &'a String {
|
impl<'a> IntoFragment<'a> for &'a String {
|
||||||
fn into_content(self) -> Content<'a> {
|
fn into_fragment(self) -> Fragment<'a> {
|
||||||
Content::Borrowed(self.as_str())
|
Fragment::Borrowed(self.as_str())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> IntoContent<'a> for String {
|
impl<'a> IntoFragment<'a> for String {
|
||||||
fn into_content(self) -> Content<'a> {
|
fn into_fragment(self) -> Fragment<'a> {
|
||||||
Content::Owned(self)
|
Fragment::Owned(self)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
macro_rules! into_content {
|
macro_rules! into_fragment {
|
||||||
($type:ty) => {
|
($type:ty) => {
|
||||||
impl<'a> IntoContent<'a> for $type {
|
impl<'a> IntoFragment<'a> for $type {
|
||||||
fn into_content(self) -> Content<'a> {
|
fn into_fragment(self) -> Fragment<'a> {
|
||||||
Content::Owned(self.to_string())
|
Fragment::Owned(self.to_string())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> IntoContent<'a> for &$type {
|
impl<'a> IntoFragment<'a> for &$type {
|
||||||
fn into_content(self) -> Content<'a> {
|
fn into_fragment(self) -> Fragment<'a> {
|
||||||
Content::Owned(self.to_string())
|
Fragment::Owned(self.to_string())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
into_content!(char);
|
into_fragment!(char);
|
||||||
into_content!(bool);
|
into_fragment!(bool);
|
||||||
|
|
||||||
into_content!(u8);
|
into_fragment!(u8);
|
||||||
into_content!(u16);
|
into_fragment!(u16);
|
||||||
into_content!(u32);
|
into_fragment!(u32);
|
||||||
into_content!(u64);
|
into_fragment!(u64);
|
||||||
into_content!(u128);
|
into_fragment!(u128);
|
||||||
|
|
||||||
into_content!(i8);
|
into_fragment!(i8);
|
||||||
into_content!(i16);
|
into_fragment!(i16);
|
||||||
into_content!(i32);
|
into_fragment!(i32);
|
||||||
into_content!(i64);
|
into_fragment!(i64);
|
||||||
into_content!(i128);
|
into_fragment!(i128);
|
||||||
|
|
||||||
into_content!(f32);
|
into_fragment!(f32);
|
||||||
into_content!(f64);
|
into_fragment!(f64);
|
||||||
|
|
|
||||||
|
|
@ -145,7 +145,7 @@ where
|
||||||
///
|
///
|
||||||
/// [`Text`]: core::widget::Text
|
/// [`Text`]: core::widget::Text
|
||||||
pub fn text<'a, Theme, Renderer>(
|
pub fn text<'a, Theme, Renderer>(
|
||||||
text: impl text::IntoContent<'a>,
|
text: impl text::IntoFragment<'a>,
|
||||||
) -> Text<'a, Theme, Renderer>
|
) -> Text<'a, Theme, Renderer>
|
||||||
where
|
where
|
||||||
Theme: text::Catalog + 'a,
|
Theme: text::Catalog + 'a,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue