add ability to list available fonts

macos-click-through
Keith Simmons 3 years ago
parent f8cb3a2131
commit bc8d002e32

@ -4,7 +4,7 @@ use std::sync::Arc;
use log::error; use log::error;
use log::trace; use log::trace;
use nvim_rs::Neovim; use nvim_rs::{Neovim, call_args, rpc::model::IntoVal};
use tokio::sync::mpsc::{unbounded_channel, UnboundedReceiver}; use tokio::sync::mpsc::{unbounded_channel, UnboundedReceiver};
use crate::bridge::TxWrapper; use crate::bridge::TxWrapper;
@ -15,7 +15,9 @@ use crate::windows_utils::{
}; };
// Serial commands are any commands which must complete before the next value is sent. This // Serial commands are any commands which must complete before the next value is sent. This
// includes keyboard and mouse input which would cuase problems if sent out of order. // includes keyboard and mouse input which would cause problems if sent out of order.
//
// When in doubt, use Parallel Commands.
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub enum SerialCommand { pub enum SerialCommand {
Keyboard(String), Keyboard(String),
@ -113,6 +115,7 @@ pub enum ParallelCommand {
FileDrop(String), FileDrop(String),
FocusLost, FocusLost,
FocusGained, FocusGained,
DisplayAvailableFonts(Vec<String>),
#[cfg(windows)] #[cfg(windows)]
RegisterRightClick, RegisterRightClick,
#[cfg(windows)] #[cfg(windows)]
@ -140,6 +143,44 @@ impl ParallelCommand {
ParallelCommand::FileDrop(path) => { ParallelCommand::FileDrop(path) => {
nvim.command(format!("e {}", path).as_str()).await.ok(); nvim.command(format!("e {}", path).as_str()).await.ok();
} }
ParallelCommand::DisplayAvailableFonts(fonts) => {
let mut content: Vec<String> = vec![
"What follows are the font names available for guifont. To use one of these, type:",
"",
" :set guifont=<font name>:h<font size>",
"",
"where <font name> is one of the following with spaces escaped",
"and <font size> is the desired font size. As an example:",
"",
" :set guifont=Cascadia\\ Code\\ PL:h12",
"",
"You may specify multiple fonts separated by commas like so:",
"",
" :set guifont=Cascadia\\ Code\\ PL,Delugia\\ Nerd\\ Font:h12",
"",
"------------------------------",
"Available Fonts on this System",
"------------------------------",
].into_iter().map(|text| text.to_owned()).collect();
content.extend(fonts);
nvim.command("split").await.ok();
nvim.command("noswapfile hide enew").await.ok();
nvim.command("setlocal buftype=nofile").await.ok();
nvim.command("setlocal bufhidden=hide").await.ok();
nvim.command("\"setlocal nobuflisted").await.ok();
nvim.command("\"lcd ~").await.ok();
nvim.command("file scratch").await.ok();
nvim.call(
"nvim_buf_set_lines",
call_args![
0i64,
0i64,
-1i64,
false,
content
]).await.ok();
}
#[cfg(windows)] #[cfg(windows)]
ParallelCommand::RegisterRightClick => { ParallelCommand::RegisterRightClick => {
if unregister_rightclick() { if unregister_rightclick() {

@ -63,6 +63,7 @@ pub enum DrawCommand {
pub enum WindowCommand { pub enum WindowCommand {
TitleChanged(String), TitleChanged(String),
SetMouseEnabled(bool), SetMouseEnabled(bool),
ListAvailableFonts,
} }
pub struct Editor { pub struct Editor {
@ -421,9 +422,16 @@ impl Editor {
fn set_option(&mut self, gui_option: GuiOption) { fn set_option(&mut self, gui_option: GuiOption) {
trace!("Option set {:?}", &gui_option); trace!("Option set {:?}", &gui_option);
if let GuiOption::GuiFont(guifont) = gui_option { if let GuiOption::GuiFont(guifont) = gui_option {
if guifont == "*".to_owned() {
self.window_command_sender
.send(WindowCommand::ListAvailableFonts)
.ok();
}
self.draw_command_batcher self.draw_command_batcher
.queue(DrawCommand::FontChanged(guifont)) .queue(DrawCommand::FontChanged(guifont))
.ok(); .ok();
for window in self.windows.values() { for window in self.windows.values() {
window.redraw(); window.redraw();
} }

@ -106,6 +106,10 @@ impl CachingShaper {
self.blob_cache.clear(); self.blob_cache.clear();
} }
pub fn font_names(&self) -> Vec<String> {
self.font_loader.font_names()
}
fn info(&mut self) -> (Metrics, f32) { fn info(&mut self) -> (Metrics, f32) {
let font_pair = self.current_font_pair(); let font_pair = self.current_font_pair();
let size = self.current_size(); let size = self.current_size();

@ -162,4 +162,8 @@ impl FontLoader {
Some(font_arc) Some(font_arc)
} }
pub fn font_names(&self) -> Vec<String> {
self.font_mgr.family_names().collect()
}
} }

@ -41,6 +41,10 @@ impl GridRenderer {
} }
} }
pub fn font_names(&self) -> Vec<String> {
self.shaper.font_names()
}
/// Convert PhysicalSize to grid size /// Convert PhysicalSize to grid size
pub fn convert_physical_to_grid(&self, physical: PhysicalSize<u32>) -> Dimensions { pub fn convert_physical_to_grid(&self, physical: PhysicalSize<u32>) -> Dimensions {
Dimensions::from(physical) / self.font_dimensions Dimensions::from(physical) / self.font_dimensions

@ -75,6 +75,10 @@ impl Renderer {
} }
} }
pub fn font_names(&self) -> Vec<String> {
self.grid_renderer.font_names()
}
/// Draws frame /// Draws frame
/// ///
/// # Returns /// # Returns

@ -88,7 +88,8 @@ impl GlutinWindowWrapper {
WindowCommand::TitleChanged(new_title) => self.handle_title_changed(new_title), WindowCommand::TitleChanged(new_title) => self.handle_title_changed(new_title),
WindowCommand::SetMouseEnabled(mouse_enabled) => { WindowCommand::SetMouseEnabled(mouse_enabled) => {
self.mouse_manager.enabled = mouse_enabled self.mouse_manager.enabled = mouse_enabled
} },
WindowCommand::ListAvailableFonts => self.send_font_names(),
} }
} }
} }
@ -98,6 +99,11 @@ impl GlutinWindowWrapper {
self.windowed_context.window().set_title(&self.title); self.windowed_context.window().set_title(&self.title);
} }
pub fn send_font_names(&self) {
let font_names = self.renderer.font_names();
self.ui_command_sender.send(UiCommand::Parallel(ParallelCommand::DisplayAvailableFonts(font_names))).unwrap();
}
pub fn handle_quit(&mut self) { pub fn handle_quit(&mut self) {
if SETTINGS.get::<CmdLineSettings>().remote_tcp.is_none() { if SETTINGS.get::<CmdLineSettings>().remote_tcp.is_none() {
self.ui_command_sender self.ui_command_sender

Loading…
Cancel
Save