Skip to content

Commit c9abe25

Browse files
committed
Use text::Span::new in window_manager
1 parent c83809a commit c9abe25

File tree

2 files changed

+27
-52
lines changed

2 files changed

+27
-52
lines changed

core/src/text.rs

+18-26
Original file line numberDiff line numberDiff line change
@@ -270,23 +270,6 @@ pub struct Span<'a, Link = (), Font = crate::Font> {
270270
pub strikethrough: bool,
271271
}
272272

273-
impl<Link, Font> Default for Span<'_, Link, Font> {
274-
fn default() -> Self {
275-
Self {
276-
text: Cow::default(),
277-
size: None,
278-
line_height: None,
279-
font: None,
280-
color: None,
281-
link: None,
282-
highlight: None,
283-
padding: Padding::default(),
284-
underline: false,
285-
strikethrough: false,
286-
}
287-
}
288-
}
289-
290273
/// A text highlight.
291274
#[derive(Debug, Clone, Copy, PartialEq)]
292275
pub struct Highlight {
@@ -301,15 +284,7 @@ impl<'a, Link, Font> Span<'a, Link, Font> {
301284
pub fn new(fragment: impl IntoFragment<'a>) -> Self {
302285
Self {
303286
text: fragment.into_fragment(),
304-
size: None,
305-
line_height: None,
306-
font: None,
307-
color: None,
308-
highlight: None,
309-
link: None,
310-
padding: Padding::ZERO,
311-
underline: false,
312-
strikethrough: false,
287+
..Self::default()
313288
}
314289
}
315290

@@ -457,6 +432,23 @@ impl<'a, Link, Font> Span<'a, Link, Font> {
457432
}
458433
}
459434

435+
impl<Link, Font> Default for Span<'_, Link, Font> {
436+
fn default() -> Self {
437+
Self {
438+
text: Cow::default(),
439+
size: None,
440+
line_height: None,
441+
font: None,
442+
color: None,
443+
link: None,
444+
highlight: None,
445+
padding: Padding::default(),
446+
underline: false,
447+
strikethrough: false,
448+
}
449+
}
450+
}
451+
460452
impl<'a, Link, Font> From<&'a str> for Span<'a, Link, Font> {
461453
fn from(value: &'a str) -> Self {
462454
Span::new(value)

winit/src/program/window_manager.rs

+9-26
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ use crate::program::{Program, State};
1616
use winit::dpi::{LogicalPosition, LogicalSize};
1717
use winit::monitor::MonitorHandle;
1818

19-
use std::borrow::Cow;
2019
use std::collections::BTreeMap;
2120
use std::sync::Arc;
2221

@@ -304,33 +303,17 @@ where
304303
let spans = match &preedit.selection {
305304
Some(selection) => {
306305
vec![
307-
text::Span {
308-
text: Cow::Borrowed(
309-
&preedit.content[..selection.start],
310-
),
311-
..text::Span::default()
312-
},
313-
text::Span {
314-
text: Cow::Borrowed(
315-
if selection.start == selection.end {
316-
"\u{200A}"
317-
} else {
318-
&preedit.content[selection.start..selection.end]
319-
},
320-
),
321-
color: Some(background),
322-
..text::Span::default()
323-
},
324-
text::Span {
325-
text: Cow::Borrowed(&preedit.content[selection.end..]),
326-
..text::Span::default()
327-
},
306+
text::Span::new(&preedit.content[..selection.start]),
307+
text::Span::new(if selection.start == selection.end {
308+
"\u{200A}"
309+
} else {
310+
&preedit.content[selection.start..selection.end]
311+
})
312+
.color(background),
313+
text::Span::new(&preedit.content[selection.end..]),
328314
]
329315
}
330-
_ => vec![text::Span {
331-
text: Cow::Borrowed(&preedit.content),
332-
..text::Span::default()
333-
}],
316+
_ => vec![text::Span::new(&preedit.content)],
334317
};
335318

336319
if spans != self.spans.as_slice() {

0 commit comments

Comments
 (0)