Merge ecc9ddb1cb
into b54cfeb0c0
This commit is contained in:
commit
2fcfb394be
|
@ -263,8 +263,8 @@ export class HuiAreaCard
|
|||
];
|
||||
}
|
||||
|
||||
public getCardSize(): number {
|
||||
return 3;
|
||||
public getCardSize(hScale?: number): number {
|
||||
return 3 * (hScale || 1);
|
||||
}
|
||||
|
||||
public setConfig(config: AreaCardConfig): void {
|
||||
|
|
|
@ -141,9 +141,10 @@ export class HuiButtonCard extends LitElement implements LovelaceCard {
|
|||
return config && (config.state_color ?? domain === "light");
|
||||
}
|
||||
|
||||
public getCardSize(): number {
|
||||
public getCardSize(hScale?: number): number {
|
||||
return (
|
||||
(this._config?.show_icon ? 4 : 0) + (this._config?.show_name ? 1 : 0)
|
||||
(this._config?.show_icon ? 4 * (hScale || 1) : 0) +
|
||||
(this._config?.show_name ? 1 : 0)
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -17,13 +17,14 @@ class HuiGridCard extends HuiStackCard<GridCardConfig> {
|
|||
return document.createElement("hui-grid-card-editor");
|
||||
}
|
||||
|
||||
public async getCardSize(): Promise<number> {
|
||||
public async getCardSize(hScale?: number): Promise<number> {
|
||||
if (!this._cards || !this._config) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (this.square) {
|
||||
const rowHeight = SQUARE_ROW_HEIGHTS_BY_COLUMNS[this.columns] || 1;
|
||||
const rowHeight =
|
||||
(SQUARE_ROW_HEIGHTS_BY_COLUMNS[this.columns] || 1) * (hScale || 1);
|
||||
return (
|
||||
(this._cards.length < this.columns
|
||||
? rowHeight
|
||||
|
@ -35,7 +36,7 @@ class HuiGridCard extends HuiStackCard<GridCardConfig> {
|
|||
const promises: Array<Promise<number> | number> = [];
|
||||
|
||||
for (const element of this._cards) {
|
||||
promises.push(computeCardSize(element));
|
||||
promises.push(computeCardSize(element, (hScale || 1) / this.columns));
|
||||
}
|
||||
|
||||
const cardSizes = await Promise.all(promises);
|
||||
|
|
|
@ -5,7 +5,7 @@ import { HuiStackCard } from "./hui-stack-card";
|
|||
|
||||
@customElement("hui-horizontal-stack-card")
|
||||
export class HuiHorizontalStackCard extends HuiStackCard {
|
||||
public async getCardSize(): Promise<number> {
|
||||
public async getCardSize(hScale?: number): Promise<number> {
|
||||
if (!this._cards) {
|
||||
return 0;
|
||||
}
|
||||
|
@ -13,7 +13,9 @@ export class HuiHorizontalStackCard extends HuiStackCard {
|
|||
const promises: Array<Promise<number> | number> = [];
|
||||
|
||||
for (const element of this._cards) {
|
||||
promises.push(computeCardSize(element));
|
||||
promises.push(
|
||||
computeCardSize(element, (hScale || 1) / this._cards.length)
|
||||
);
|
||||
}
|
||||
|
||||
const results = await Promise.all(promises);
|
||||
|
|
|
@ -104,9 +104,9 @@ class HuiMapCard extends LitElement implements LovelaceCard {
|
|||
this._mapEntities = this._getMapEntities();
|
||||
}
|
||||
|
||||
public getCardSize(): number {
|
||||
public getCardSize(hScale?: number): number {
|
||||
if (!this._config?.aspect_ratio) {
|
||||
return 7;
|
||||
return 7 * (hScale || 1);
|
||||
}
|
||||
|
||||
const ratio = parseAspectRatio(this._config.aspect_ratio);
|
||||
|
@ -115,7 +115,7 @@ class HuiMapCard extends LitElement implements LovelaceCard {
|
|||
? `${((100 * ratio.h) / ratio.w).toFixed(2)}`
|
||||
: "100";
|
||||
|
||||
return 1 + Math.floor(Number(ar) / 25) || 3;
|
||||
return (1 + Math.floor(Number(ar) / 25) || 3) * (hScale || 1);
|
||||
}
|
||||
|
||||
public static async getConfigElement() {
|
||||
|
|
|
@ -40,8 +40,8 @@ export class HuiPictureCard extends LitElement implements LovelaceCard {
|
|||
|
||||
@state() private _config?: PictureCardConfig;
|
||||
|
||||
public getCardSize(): number {
|
||||
return 5;
|
||||
public getCardSize(hScale?: number): number {
|
||||
return 5 * (hScale || 1);
|
||||
}
|
||||
|
||||
public setConfig(config: PictureCardConfig): void {
|
||||
|
|
|
@ -55,8 +55,8 @@ class HuiPictureElementsCard extends LitElement implements LovelaceCard {
|
|||
|
||||
@state() private _config?: PictureElementsCardConfig;
|
||||
|
||||
public getCardSize(): number {
|
||||
return 4;
|
||||
public getCardSize(hScale?: number): number {
|
||||
return 4 * (hScale || 1);
|
||||
}
|
||||
|
||||
public setConfig(config: PictureElementsCardConfig): void {
|
||||
|
|
|
@ -71,8 +71,8 @@ class HuiPictureGlanceCard extends LitElement implements LovelaceCard {
|
|||
|
||||
private _entitiesToggle?: PictureGlanceEntityConfig[];
|
||||
|
||||
public getCardSize(): number {
|
||||
return 3;
|
||||
public getCardSize(hScale?: number): number {
|
||||
return 3 * (hScale || 1);
|
||||
}
|
||||
|
||||
public setConfig(config: PictureGlanceCardConfig): void {
|
||||
|
|
|
@ -89,9 +89,9 @@ export class HuiStatisticsGraphCard extends LitElement implements LovelaceCard {
|
|||
this._setFetchStatisticsTimer();
|
||||
}
|
||||
|
||||
public getCardSize(): number {
|
||||
public getCardSize(hScale?: number): number {
|
||||
return (
|
||||
5 +
|
||||
5 * (hScale || 1) +
|
||||
(this._config?.title ? 2 : 0) +
|
||||
(!this._config?.hide_legend ? this._entities?.length || 0 : 0)
|
||||
);
|
||||
|
|
|
@ -3,7 +3,7 @@ import { computeCardSize } from "../common/compute-card-size";
|
|||
import { HuiStackCard } from "./hui-stack-card";
|
||||
|
||||
class HuiVerticalStackCard extends HuiStackCard {
|
||||
public async getCardSize() {
|
||||
public async getCardSize(hScale?: number) {
|
||||
if (!this._cards) {
|
||||
return 0;
|
||||
}
|
||||
|
@ -11,7 +11,7 @@ class HuiVerticalStackCard extends HuiStackCard {
|
|||
const promises: Array<Promise<number> | number> = [];
|
||||
|
||||
for (const element of this._cards) {
|
||||
promises.push(computeCardSize(element));
|
||||
promises.push(computeCardSize(element, hScale));
|
||||
}
|
||||
|
||||
const results = await Promise.all(promises);
|
||||
|
|
|
@ -2,11 +2,12 @@ import { promiseTimeout } from "../../../common/util/promise-timeout";
|
|||
import { LovelaceCard, LovelaceHeaderFooter } from "../types";
|
||||
|
||||
export const computeCardSize = (
|
||||
card: LovelaceCard | LovelaceHeaderFooter
|
||||
card: LovelaceCard | LovelaceHeaderFooter,
|
||||
hScale: number = 1
|
||||
): number | Promise<number> => {
|
||||
if (typeof card.getCardSize === "function") {
|
||||
try {
|
||||
return promiseTimeout(500, card.getCardSize()).catch(
|
||||
return promiseTimeout(500, card.getCardSize(hScale)).catch(
|
||||
() => 1
|
||||
) as Promise<number>;
|
||||
} catch (_e: any) {
|
||||
|
@ -18,5 +19,5 @@ export const computeCardSize = (
|
|||
}
|
||||
return customElements
|
||||
.whenDefined(card.localName)
|
||||
.then(() => computeCardSize(card));
|
||||
.then(() => computeCardSize(card, hScale));
|
||||
};
|
||||
|
|
|
@ -48,7 +48,7 @@ export interface LovelaceCard extends HTMLElement {
|
|||
hass?: HomeAssistant;
|
||||
isPanel?: boolean;
|
||||
editMode?: boolean;
|
||||
getCardSize(): number | Promise<number>;
|
||||
getCardSize(hScale?: number): number | Promise<number>;
|
||||
getLayoutOptions?(): LovelaceLayoutOptions;
|
||||
setConfig(config: LovelaceCardConfig): void;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue