mirror of
https://github.com/kovidgoyal/kitty
synced 2026-07-11 18:32:12 +02:00
Work on face panel
This commit is contained in:
@@ -3,6 +3,7 @@ package choose_fonts
|
||||
import (
|
||||
"fmt"
|
||||
"kitty/tools/tui/loop"
|
||||
"math"
|
||||
"sync"
|
||||
)
|
||||
|
||||
@@ -19,6 +20,54 @@ type face_panel struct {
|
||||
}
|
||||
|
||||
func (self *face_panel) draw_screen() (err error) {
|
||||
lp := self.handler.lp
|
||||
lp.SetCursorVisible(false)
|
||||
sz, _ := lp.ScreenSize()
|
||||
styled := lp.SprintStyled
|
||||
wt := "Regular"
|
||||
switch self.which {
|
||||
case "bold_font":
|
||||
wt = "Bold"
|
||||
case "italic_font":
|
||||
wt = "Italic"
|
||||
case "bold_italic_font":
|
||||
wt = "Bold-Italic font"
|
||||
}
|
||||
|
||||
lines := []string{
|
||||
self.handler.format_title(self.family+": "+wt, 0), "",
|
||||
fmt.Sprintf("Press %s to select this face or %s to cancel. Click on a style name below to switch to it.", styled("fg=green", "Enter"), styled("fg=red", "Esc")), "",
|
||||
}
|
||||
_, y, str := self.handler.render_lines.InRectangle(lines, 0, 0, int(sz.WidthCells), int(sz.HeightCells), &self.handler.mouse_state, self.on_click)
|
||||
lp.QueueWriteString(str)
|
||||
num_lines_per_font := (int(sz.HeightCells) - y - 1) - 2
|
||||
num_lines_needed := int(math.Ceil(100. / float64(sz.WidthCells)))
|
||||
num_lines := max(1, min(num_lines_per_font, num_lines_needed))
|
||||
key := faces_preview_key{settings: self.settings, width: int(sz.WidthCells * sz.CellWidth), height: int(sz.CellHeight) * num_lines}
|
||||
self.preview_cache_mutex.Lock()
|
||||
defer self.preview_cache_mutex.Unlock()
|
||||
previews, found := self.preview_cache[key]
|
||||
if !found {
|
||||
self.preview_cache[key] = make(map[string]RenderedSampleTransmit)
|
||||
go func() {
|
||||
var r map[string]RenderedSampleTransmit
|
||||
s := key.settings
|
||||
self.handler.set_worker_error(kitty_font_backend.query("render_family_samples", map[string]any{
|
||||
"text_style": self.handler.text_style, "font_family": s.font_family,
|
||||
"bold_font": s.bold_font, "italic_font": s.italic_font, "bold_italic_font": s.bold_italic_font,
|
||||
"width": key.width, "height": key.height, "output_dir": self.handler.temp_dir,
|
||||
}, &r))
|
||||
self.preview_cache_mutex.Lock()
|
||||
defer self.preview_cache_mutex.Unlock()
|
||||
self.preview_cache[key] = r
|
||||
self.handler.lp.WakeupMainThread()
|
||||
}()
|
||||
return
|
||||
}
|
||||
if len(previews) < 4 {
|
||||
return
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user