Use text::Span::new in window_manager
This commit is contained in:
parent
c83809adb9
commit
c9abe25d31
2 changed files with 27 additions and 52 deletions
|
|
@ -270,23 +270,6 @@ pub struct Span<'a, Link = (), Font = crate::Font> {
|
||||||
pub strikethrough: bool,
|
pub strikethrough: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<Link, Font> Default for Span<'_, Link, Font> {
|
|
||||||
fn default() -> Self {
|
|
||||||
Self {
|
|
||||||
text: Cow::default(),
|
|
||||||
size: None,
|
|
||||||
line_height: None,
|
|
||||||
font: None,
|
|
||||||
color: None,
|
|
||||||
link: None,
|
|
||||||
highlight: None,
|
|
||||||
padding: Padding::default(),
|
|
||||||
underline: false,
|
|
||||||
strikethrough: false,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// A text highlight.
|
/// A text highlight.
|
||||||
#[derive(Debug, Clone, Copy, PartialEq)]
|
#[derive(Debug, Clone, Copy, PartialEq)]
|
||||||
pub struct Highlight {
|
pub struct Highlight {
|
||||||
|
|
@ -301,15 +284,7 @@ impl<'a, Link, Font> Span<'a, Link, Font> {
|
||||||
pub fn new(fragment: impl IntoFragment<'a>) -> Self {
|
pub fn new(fragment: impl IntoFragment<'a>) -> Self {
|
||||||
Self {
|
Self {
|
||||||
text: fragment.into_fragment(),
|
text: fragment.into_fragment(),
|
||||||
size: None,
|
..Self::default()
|
||||||
line_height: None,
|
|
||||||
font: None,
|
|
||||||
color: None,
|
|
||||||
highlight: None,
|
|
||||||
link: None,
|
|
||||||
padding: Padding::ZERO,
|
|
||||||
underline: false,
|
|
||||||
strikethrough: false,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -457,6 +432,23 @@ impl<'a, Link, Font> Span<'a, Link, Font> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<Link, Font> Default for Span<'_, Link, Font> {
|
||||||
|
fn default() -> Self {
|
||||||
|
Self {
|
||||||
|
text: Cow::default(),
|
||||||
|
size: None,
|
||||||
|
line_height: None,
|
||||||
|
font: None,
|
||||||
|
color: None,
|
||||||
|
link: None,
|
||||||
|
highlight: None,
|
||||||
|
padding: Padding::default(),
|
||||||
|
underline: false,
|
||||||
|
strikethrough: false,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl<'a, Link, Font> From<&'a str> for Span<'a, Link, Font> {
|
impl<'a, Link, Font> From<&'a str> for Span<'a, Link, Font> {
|
||||||
fn from(value: &'a str) -> Self {
|
fn from(value: &'a str) -> Self {
|
||||||
Span::new(value)
|
Span::new(value)
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,6 @@ use crate::program::{Program, State};
|
||||||
use winit::dpi::{LogicalPosition, LogicalSize};
|
use winit::dpi::{LogicalPosition, LogicalSize};
|
||||||
use winit::monitor::MonitorHandle;
|
use winit::monitor::MonitorHandle;
|
||||||
|
|
||||||
use std::borrow::Cow;
|
|
||||||
use std::collections::BTreeMap;
|
use std::collections::BTreeMap;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
|
|
@ -304,33 +303,17 @@ where
|
||||||
let spans = match &preedit.selection {
|
let spans = match &preedit.selection {
|
||||||
Some(selection) => {
|
Some(selection) => {
|
||||||
vec![
|
vec![
|
||||||
text::Span {
|
text::Span::new(&preedit.content[..selection.start]),
|
||||||
text: Cow::Borrowed(
|
text::Span::new(if selection.start == selection.end {
|
||||||
&preedit.content[..selection.start],
|
"\u{200A}"
|
||||||
),
|
} else {
|
||||||
..text::Span::default()
|
&preedit.content[selection.start..selection.end]
|
||||||
},
|
})
|
||||||
text::Span {
|
.color(background),
|
||||||
text: Cow::Borrowed(
|
text::Span::new(&preedit.content[selection.end..]),
|
||||||
if selection.start == selection.end {
|
|
||||||
"\u{200A}"
|
|
||||||
} else {
|
|
||||||
&preedit.content[selection.start..selection.end]
|
|
||||||
},
|
|
||||||
),
|
|
||||||
color: Some(background),
|
|
||||||
..text::Span::default()
|
|
||||||
},
|
|
||||||
text::Span {
|
|
||||||
text: Cow::Borrowed(&preedit.content[selection.end..]),
|
|
||||||
..text::Span::default()
|
|
||||||
},
|
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
_ => vec![text::Span {
|
_ => vec![text::Span::new(&preedit.content)],
|
||||||
text: Cow::Borrowed(&preedit.content),
|
|
||||||
..text::Span::default()
|
|
||||||
}],
|
|
||||||
};
|
};
|
||||||
|
|
||||||
if spans != self.spans.as_slice() {
|
if spans != self.spans.as_slice() {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue