Skip to content

Commit

Permalink
mode/hint: Add hints-alignment-x slot
Browse files Browse the repository at this point in the history
Set the horizontal alignment of hints:
On top/to the left/to the right of a link
  • Loading branch information
MaxGyver83 committed Oct 18, 2023
1 parent f94d716 commit 3c8a62f
Showing 1 changed file with 23 additions and 5 deletions.
28 changes: 23 additions & 5 deletions source/mode/hint.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ A positive value shifts to the right.")
:type integer
:documentation "The number of pixels that hint overlays are vertically shifted by.
A positive value shifts to the bottom.")
(hints-alignment-x
:on-top
:type keyword
:documentation "Where to position hints: :left, :on-top, or :right of a link.")
(keyscheme-map
(define-keyscheme-map "hint-mode" ()
keyscheme:cua
Expand Down Expand Up @@ -110,14 +114,26 @@ A positive value shifts to the bottom.")
(define-parenscript-async hint-elements (hints nyxt-identifiers)
(defun create-hint-overlay (original-element hint)
"Create a DOM element to be used as a hint."
(ps:let ((user-x-offset (ps:lisp (hints-offset-x (find-submode 'hint-mode))))
(user-y-offset (ps:lisp (hints-offset-y (find-submode 'hint-mode))))
(rect (ps:chain original-element (get-bounding-client-rect)))
(element (ps:chain document (create-element "span"))))
(ps:let* ((user-x-offset (ps:lisp (hints-offset-x (find-submode 'hint-mode))))
(user-y-offset (ps:lisp (hints-offset-y (find-submode 'hint-mode))))
(user-x-alignment (ps:lisp (hints-alignment-x (find-submode 'hint-mode))))
(rect (ps:chain original-element (get-bounding-client-rect)))
(relative-x-position (if (eq user-x-alignment :right)
(+ (ps:@ rect right) 2)
(- (ps:@ rect left) 2)))
(computed-style (ps:chain window (get-computed-style original-element)))
(padding-left (parse-float (ps:@ computed-style padding-left)))
(padding-right (parse-float (ps:@ computed-style padding-right)))
(padding-x-adjustment (case user-x-alignment
(:left padding-left)
(:right (- padding-right))
(otherwise 0)))
(element (ps:chain document (create-element "span"))))
(setf (ps:@ element class-name) "nyxt-hint"
(ps:@ element style position) "absolute"
(ps:@ element style left) (+ (ps:max (+ (ps:@ window page-x-offset)
(ps:@ rect left)
relative-x-position
padding-x-adjustment
user-x-offset)
0)
"px")
Expand All @@ -126,6 +142,8 @@ A positive value shifts to the bottom.")
user-y-offset)
0)
"px")
(ps:@ element style transform) (when (eq user-x-alignment :left)
"translate(-100%, 0)")
(ps:@ element id) (+ "nyxt-hint-" hint)
(ps:@ element text-content) hint)
element))
Expand Down

0 comments on commit 3c8a62f

Please sign in to comment.