mirror of
https://github.com/kovidgoyal/kitty
synced 2026-07-28 03:01:57 +02:00
more work on axis fine tuning
This commit is contained in:
@@ -4,6 +4,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"maps"
|
"maps"
|
||||||
"math"
|
"math"
|
||||||
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
@@ -66,7 +67,7 @@ func (self *face_panel) draw_axis(sz loop.ScreenSize, y int, ax VariableAxis, ax
|
|||||||
if i == current_cell {
|
if i == current_cell {
|
||||||
text = lp.SprintStyled(current_val_style, text)
|
text = lp.SprintStyled(current_val_style, text)
|
||||||
} else {
|
} else {
|
||||||
text = tui.InternalHyperlink(text, fmt.Sprintf("axis:%d/%d:%s", i, num_of_cells-1, ax.Tag))
|
text = tui.InternalHyperlink(text, fmt.Sprintf("axis:%d/%d;%s", i, num_of_cells-1, ax.Tag))
|
||||||
}
|
}
|
||||||
buf.WriteString(text)
|
buf.WriteString(text)
|
||||||
}
|
}
|
||||||
@@ -133,6 +134,13 @@ func (self *face_panel) draw_family_style_select(_ loop.ScreenSize, start_y int,
|
|||||||
return y, nil
|
return y, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (self *handler) draw_preview_header(x int) {
|
||||||
|
sz, _ := self.lp.ScreenSize()
|
||||||
|
width := int(sz.WidthCells) - x
|
||||||
|
p := center_string(self.lp.SprintStyled("italic", " preview "), width, "─")
|
||||||
|
self.lp.QueueWriteString(self.lp.SprintStyled("dim", p))
|
||||||
|
}
|
||||||
|
|
||||||
func (self *face_panel) draw_screen() (err error) {
|
func (self *face_panel) draw_screen() (err error) {
|
||||||
lp := self.handler.lp
|
lp := self.handler.lp
|
||||||
lp.SetCursorVisible(false)
|
lp.SetCursorVisible(false)
|
||||||
@@ -198,7 +206,7 @@ func (self *face_panel) draw_screen() (err error) {
|
|||||||
if int(sz.HeightCells)-y >= num_lines+2 {
|
if int(sz.HeightCells)-y >= num_lines+2 {
|
||||||
y += 1
|
y += 1
|
||||||
lp.MoveCursorTo(1, y+1)
|
lp.MoveCursorTo(1, y+1)
|
||||||
lp.QueueWriteString(lp.SprintStyled(control_name_style, "Preview") + ":")
|
self.handler.draw_preview_header(0)
|
||||||
y++
|
y++
|
||||||
lp.MoveCursorTo(1, y+1)
|
lp.MoveCursorTo(1, y+1)
|
||||||
self.handler.graphics_manager.display_image(0, preview.Path, key.width, key.height)
|
self.handler.graphics_manager.display_image(0, preview.Path, key.width, key.height)
|
||||||
@@ -250,6 +258,19 @@ func (self *face_panel) on_click(id string) (err error) {
|
|||||||
self.set(fmt.Sprintf(`family="%s" style="%s"`, self.family, val))
|
self.set(fmt.Sprintf(`family="%s" style="%s"`, self.family, val))
|
||||||
case "variable_style":
|
case "variable_style":
|
||||||
self.set(self.variable_spec(val, nil))
|
self.set(self.variable_spec(val, nil))
|
||||||
|
case "axis":
|
||||||
|
p, tag, _ := strings.Cut(val, ";")
|
||||||
|
num, den, _ := strings.Cut(p, "/")
|
||||||
|
n, _ := strconv.Atoi(num)
|
||||||
|
d, _ := strconv.Atoi(den)
|
||||||
|
frac := float64(n) / float64(d)
|
||||||
|
for _, ax := range self.current_preview.Variable_data.Axes {
|
||||||
|
if ax.Tag == tag {
|
||||||
|
axval := ax.Minimum + (ax.Maximum-ax.Minimum)*frac
|
||||||
|
self.set(self.variable_spec("", map[string]float64{tag: axval}))
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return self.handler.draw_screen()
|
return self.handler.draw_screen()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -53,10 +53,15 @@ func (self *FontList) draw_search_bar() {
|
|||||||
|
|
||||||
const SEPARATOR = "║"
|
const SEPARATOR = "║"
|
||||||
|
|
||||||
func center_string(x string, width int) string {
|
func center_string(x string, width int, filler ...string) string {
|
||||||
|
space := " "
|
||||||
|
if len(filler) > 0 {
|
||||||
|
space = filler[0]
|
||||||
|
}
|
||||||
l := wcswidth.Stringwidth(x)
|
l := wcswidth.Stringwidth(x)
|
||||||
spaces := int(float64(width-l) / 2)
|
spaces := int(float64(width-l) / 2)
|
||||||
return strings.Repeat(" ", utils.Max(0, spaces)) + x
|
space = strings.Repeat(space, utils.Max(0, spaces))
|
||||||
|
return space + x + space
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *handler) format_title(title string, start_x int) string {
|
func (self *handler) format_title(title string, start_x int) string {
|
||||||
@@ -124,7 +129,7 @@ func (self *FontList) draw_preview(x, y int, sz loop.ScreenSize) (err error) {
|
|||||||
}
|
}
|
||||||
y++
|
y++
|
||||||
self.handler.lp.MoveCursorTo(x+1, y+1)
|
self.handler.lp.MoveCursorTo(x+1, y+1)
|
||||||
self.handler.lp.QueueWriteString(self.handler.lp.SprintStyled(control_name_style, "Preview") + ":")
|
self.handler.draw_preview_header(x)
|
||||||
y++
|
y++
|
||||||
height_cells -= 2
|
height_cells -= 2
|
||||||
height_cells = min(height_cells, int(math.Ceil(100./float64(width_cells))))
|
height_cells = min(height_cells, int(math.Ceil(100./float64(width_cells))))
|
||||||
|
|||||||
Reference in New Issue
Block a user