Open gaesa opened 5 months ago
Hi there.
I don't think there's a simple way to achieve this because Yazi supports a mixed mode preview of text and images (like what the https://github.com/Sonico98/exifaudio.yazi plugin does). In this case, we can't predict the relative position of the image and text — whether the image is above the text, the text is above the image, or how much space the text takes up to leave room for the image. This information is only known by the plugin itself.
PS: Currently, only community plugins support mixed preview, but I plan to add these text details (such as image dimensions, video length, etc.) to Yazi's built-in previewer in the future.
Thank you for your detailed response and for highlighting the complexities involved with mixed mode preview of text and images.
One possible approach could be to use [preview.alignment]
as the default alignment settings when no third-party plugins are actively controlling the layout. In this case, the alignment settings in yazi.toml
would govern the positioning of images and text. If a third-party plugin explicitly controls the layout, then the [preview.alignment]
settings would be overridden by the plugin's logic. This should help address the concern that "This information is only known by the plugin itself."
To further simplify the process for plugin developers, we could also expose a helper function within the plugin environment. This helper function would handle the alignment calculations based on the image size and desired alignment, allowing plugins to easily position images without needing to manually compute x and y values. For non-image content, I am not sure if it is similar.
This would ensure that the alignment settings are consistently applied, whether controlled by the plugin or by the default settings in yazi.toml
.
Please describe the problem you're trying to solve
Currently, the
yazi.toml
configuration file does not provide options to control the alignment of images within the preview section. This limitation restricts users from customizing how images are positioned within the designated preview area, leading to less flexibility in layout management. Plugin developers may often need to manually calculate and adjust image positions, which can be time-consuming and error-prone. This is a common demand in many applications.Would you be willing to contribute this feature?
Describe the solution you'd like
Add a new section
[preview.alignment]
within the existing[preview]
settings inyazi.toml
. This section would include two options:horizontal
andvertical
, allowing users to specify the alignment of images.The horizontal option should support values
"left"
,"center"
, and"right"
, while the vertical option should support values"top"
,"center"
, and"bottom"
. There are 9 combinations in total, all are valid. By default,horizontal
should be set to"left"
andvertical
should be set to"top"
to maintain backward compatibility.The new alignment settings will serve as the default preview rule. Plugins can still use the existing
[plugin.prepend_previewers]
configuration to override the default alignment behavior.Additional context
Introducing these alignment settings would significantly enhance user experience by providing greater control over image placement, making their workflow more convenient and efficient, resulting in a more versatile and user-friendly preview experience. The feature would support nine valid alignment combinations, ensuring comprehensive options for users to choose from. The most commonly used combinations are:
horizontal = "left", vertical = "top"
horizontal = "center", vertical = "top"
horizontal = "center", vertical = "center"
Additionally, plugin developers will benefit from this feature by avoiding repetitive calculations for image positioning. This built-in functionality reduces the complexity of plugin development and maintenance, allowing developers to focus on other critical features.