Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mode/hint: Add hints-alignment-x slot #3226

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion source/changelog.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -928,7 +928,12 @@ invoked via " (:code "flatpak-spawn --host <command> <command-args>") "."))))
(:nsection :title "UI/UX"
(:ul
(:li "Improve source heading buttons, layout and interactions in the "
(:nxref :class-name 'prompt-buffer) "."))))
(:nxref :class-name 'prompt-buffer) ".")))
(:nsection :title "Features"
(:ul
(:li "Add new slot "
(:nxref :class-name 'nyxt/mode/hint:hint-mode :slot 'nyxt/mode/hint:hints-alignment-x)
", to set the horizontal alignment of hint overlays."))))

(define-version "4-pre-release-1"
(:li "When on pre-release, push " (:code "X-pre-release")
Expand Down
57 changes: 45 additions & 12 deletions source/mode/hint.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,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 @@ -111,17 +115,43 @@ 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)))
(absolute-x-position (+ (ps:@ window page-x-offset)
relative-x-position
padding-x-adjustment
user-x-offset))
(inner-width (ps:@ window inner-width))
(max-x-position (- inner-width 25))
(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)
user-x-offset)
0)
"px")
(ps:@ element style left) (unless (eq user-x-alignment :left)
(+ (ps:min
max-x-position
(ps:max
0
absolute-x-position))
"px"))
(ps:@ element style right) (when (eq user-x-alignment :left)
(+ (ps:min
max-x-position
(ps:max
0
(- inner-width absolute-x-position)))
"px"))
(ps:@ element style top) (+ (ps:max (+ (ps:@ window page-y-offset)
(ps:@ rect top)
user-y-offset)
Expand All @@ -133,13 +163,16 @@ A positive value shifts to the bottom.")

(let ((fragment (ps:chain document (create-document-fragment)))
(hints (ps:lisp (list 'quote hints)))
(nyxt-identifiers (ps:lisp (list 'quote nyxt-identifiers))))
(nyxt-identifiers (ps:lisp (list 'quote nyxt-identifiers)))
(hint-elements '()))
(dotimes (i (length hints))
(let* ((hint (aref hints i))
(nyxt-identifier (aref nyxt-identifiers i))
(element (nyxt/ps:rqs-nyxt-id document nyxt-identifier)))
(element (nyxt/ps:rqs-nyxt-id document nyxt-identifier))
(hint-element (create-hint-overlay element hint)))
(setq hint-elements (append hint-elements hint-element))
(ps:chain fragment (append-child hint-element))
(ps:chain element (set-attribute "nyxt-hint" hint))
(ps:chain fragment (append-child (create-hint-overlay element hint)))
(when (ps:lisp (show-hint-scope-p (find-submode 'hint-mode)))
(ps:chain element class-list (add "nyxt-element-hint")))))
(ps:chain document body (append-child fragment))
Expand Down