Skip to content

Commit

Permalink
Merge pull request #470 from ExperienceLovelace/feat/control_image_wi…
Browse files Browse the repository at this point in the history
…dth_logics

Feat/control image width logics
  • Loading branch information
exetico authored Oct 29, 2024
2 parents 6dc3223 + 14d5060 commit f272a32
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 9 deletions.
4 changes: 2 additions & 2 deletions dist/floorplan-examples.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions dist/floorplan.js

Large diffs are not rendered by default.

6 changes: 4 additions & 2 deletions docs/_docs/03-usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ image:
cache: true
```

For supporting multiple Floorplan images based on the current screen resolution, `image` can be set to an object that contains a list of image sizes.
For supporting multiple Floorplan images based on the current window size, `image` can be set to an object that contains a list of image sizes.

In the example below, the first image will be used if the screen width is less than 1024 pixels, and the second image will be used if the screen widths is greater than that.
In the example below, the first image will be used if the window width is less than 1024 pixels, and the second image will be used if the window widths is greater than that.

```yaml
image:
Expand All @@ -59,6 +59,8 @@ image:
cache: true
```

From v1.0.45 and onwards, Floorplan will use the [window inner width](https://developer.mozilla.org/en-US/docs/Web/API/Window/innerWidth) in the calculations. If you have specific needs, it's still possible to enforce the usage of [screen width](https://developer.mozilla.org/en-US/docs/Web/API/Screen/width), by setting the `use_screen_width: true` key, on the image property. Please stick to the default option, whenever possible.

Floorplan can display an alternate image for mobile devices. This can be configured using the `image_mobile` setting.

```yaml
Expand Down
2 changes: 1 addition & 1 deletion docs/_docs/floorplan/floorplan-examples.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ha-floorplan",
"version": "1.0.45",
"version": "1.0.46",
"description": "Floorplan for Home Assistant",
"homepage": "https://experiencelovelace.github.io/ha-floorplan",
"keywords": [
Expand Down
4 changes: 3 additions & 1 deletion src/components/floorplan/floorplan-element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -446,9 +446,11 @@ export class FloorplanElement extends LitElement {
}
} else {
if (config.image?.sizes) {
// Legacy: Previously we always used screen.width. This logic are here, to support the old way of doing it.
const target_width = config?.image?.use_screen_width === true ? screen.width : window.innerWidth;
config.image.sizes.sort((a, b) => b.min_width - a.min_width); // sort descending
for (const pageSize of config.image.sizes) {
if (screen.width >= pageSize.min_width) {
if (target_width >= pageSize.min_width) {
imageUrl = pageSize.location;
cache = pageSize.cache === true;
break;
Expand Down
1 change: 1 addition & 0 deletions src/components/floorplan/lib/floorplan-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ export class FloorplanImageConfig {
location!: string;
cache!: boolean;
sizes!: FloorplanImageSize[];
use_screen_width?: boolean;
}

export class FloorplanImageSize {
Expand Down

0 comments on commit f272a32

Please sign in to comment.