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

Feat/control image width logics #470

Merged
merged 5 commits into from
Oct 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading