Plushie.UI.WidgetSet (Plushie v0.7.2)

Copy Markdown View Source

Macro for creating widget set modules that override built-in widget macros.

A widget set is a module that re-exports all of Plushie.UI but replaces specific widget macros with alternatives. This enables widget packs, custom themes, and per-app widget customization without manual import juggling.

Usage

Define a widget set module:

defmodule MyApp.MaterialUI do
  use Plushie.UI.WidgetSet,
    override: [
      button: MyApp.Widgets.MaterialButton,
      text_input: MyApp.Widgets.MaterialTextInput
    ]
end

Use it in view functions:

defmodule MyApp do
  use Plushie.App

  def view(model) do
    use MyApp.MaterialUI

    window "main", title: "My App" do
      button("save", label: "Save")  # uses MaterialButton
      text("greeting", "Hello")      # uses built-in (not overridden)
    end
  end
end

How it works

The macro generates a module that:

  1. Imports all of Plushie.UI except the overridden widget macros
  2. Imports the override modules, bringing their macros into scope
  3. Re-exports everything so consumers get a single import

Override modules must export macros with the same names and compatible arities as the built-in widgets they replace. The easiest way to create an override module is with use Plushie.Widget:

defmodule MyApp.Widgets.MaterialButton do
  use Plushie.Widget

  widget :button do
    field :label, :string
    field :rounded, :boolean, default: true
    # ... material-specific fields
  end

  def view(id, props) do
    import Plushie.UI
    button(id, props.label, style: :primary, padding: 12)
  end
end