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

Add alignment settings for preview #1141

Open
1 task
gaesa opened this issue Jun 8, 2024 · 2 comments
Open
1 task

Add alignment settings for preview #1141

gaesa opened this issue Jun 8, 2024 · 2 comments
Labels
feature New feature request

Comments

@gaesa
Copy link

gaesa commented Jun 8, 2024

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?

  • Yes, I'll give it a shot

Describe the solution you'd like

Add a new section [preview.alignment] within the existing [preview] settings in yazi.toml. This section would include two options: horizontal and vertical, 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" and vertical 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:

  1. horizontal = "left", vertical = "top"
  2. horizontal = "center", vertical = "top"
  3. 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.

@gaesa gaesa added the feature New feature request label Jun 8, 2024
@sxyazi
Copy link
Owner

sxyazi commented Jun 9, 2024

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.

@sxyazi sxyazi added the waiting on op Waiting for more information from the original poster label Jun 9, 2024
@gaesa
Copy link
Author

gaesa commented Jun 9, 2024

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.

@github-actions github-actions bot removed the waiting on op Waiting for more information from the original poster label Jun 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature request
Projects
None yet
Development

No branches or pull requests

2 participants