Skip to content

Commit

Permalink
Cleanup the code from warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
fredizzimo committed Jul 19, 2024
1 parent c4ad16c commit 3d368c1
Show file tree
Hide file tree
Showing 22 changed files with 244 additions and 481 deletions.
7 changes: 0 additions & 7 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ lazy_static = "1.4.0"
log = "0.4.16"
lru = "0.12.2"
neovide-derive = { path = "neovide-derive", version = "0.1.0" }
mint = "0.5.9"
num = "0.4.1"
nvim-rs = { version = "0.7.0", features = ["use_tokio"] }
palette = "0.7.6"
Expand Down
2 changes: 2 additions & 0 deletions src/editor/cursor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ pub struct Cursor {
pub grid_cell: GridCell,
}

// TODO: Remove
#[allow(unused)]
impl Cursor {
pub fn new() -> Cursor {
Cursor {
Expand Down
2 changes: 2 additions & 0 deletions src/editor/style.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ impl Style {
}
}

//TODO: Remove
#[allow(unused)]
pub fn special(&self, default_colors: &Colors) -> Srgba {
self.colors
.special
Expand Down
2 changes: 1 addition & 1 deletion src/error_handling.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ fn handle_terminal_startup_errors(err: Error) -> i32 {
1
}

fn handle_gui_startup_errors(err: Error, event_loop: EventLoop<UserEvent>) -> i32 {
fn handle_gui_startup_errors(_err: Error, _event_loop: EventLoop<UserEvent>) -> i32 {
// show_error_window(&format_and_log_error_message(err), event_loop);
1
}
Expand Down
2 changes: 2 additions & 0 deletions src/renderer/cursor_renderer/blink.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ fn is_static(cursor: &Cursor) -> bool {
|| cursor.blinkon.is_none()
}

// TODO: Remove
#[allow(unused)]
impl BlinkStatus {
pub fn new() -> BlinkStatus {
BlinkStatus {
Expand Down
8 changes: 4 additions & 4 deletions src/renderer/cursor_renderer/cursor_vfx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ use nvim_rs::Value;
use crate::{
editor::Cursor,
renderer::cursor_renderer::CursorSettings,
renderer::{animation_utils::*, grid_renderer::GridRenderer},
renderer::grid_renderer::GridRenderer,
settings::*,
units::{GridSize, PixelPos, PixelSize, PixelVec},
units::{PixelPos, PixelSize, PixelVec},
};

pub trait CursorVfx {
Expand Down Expand Up @@ -90,15 +90,15 @@ pub fn new_cursor_vfx(mode: &VfxMode) -> Option<Box<dyn CursorVfx>> {
pub struct PointHighlight {
t: f32,
center_position: PixelPos<f32>,
mode: HighlightMode,
_mode: HighlightMode,
}

impl PointHighlight {
pub fn new(mode: &HighlightMode) -> PointHighlight {
PointHighlight {
t: 0.0,
center_position: PixelPos::new(0.0, 0.0),
mode: mode.clone(),
_mode: mode.clone(),
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/renderer/cursor_renderer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use crate::{
profiling::{tracy_plot, tracy_zone},
renderer::{animation_utils::*, GridRenderer, RenderedWindow},
settings::{ParseFromValue, SETTINGS},
units::{GridPos, GridScale, PixelPos, PixelSize, PixelVec},
units::{GridPos, GridScale, PixelPos, PixelSize},
window::{ShouldRender, UserEvent},
};

Expand Down
217 changes: 112 additions & 105 deletions src/renderer/fonts/caching_shaper.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
use std::{num::NonZeroUsize, sync::Arc};

use itertools::Itertools;
use log::{debug, error, info, trace};
use log::{debug, error};

use parley::style::{FontStack, StyleProperty};
use vide::Shaper;
Expand All @@ -14,8 +11,6 @@ struct ShapeKey {
pub style: CoarseStyle,
}

const FONT_CACHE_SIZE: usize = 8 * 1024 * 1024;

pub struct CachingShaper {
options: FontOptions,
scale_factor: f32,
Expand All @@ -38,19 +33,21 @@ impl CachingShaper {
}
}

// fn current_font_pair(&mut self) -> Arc<FontPair> {
// self.font_loader
// .get_or_load(&FontKey {
// font_desc: self.options.primary_font(),
// hinting: self.options.hinting.clone(),
// edging: self.options.edging.clone(),
// })
// .unwrap_or_else(|| {
// self.font_loader
// .get_or_load(&FontKey::default())
// .expect("Could not load default font")
// })
// }
/*
fn current_font_pair(&mut self) -> Arc<FontPair> {
self.font_loader
.get_or_load(&FontKey {
font_desc: self.options.primary_font(),
hinting: self.options.hinting.clone(),
edging: self.options.edging.clone(),
})
.unwrap_or_else(|| {
self.font_loader
.get_or_load(&FontKey::default())
.expect("Could not load default font")
})
}
*/

pub fn current_size(&self) -> f32 {
let min_font_size = 1.0;
Expand Down Expand Up @@ -80,36 +77,38 @@ impl CachingShaper {
pub fn update_font_options(&mut self, options: FontOptions) {
debug!("Updating font options: {:?}", options);

// let keys = options
// .possible_fonts()
// .iter()
// .map(|desc| FontKey {
// font_desc: Some(desc.clone()),
// hinting: options.hinting.clone(),
// edging: options.edging.clone(),
// })
// .unique()
// .collect::<Vec<_>>();
//
// let failed_fonts = keys
// .iter()
// .filter(|key| self.font_loader.get_or_load(key).is_none())
// .collect_vec();
//
// if !failed_fonts.is_empty() {
// error_msg!(
// "Font can't be updated to: {:#?}\n\
// Following fonts couldn't be loaded: {}",
// options,
// failed_fonts.iter().join(",\n"),
// );
// }
//
// if failed_fonts.len() != keys.len() {
// debug!("Font updated to: {:?}", options);
// self.options = options;
// self.reset_font_loader();
// }
/*
let keys = options
.possible_fonts()
.iter()
.map(|desc| FontKey {
font_desc: Some(desc.clone()),
hinting: options.hinting.clone(),
edging: options.edging.clone(),
})
.unique()
.collect::<Vec<_>>();
let failed_fonts = keys
.iter()
.filter(|key| self.font_loader.get_or_load(key).is_none())
.collect_vec();
if !failed_fonts.is_empty() {
error_msg!(
"Font can't be updated to: {:#?}\n\
Following fonts couldn't be loaded: {}",
options,
failed_fonts.iter().join(",\n"),
);
}
if failed_fonts.len() != keys.len() {
debug!("Font updated to: {:?}", options);
self.options = options;
self.reset_font_loader();
}
*/
}

pub fn update_linespace(&mut self, linespace: f32) {
Expand All @@ -134,84 +133,92 @@ impl CachingShaper {

fn reset_font_loader(&mut self) {
tracy_zone!("reset_font_loader");
// self.font_info = None;
// let font_size = self.current_size();
//
// self.font_loader = FontLoader::new(font_size);
// let (_, font_width) = self.info();
// info!(
// "Reset Font Loader: font_size: {:.2}px, font_width: {:.2}px",
// font_size, font_width
// );
//
// self.blob_cache.clear();
/*
self.font_info = None;
let font_size = self.current_size();
self.font_loader = FontLoader::new(font_size);
let (_, font_width) = self.info();
info!(
"Reset Font Loader: font_size: {:.2}px, font_width: {:.2}px",
font_size, font_width
);
self.blob_cache.clear();
*/
}

pub fn font_names(&self) -> Vec<String> {
//self.font_loader.font_names()
Vec::new()
}

// fn info(&mut self) -> (Metrics, f32) {
// if let Some(info) = self.font_info {
// return info;
// }
//
// let font_pair = self.current_font_pair();
// let size = self.current_size();
// let mut shaper = self
// .shape_context
// .builder(font_pair.swash_font.as_ref())
// .size(size)
// .build();
// shaper.add_str("M");
// let metrics = shaper.metrics();
// let mut advance = metrics.average_width;
// shaper.shape_with(|cluster| {
// advance = cluster
// .glyphs
// .first()
// .map_or(metrics.average_width, |g| g.advance);
// });
// self.font_info = Some((metrics, advance));
// (metrics, advance)
// }
//
// fn metrics(&mut self) -> Metrics {
// tracy_zone!("font_metrics");
// self.info().0
// }
/*
fn info(&mut self) -> (Metrics, f32) {
if let Some(info) = self.font_info {
return info;
}
let font_pair = self.current_font_pair();
let size = self.current_size();
let mut shaper = self
.shape_context
.builder(font_pair.swash_font.as_ref())
.size(size)
.build();
shaper.add_str("M");
let metrics = shaper.metrics();
let mut advance = metrics.average_width;
shaper.shape_with(|cluster| {
advance = cluster
.glyphs
.first()
.map_or(metrics.average_width, |g| g.advance);
});
self.font_info = Some((metrics, advance));
(metrics, advance)
}
fn metrics(&mut self) -> Metrics {
tracy_zone!("font_metrics");
self.info().0
}
*/

pub fn font_base_dimensions(&mut self) -> PixelSize<f32> {
// let (metrics, glyph_advance) = self.info();
//
// let bare_font_height = metrics.ascent + metrics.descent + metrics.leading;
// // assuming that linespace is checked on receive for validity
// let font_height = (bare_font_height + self.linespace).ceil();
// let font_width = glyph_advance + self.options.width;
//
// (font_width, font_height).into()
/*
let (metrics, glyph_advance) = self.info();
(11.487181, 23.0).into()
let bare_font_height = metrics.ascent + metrics.descent + metrics.leading;
// assuming that linespace is checked on receive for validity
let font_height = (bare_font_height + self.linespace).ceil();
let font_width = glyph_advance + self.options.width;
(font_width, font_height).into()
*/

//(8.205129, 17.0).into()
(11.487181, 23.0).into()
}

/*
pub fn underline_position(&mut self) -> f32 {
self.baseline_offset()
}
pub fn stroke_size(&mut self) -> f32 {
1.0
}
*/

pub fn baseline_offset(&mut self) -> f32 {
//let metrics = self.metrics();
// NOTE: leading is also called linegap and should be equally distributed on the top and
// bottom, so it's centered like our linespace settings. That's how it works on the web,
// but some desktop applications only use the top according to:
// https://googlefonts.github.io/gf-guide/metrics.html#8-linegap-values-must-be-0
////////////////metrics.ascent + (metrics.leading + self.linespace) / 2.0
/*
let metrics = self.metrics();
NOTE: leading is also called linegap and should be equally distributed on the top and
bottom, so it's centered like our linespace settings. That's how it works on the web,
but some desktop applications only use the top according to:
https://googlefonts.github.io/gf-guide/metrics.html#8-linegap-values-must-be-0
metrics.ascent + (metrics.leading + self.linespace) / 2.0
*/
0.0
}
}
Loading

0 comments on commit 3d368c1

Please sign in to comment.