lovelace-layout-card icon indicating copy to clipboard operation
lovelace-layout-card copied to clipboard

Add support for card_margin in grid layouts

Open cdhgee opened this issue 2 years ago • 14 comments

Fixes #194

cdhgee avatar Apr 10 '22 19:04 cdhgee

Has this been merged yet? This fix is sorely needed.

Madelena avatar May 17 '22 01:05 Madelena

@thomasloven

M4th1asK avatar Sep 01 '22 19:09 M4th1asK

This code looks good :) Need this as well ;) *NVM noticed a bug

awgneo avatar Sep 06 '22 18:09 awgneo

I corrected and tested this change in this PR instead https://github.com/thomasloven/lovelace-layout-card/pull/210/files :)

awgneo avatar Sep 06 '22 19:09 awgneo

Looks like you only changed line 152 in grid.ts, correct?

from

image

to

image

The fallback value of 4px 4px 8px was deliberate so that it retains the existing behavior if not explicitly defined. Your version of the PR would introduce a breaking change.

cdhgee avatar Sep 06 '22 19:09 cdhgee

When I tested this PR, my margins were not appropriately applied. So instead, I mirrored the existing column logic of https://github.com/thomasloven/lovelace-layout-card/blob/466df9cb051033881106dfb9029672ac7ea2a2c3/src/layouts/base-column-layout.ts#L256 in my PR, which already has a fallback defined in its configuration https://github.com/thomasloven/lovelace-layout-card/blob/466df9cb051033881106dfb9029672ac7ea2a2c3/src/layouts/base-column-layout.ts#L95 I supported this strategy in the same way in my PR https://github.com/thomasloven/lovelace-layout-card/pull/210/files#diff-4f9f8ab90608430f9ad38a4a682f3e9f7cbd2aa69d11a636ec18b84ea33f5094R62, and it works as expected without breaking existing logic, with or without setting card_margin.

awgneo avatar Sep 13 '22 14:09 awgneo

Has this been merged yet? This fix is sorely needed.

Me too !

pafnow avatar Dec 13 '22 10:12 pafnow

@thomasloven can we have this merged please?

snjoetw avatar Dec 31 '22 14:12 snjoetw

Isn't this the same with additional overflow? https://github.com/thomasloven/lovelace-layout-card/pull/210

EmJay276 avatar Jan 01 '23 22:01 EmJay276

@cdhgee With your version of card-layout.js I still get unwanted margins.

views:
      - type: custom:grid-layout
        layout:
          grid-template-columns: 50% 50%
          margin: 0
          padding: 0
          card_margin: 0 0 0 0
        cards:
              - type: markdown
                content: 'a'
              - type: markdown
                content: 'b'
              - type: markdown
                content: 'c'
              - type: markdown
                content: 'd'

Did I misunderstand this feature, or how to apply? I just copied card-layout.js to www/community/lovelace-layout-card/.

scrot20230226152721

sciurius avatar Feb 26 '23 14:02 sciurius

The intention was to fix the hardcoded card margins that are present in the grid layout. I'll have a play around using your layout config and see if I can figure out what's going on. I was using a custom:layout-card inside a panel layout instead of using the custom:grid-layout directly, maybe it behaves differently for some reason.

On Sun, Feb 26, 2023, 08:28 Johan Vromans @.***> wrote:

@cdhgee https://github.com/cdhgee With your version of card-layout.js I still get unwanted margins.

views: - type: custom:grid-layout layout: grid-template-columns: 50% 50% margin: 0 padding: 0 card_margin: 0 0 0 0 cards: - type: markdown content: 'a' - type: markdown content: 'b' - type: markdown content: 'c' - type: markdown content: 'd'

Did I misunderstand this feature?

[image: scrot20230226152721] https://user-images.githubusercontent.com/1118804/221416646-a3796889-246e-4341-ba0a-4982f3263bf0.png

— Reply to this email directly, view it on GitHub https://github.com/thomasloven/lovelace-layout-card/pull/195#issuecomment-1445375356, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAJSWKKYNNDNPDCQR4AL523WZNSCFANCNFSM5TBIZ6AA . You are receiving this because you were mentioned.Message ID: @.***>

cdhgee avatar Feb 26 '23 15:02 cdhgee

@sciurius This is how it looks with your code on my system:

image

I've noticed that Lovelace generates/uses gzipped versions of JS files in some instances. I suspect that even though you copied over the card-layout.js file, Lovelace is using the card-layout.js.gz compressed version. Renaming or removing the compressed version and restarting HA should force it to start using the updated card-layout.js file.

image

cdhgee avatar Feb 27 '23 00:02 cdhgee

I did replace layout-card.js, layout-card.js.gz, rollup.config.js and rollup.config.js.gz and restarted HA (and the browser) several times... The size difference shown in your screenshot made me realize that I forgot to switch to the bugfix-grid-layout-margin branch first. Now it is working as expected. Great job!

For the sake of completeness, layout-card.js in the bugfix-grid-layout-margin branch of the repo is 49409 bytes while the one shown is 49535 bytes.

sciurius avatar Feb 27 '23 07:02 sciurius

@sciurius Glad you got it working. The difference in size in my local copy vs the PR copy of layout-card.js is because I tweaked the console output of my local copy so that I could be certain that my updated copy was being used.

image

cdhgee avatar Feb 27 '23 13:02 cdhgee