-
Notifications
You must be signed in to change notification settings - Fork 120
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Unify Prose and Textbox with an underlying
TextRegion
(#754)
Remaining steps - [x] Update Textbox to use this - [x] Add internal padding Follow-up work: - [ ] Restore IME support - [ ] Upstream new result of PlainEditor (once other steps are complete)
- Loading branch information
Showing
22 changed files
with
1,438 additions
and
1,364 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// Copyright 2018 the Xilem Authors and the Druid Authors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
use std::{collections::HashMap, mem::Discriminant}; | ||
|
||
type StyleProperty<Brush> = parley::StyleProperty<'static, Brush>; | ||
|
||
/// A set of Parley styles. | ||
#[derive(Clone, Debug)] | ||
pub struct StyleSet<Brush: parley::Brush>( | ||
HashMap<Discriminant<StyleProperty<Brush>>, StyleProperty<Brush>>, | ||
); | ||
|
||
impl<Brush: parley::Brush> StyleSet<Brush> { | ||
pub fn new(font_size: f32) -> Self { | ||
let mut this = Self(Default::default()); | ||
this.insert(StyleProperty::FontSize(font_size)); | ||
this | ||
} | ||
|
||
pub fn insert(&mut self, style: StyleProperty<Brush>) -> Option<StyleProperty<Brush>> { | ||
let discriminant = std::mem::discriminant(&style); | ||
self.0.insert(discriminant, style) | ||
} | ||
|
||
pub fn retain(&mut self, mut f: impl FnMut(&StyleProperty<Brush>) -> bool) { | ||
self.0.retain(|_, v| f(v)); | ||
} | ||
|
||
pub fn remove( | ||
&mut self, | ||
property: Discriminant<StyleProperty<Brush>>, | ||
) -> Option<StyleProperty<Brush>> { | ||
self.0.remove(&property) | ||
} | ||
|
||
pub fn inner(&self) -> &HashMap<Discriminant<StyleProperty<Brush>>, StyleProperty<Brush>> { | ||
&self.0 | ||
} | ||
} |
Oops, something went wrong.