Remove monospaced from attrs
This commit is contained in:
parent
521acb64e0
commit
3c7dc1f657
5 changed files with 17 additions and 29 deletions
|
|
@ -131,9 +131,7 @@ impl Application for Window {
|
||||||
type Theme = Theme;
|
type Theme = Theme;
|
||||||
|
|
||||||
fn new(_flags: ()) -> (Self, Command<Self::Message>) {
|
fn new(_flags: ()) -> (Self, Command<Self::Message>) {
|
||||||
let attrs = cosmic_text::Attrs::new()
|
let attrs = cosmic_text::Attrs::new().family(cosmic_text::Family::Monospace);
|
||||||
.monospaced(true)
|
|
||||||
.family(cosmic_text::Family::Monospace);
|
|
||||||
|
|
||||||
let mut editor = SyntaxEditor::new(
|
let mut editor = SyntaxEditor::new(
|
||||||
Buffer::new(
|
Buffer::new(
|
||||||
|
|
@ -225,14 +223,11 @@ impl Application for Window {
|
||||||
update_attrs(&mut *editor, self.attrs);
|
update_attrs(&mut *editor, self.attrs);
|
||||||
}
|
}
|
||||||
Message::Monospaced(monospaced) => {
|
Message::Monospaced(monospaced) => {
|
||||||
self.attrs = self
|
self.attrs = self.attrs.family(if monospaced {
|
||||||
.attrs
|
cosmic_text::Family::Monospace
|
||||||
.family(if monospaced {
|
} else {
|
||||||
cosmic_text::Family::Monospace
|
cosmic_text::Family::SansSerif
|
||||||
} else {
|
});
|
||||||
cosmic_text::Family::SansSerif
|
|
||||||
})
|
|
||||||
.monospaced(monospaced);
|
|
||||||
|
|
||||||
let mut editor = self.editor.lock().unwrap();
|
let mut editor = self.editor.lock().unwrap();
|
||||||
update_attrs(&mut *editor, self.attrs);
|
update_attrs(&mut *editor, self.attrs);
|
||||||
|
|
@ -331,7 +326,11 @@ impl Application for Window {
|
||||||
Message::Italic
|
Message::Italic
|
||||||
),
|
),
|
||||||
text("Monospaced:"),
|
text("Monospaced:"),
|
||||||
toggler(None, self.attrs.monospaced, Message::Monospaced),
|
toggler(
|
||||||
|
None,
|
||||||
|
self.attrs.family == cosmic_text::Family::Monospace,
|
||||||
|
Message::Monospaced
|
||||||
|
),
|
||||||
text("Theme:"),
|
text("Theme:"),
|
||||||
theme_picker,
|
theme_picker,
|
||||||
text("Font Size:"),
|
text("Font Size:"),
|
||||||
|
|
|
||||||
|
|
@ -227,7 +227,9 @@ where
|
||||||
|
|
||||||
// Scale metrics
|
// Scale metrics
|
||||||
let metrics = editor.buffer().metrics();
|
let metrics = editor.buffer().metrics();
|
||||||
editor.buffer_mut().set_metrics(metrics.scale(style.scale_factor as f32));
|
editor
|
||||||
|
.buffer_mut()
|
||||||
|
.set_metrics(metrics.scale(style.scale_factor as f32));
|
||||||
|
|
||||||
// Set size
|
// Set size
|
||||||
editor.buffer_mut().set_size(image_w as f32, image_h as f32);
|
editor.buffer_mut().set_size(image_w as f32, image_h as f32);
|
||||||
|
|
|
||||||
|
|
@ -73,7 +73,7 @@ fn main() {
|
||||||
.buffer_mut()
|
.buffer_mut()
|
||||||
.set_size(window.width() as f32 - line_x * 2.0, window.height() as f32);
|
.set_size(window.width() as f32 - line_x * 2.0, window.height() as f32);
|
||||||
|
|
||||||
let attrs = Attrs::new().monospaced(true).family(Family::Monospace);
|
let attrs = Attrs::new().family(Family::Monospace);
|
||||||
match editor.load_text(&path, attrs) {
|
match editor.load_text(&path, attrs) {
|
||||||
Ok(()) => (),
|
Ok(()) => (),
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
|
|
|
||||||
|
|
@ -49,7 +49,7 @@ fn main() {
|
||||||
|
|
||||||
let attrs = Attrs::new();
|
let attrs = Attrs::new();
|
||||||
let serif_attrs = attrs.family(Family::Serif);
|
let serif_attrs = attrs.family(Family::Serif);
|
||||||
let mono_attrs = attrs.monospaced(true).family(Family::Monospace);
|
let mono_attrs = attrs.family(Family::Monospace);
|
||||||
let comic_attrs = attrs.family(Family::Name("Comic Neue"));
|
let comic_attrs = attrs.family(Family::Name("Comic Neue"));
|
||||||
|
|
||||||
editor.buffer_mut().lines.clear();
|
editor.buffer_mut().lines.clear();
|
||||||
|
|
|
||||||
15
src/attrs.rs
15
src/attrs.rs
|
|
@ -93,7 +93,6 @@ pub struct Attrs<'a> {
|
||||||
//TODO: should this be an option?
|
//TODO: should this be an option?
|
||||||
pub color_opt: Option<Color>,
|
pub color_opt: Option<Color>,
|
||||||
pub family: Family<'a>,
|
pub family: Family<'a>,
|
||||||
pub monospaced: bool,
|
|
||||||
pub stretch: Stretch,
|
pub stretch: Stretch,
|
||||||
pub style: Style,
|
pub style: Style,
|
||||||
pub weight: Weight,
|
pub weight: Weight,
|
||||||
|
|
@ -108,7 +107,6 @@ impl<'a> Attrs<'a> {
|
||||||
Self {
|
Self {
|
||||||
color_opt: None,
|
color_opt: None,
|
||||||
family: Family::SansSerif,
|
family: Family::SansSerif,
|
||||||
monospaced: false,
|
|
||||||
stretch: Stretch::Normal,
|
stretch: Stretch::Normal,
|
||||||
style: Style::Normal,
|
style: Style::Normal,
|
||||||
weight: Weight::NORMAL,
|
weight: Weight::NORMAL,
|
||||||
|
|
@ -128,12 +126,6 @@ impl<'a> Attrs<'a> {
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Set monospaced
|
|
||||||
pub fn monospaced(mut self, monospaced: bool) -> Self {
|
|
||||||
self.monospaced = monospaced;
|
|
||||||
self
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Set [Stretch]
|
/// Set [Stretch]
|
||||||
pub fn stretch(mut self, stretch: Stretch) -> Self {
|
pub fn stretch(mut self, stretch: Stretch) -> Self {
|
||||||
self.stretch = stretch;
|
self.stretch = stretch;
|
||||||
|
|
@ -164,14 +156,12 @@ impl<'a> Attrs<'a> {
|
||||||
face.post_script_name.contains("Emoji")
|
face.post_script_name.contains("Emoji")
|
||||||
|| (face.style == self.style
|
|| (face.style == self.style
|
||||||
&& face.weight == self.weight
|
&& face.weight == self.weight
|
||||||
&& face.stretch == self.stretch
|
&& face.stretch == self.stretch)
|
||||||
&& face.monospaced == self.monospaced)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Check if this set of attributes can be shaped with another
|
/// Check if this set of attributes can be shaped with another
|
||||||
pub fn compatible(&self, other: &Self) -> bool {
|
pub fn compatible(&self, other: &Self) -> bool {
|
||||||
self.family == other.family
|
self.family == other.family
|
||||||
&& self.monospaced == other.monospaced
|
|
||||||
&& self.stretch == other.stretch
|
&& self.stretch == other.stretch
|
||||||
&& self.style == other.style
|
&& self.style == other.style
|
||||||
&& self.weight == other.weight
|
&& self.weight == other.weight
|
||||||
|
|
@ -184,7 +174,6 @@ pub struct AttrsOwned {
|
||||||
//TODO: should this be an option?
|
//TODO: should this be an option?
|
||||||
pub color_opt: Option<Color>,
|
pub color_opt: Option<Color>,
|
||||||
pub family_owned: FamilyOwned,
|
pub family_owned: FamilyOwned,
|
||||||
pub monospaced: bool,
|
|
||||||
pub stretch: Stretch,
|
pub stretch: Stretch,
|
||||||
pub style: Style,
|
pub style: Style,
|
||||||
pub weight: Weight,
|
pub weight: Weight,
|
||||||
|
|
@ -196,7 +185,6 @@ impl AttrsOwned {
|
||||||
Self {
|
Self {
|
||||||
color_opt: attrs.color_opt,
|
color_opt: attrs.color_opt,
|
||||||
family_owned: FamilyOwned::new(attrs.family),
|
family_owned: FamilyOwned::new(attrs.family),
|
||||||
monospaced: attrs.monospaced,
|
|
||||||
stretch: attrs.stretch,
|
stretch: attrs.stretch,
|
||||||
style: attrs.style,
|
style: attrs.style,
|
||||||
weight: attrs.weight,
|
weight: attrs.weight,
|
||||||
|
|
@ -208,7 +196,6 @@ impl AttrsOwned {
|
||||||
Attrs {
|
Attrs {
|
||||||
color_opt: self.color_opt,
|
color_opt: self.color_opt,
|
||||||
family: self.family_owned.as_family(),
|
family: self.family_owned.as_family(),
|
||||||
monospaced: self.monospaced,
|
|
||||||
stretch: self.stretch,
|
stretch: self.stretch,
|
||||||
style: self.style,
|
style: self.style,
|
||||||
weight: self.weight,
|
weight: self.weight,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue