Browse Source

Support rich text convert from cow-string. (#1774)

pull/1793/head
Yuan Chang 2 years ago
committed by GitHub
parent
commit
14ae4b24a7
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 15
      egui/src/widget_text.rs

15
egui/src/widget_text.rs

@ -1,3 +1,4 @@
use std::borrow::Cow;
use std::sync::Arc; use std::sync::Arc;
use crate::{ use crate::{
@ -65,6 +66,13 @@ impl From<String> for RichText {
} }
} }
impl From<Cow<'_, str>> for RichText {
#[inline]
fn from(text: Cow<'_, str>) -> Self {
Self::new(text)
}
}
impl RichText { impl RichText {
#[inline] #[inline]
pub fn new(text: impl Into<String>) -> Self { pub fn new(text: impl Into<String>) -> Self {
@ -605,6 +613,13 @@ impl From<String> for WidgetText {
} }
} }
impl From<Cow<'_, str>> for WidgetText {
#[inline]
fn from(text: Cow<'_, str>) -> Self {
Self::RichText(RichText::new(text))
}
}
impl From<RichText> for WidgetText { impl From<RichText> for WidgetText {
#[inline] #[inline]
fn from(rich_text: RichText) -> Self { fn from(rich_text: RichText) -> Self {

Loading…
Cancel
Save