From 14ae4b24a7e07485bd707965b1d8493010ac6359 Mon Sep 17 00:00:00 2001 From: Yuan Chang Date: Sun, 3 Jul 2022 21:16:05 +0800 Subject: [PATCH] Support rich text convert from cow-string. (#1774) --- egui/src/widget_text.rs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/egui/src/widget_text.rs b/egui/src/widget_text.rs index f7d11b0d..df535684 100644 --- a/egui/src/widget_text.rs +++ b/egui/src/widget_text.rs @@ -1,3 +1,4 @@ +use std::borrow::Cow; use std::sync::Arc; use crate::{ @@ -65,6 +66,13 @@ impl From for RichText { } } +impl From> for RichText { + #[inline] + fn from(text: Cow<'_, str>) -> Self { + Self::new(text) + } +} + impl RichText { #[inline] pub fn new(text: impl Into) -> Self { @@ -605,6 +613,13 @@ impl From for WidgetText { } } +impl From> for WidgetText { + #[inline] + fn from(text: Cow<'_, str>) -> Self { + Self::RichText(RichText::new(text)) + } +} + impl From for WidgetText { #[inline] fn from(rich_text: RichText) -> Self {