Skip to content

Promote top and left style keys to config keys in picture elements card configuration #25049

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

Draft
wants to merge 5 commits into
base: dev
Choose a base branch
from

Conversation

shocklateboy92
Copy link

Proposed change

Since a picture is worth a thousand words:
Screenshot_20250414_025706

The most common way of positioning elements in a picture-elements card is by using the top and left style keys as %. It's a pain to line everything up by deleting and re-typing the numbers repeatedly.

This improves the situation considerably since browsers allow incrementing/decrementing <input type=number> elements using arrow keys, giving pretty much real-time feedback. (I used to open the devtools, adjust the element there and copy paste the number 😁 )

I could use some feedback regarding the user-facing strings. I picked "Left" and "Top" because they were already available as localized keys. Should we indicate that these become a percentage? Or maybe just say something along the lines of Horizontal/Vertical position?

Type of change

  • Dependency upgrade
  • Bugfix (non-breaking change which fixes an issue)
  • New feature (thank you!)
  • Breaking change (fix/feature causing existing functionality to break)
  • Code quality improvements to existing code or addition of tests

Example configuration

Here's a simple complete frontend dashboard yaml for the screenshot

views:
  - title: Home
    sections:
      - type: grid
        cards:
          - type: heading
            heading: New section
          - type: picture-elements
            elements:
              - type: state-icon
                entity: sensor.sun_next_dawn
                top: 66
                left: 75
                style:
                  left: 1%
                  top: 1%
            image: https://demo.home-assistant.io/stub_config/floorplan.png

Additional information

  • Link to documentation pull request: TODO after UX feedback

Checklist

  • The code change is tested and works locally.
  • There is no commented out code in this PR.
  • Tests have been added to verify that the new code works.

If user exposed functionality or configuration variables are added/changed:

@MindFreeze MindFreeze added the Needs UX Pull requests requiring a review from the Home Assistant design team label Apr 15, 2025
Comment on lines +7360 to +7361
"left": "[%key:ui::panel::page-demo::config::arsaboo::names::left%]",
"top": "[%key:ui::panel::lovelace::editor::edit_view_header::settings::badges_position_options::top%]",
Copy link
Contributor

@MindFreeze MindFreeze Apr 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The UX team will have a look at the labels but we shouldn't use completely unrelated ones like these even though they have to desired words

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, I'll create new ones called "Horizontal Position" and "Vertical Position".

{
name: "left",
selector: {
number: { min: 0, max: 100, unit_of_measurement: "%", step: 0.1 },
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The % unit of measurement is displayed in the number box. Don't know why it is missing in your screenshot.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I realized and pushed that in a separate commit after taking the screenshot 😁

Comment on lines +10 to +11
left?: number;
top?: number;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should handle this entirely in the editor instead of adding redundant config options. The editor should translate between the style option and the top/left inputs

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure. Are you suggesting I put some extra elements in hui-state-icon-element-editor.ts line 121 outside of the <ha-form>?

Or is there some way of overriding the behavior for specific elements in a form?

@home-assistant home-assistant bot marked this pull request as draft April 15, 2025 13:03
@home-assistant
Copy link

Please take a look at the requested changes, and use the Ready for review button when you are done, thanks 👍

Learn more about our pull request process.

Copy link
Author

@shocklateboy92 shocklateboy92 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your feedback! Just one question I asked in a comment thread.

{
name: "left",
selector: {
number: { min: 0, max: 100, unit_of_measurement: "%", step: 0.1 },
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I realized and pushed that in a separate commit after taking the screenshot 😁

Comment on lines +10 to +11
left?: number;
top?: number;
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure. Are you suggesting I put some extra elements in hui-state-icon-element-editor.ts line 121 outside of the <ha-form>?

Or is there some way of overriding the behavior for specific elements in a form?

Comment on lines +7360 to +7361
"left": "[%key:ui::panel::page-demo::config::arsaboo::names::left%]",
"top": "[%key:ui::panel::lovelace::editor::edit_view_header::settings::badges_position_options::top%]",
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, I'll create new ones called "Horizontal Position" and "Vertical Position".

@MindFreeze MindFreeze removed the Needs UX Pull requests requiring a review from the Home Assistant design team label Apr 16, 2025
@MindFreeze
Copy link
Contributor

Discussed this with the UX team. Here is the summary:

  • Sliders don't make sense here. Simple input boxes would be enough
  • Some people use relative position or px values and these cases need to be handled. Not sure it's possible with the proposed UI
  • Ultimately we want this to work with drag & drop on the preview itself. So:
    • Elements are created with position: absolute by default
    • Card and elements enter a special editing mode while in the editor preview
    • The user can just move them around to change the top & left values, if the element has position: absolute
    • The top & left values are updated in the style property directly

Bottom line, this should have drag & drop but this would not be easy to implement. Input boxes can be acceptable but without sliders and they should handle all cases gracefully (Ex. no inputs if there is no position: absolute).
I know this is asking a lot so feel free to close this PR if you don't want to get into it. It is on our wish list so we'll get to it eventually.

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

Successfully merging this pull request may close these issues.

2 participants