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

How to Center Stuff #22

Open
psionic-k opened this issue Nov 30, 2024 · 2 comments
Open

How to Center Stuff #22

psionic-k opened this issue Nov 30, 2024 · 2 comments

Comments

@psionic-k
Copy link
Member

Writing this down for anyone hacking on the problem.

Use of a line-prefix with a display-property using specified space and the center can, with a bit of elbow grease on the width of text, apply an overlay to center arbitrary contents. Read the Elisp manual entry on text properties and specified space.

It's a bit hairy to write the expressions just from reading the docs. The dashboard package has both image and text examples to look at using (text-properties-at (point))

I am not sure if actions or headings or headers are most valuable to center first. Maybe we want to center the slide contents separately from the header.

A "title" slide using such centering is my most likely first application of the idea. It's possible to turn the header off, narrow the heading for a slide, center all the contents, and that is a "title" slide.

That's all hacky, but dslide is built to readily accommodate hacking anywhere that features are not baked in 🤠

@psionic-k
Copy link
Member Author

Screenshot_2024-11-30_14-53-58

For proof of concept, just add an overlay. The center expression for an image or text needs to know "half of how much" to subtract, which is honestly quite lame, but that's Emacs barebones display at work.

(overlay-put o 'line-prefix (propertize " " 'display '(space :align-to (- center (0.5 . (image :type jpeg :file
         "/home/psionic/.emacs.d/elpaca/repos/dslide/test/images/yuki-o-yak.jpeg"
         :width 595 :max-width 1200 :scale 1 :transform-smoothing t))))))

The easy way to get the image dimensions are by calling (mapcar #'overlay-properties (overlays-at (point))) on an image already visible in the buffer. At presentation time, after turning on inline images, the display property of a link is set to a valid value that center can understand.

@psionic-k
Copy link
Member Author

psionic-k commented Nov 30, 2024

https://github.com/emacs-dashboard/emacs-dashboard/blob/master/dashboard.el#L517-L526

Some vertical centering besides what I do in Master of Ceremonies. Use the screen space math, not the whole lines method of adding space.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant