PhoenixKitDashboards.Layout (PhoenixKitDashboards v0.2.0)

Copy Markdown View Source

Read/write a widget instance's geometry in the embedded item shape:

%{
  "id" => "…", "widget_key" => "…", "settings" => %{}, "view" => "…",
  "pixel" => %{"fx" => .., "fy" => .., "fw" => .., "fh" => ..},   # pixel canvas
  "bp"    => %{"l1" => %{"w" => .., "h" => .., "hidden" => ..}}  # grid, per layout
}

Pixel dashboards use pixel; grid dashboards use bp[<layout id>] (the storage key stays "bp"; flow order = list position). Keeping geometry embedded per widget means add/remove is atomic — no separate placement map to keep in sync.

Accessors default missing values and fall back to the legacy flat shape ("fx"/"w"/"h"… directly on the item) so pre-refactor local dashboards keep rendering; a put_* write upgrades that widget to the nested shape.

Summary

Functions

Whether the widget is hidden on a layout.

The widget's pixel-canvas geometry (fx/fy/fw/fh), defaulted.

The widget's grid placement (w/h/hidden) for a layout, defaulted.

Set pixel geometry (string-keyed attrs), upgrading the item to nested shape.

Set a layout's grid placement, upgrading the item to nested shape.

The widget's view on a layout: the layout's own override (stored in its placement — you design the phone layout by choosing how widgets look ON the phone), else the instance default.

Functions

hidden?(item, bp)

@spec hidden?(map(), String.t()) :: boolean()

Whether the widget is hidden on a layout.

pixel(item)

@spec pixel(map()) :: %{optional(String.t()) => term()}

The widget's pixel-canvas geometry (fx/fy/fw/fh), defaulted.

placement(item, bp)

@spec placement(map(), String.t()) :: %{optional(String.t()) => term()}

The widget's grid placement (w/h/hidden) for a layout, defaulted.

put_pixel(item, attrs)

@spec put_pixel(map(), map()) :: map()

Set pixel geometry (string-keyed attrs), upgrading the item to nested shape.

put_placement(item, bp, attrs)

@spec put_placement(map(), String.t(), map()) :: map()

Set a layout's grid placement, upgrading the item to nested shape.

view(item, bp)

@spec view(map(), String.t()) :: String.t() | nil

The widget's view on a layout: the layout's own override (stored in its placement — you design the phone layout by choosing how widgets look ON the phone), else the instance default.