Merge pull request #425 from Aquilesorei/master
Refactor: Extract monospace_attrs() helper to eliminate code duplication
This commit is contained in:
commit
0d84055362
3 changed files with 10 additions and 7 deletions
|
|
@ -1,5 +1,5 @@
|
||||||
use cosmic_text::{
|
use cosmic_text::{
|
||||||
Align, Attrs, AttrsList, BufferLine, Family, FontSystem, LayoutLine, LineEnding, Shaping, Wrap,
|
Align, AttrsList, BufferLine, FontSystem, LayoutLine, LineEnding, Shaping, Wrap,
|
||||||
};
|
};
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
|
||||||
|
|
@ -27,8 +27,7 @@ impl LineNumberCache {
|
||||||
|
|
||||||
pub fn get(&mut self, font_system: &mut FontSystem, key: LineNumberKey) -> &Vec<LayoutLine> {
|
pub fn get(&mut self, font_system: &mut FontSystem, key: LineNumberKey) -> &Vec<LayoutLine> {
|
||||||
self.cache.entry(key).or_insert_with(|| {
|
self.cache.entry(key).or_insert_with(|| {
|
||||||
//TODO: do not repeat, used in App::init
|
let attrs = crate::monospace_attrs();
|
||||||
let attrs = Attrs::new().family(Family::Monospace);
|
|
||||||
let text = format!("{:width$}", key.number, width = key.width);
|
let text = format!("{:width$}", key.number, width = key.width);
|
||||||
let mut buffer_line = BufferLine::new(
|
let mut buffer_line = BufferLine::new(
|
||||||
text,
|
text,
|
||||||
|
|
|
||||||
|
|
@ -79,6 +79,12 @@ pub fn icon_cache_get(name: &'static str, size: u16) -> icon::Icon {
|
||||||
icon_cache.get(name, size)
|
icon_cache.get(name, size)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Creates monospace attributes for text rendering.
|
||||||
|
/// This centralizes the creation of monospace font attributes to avoid duplication.
|
||||||
|
pub fn monospace_attrs() -> cosmic_text::Attrs<'static> {
|
||||||
|
cosmic_text::Attrs::new().family(Family::Monospace)
|
||||||
|
}
|
||||||
|
|
||||||
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
#[cfg(all(unix, not(target_os = "redox")))]
|
#[cfg(all(unix, not(target_os = "redox")))]
|
||||||
match fork::daemon(true, true) {
|
match fork::daemon(true, true) {
|
||||||
|
|
@ -1298,8 +1304,7 @@ impl Application for App {
|
||||||
let font_names = {
|
let font_names = {
|
||||||
let mut font_names = Vec::new();
|
let mut font_names = Vec::new();
|
||||||
let mut font_system = font_system().write().unwrap();
|
let mut font_system = font_system().write().unwrap();
|
||||||
//TODO: do not repeat, used in Tab::new
|
let attrs = monospace_attrs();
|
||||||
let attrs = cosmic_text::Attrs::new().family(Family::Monospace);
|
|
||||||
for face in font_system.raw().db().faces() {
|
for face in font_system.raw().db().faces() {
|
||||||
if attrs.matches(face) && face.monospaced {
|
if attrs.matches(face) && face.monospaced {
|
||||||
//TODO: get localized name if possible
|
//TODO: get localized name if possible
|
||||||
|
|
|
||||||
|
|
@ -47,8 +47,7 @@ pub struct EditorTab {
|
||||||
|
|
||||||
impl EditorTab {
|
impl EditorTab {
|
||||||
pub fn new(config: &Config) -> Self {
|
pub fn new(config: &Config) -> Self {
|
||||||
//TODO: do not repeat, used in App::init
|
let attrs = crate::monospace_attrs();
|
||||||
let attrs = Attrs::new().family(cosmic_text::Family::Monospace);
|
|
||||||
let zoom_adj = Default::default();
|
let zoom_adj = Default::default();
|
||||||
let mut buffer = Buffer::new_empty(config.metrics(zoom_adj));
|
let mut buffer = Buffer::new_empty(config.metrics(zoom_adj));
|
||||||
buffer.set_text(
|
buffer.set_text(
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue