{% macro edit_Controller(id, label, field, controller, subtypes) %}
    <fieldset class="controller
    {%- if id.count('.') > 1 %} collapsed{% endif %}" id="{{id}}" controller_type="Controller">
    {% if label -%}
    <legend><label for="{{id}}" onclick="this.parentElement.parentElement.classList.toggle('collapsed');">{{label}}</label>
    {%- endif %}
    {%- if controller %}
    {%- for f in controller.fields() %}
    {%- set t, st = f.parse_type_str() %}
    {{f | render_controller_value(f.name, f.type, 'edit', id + '.' + f.name, controller[f.name]) or (('<span>-- edit for ' + f.type_str() + ' not implemented --</span>') | safe)}}
    {%- endfor %}
    {%- else %}
    -- no value --
        {%- endif %}
    </fieldset>
{%- endmacro %}

{% macro edit_str(id, label, field, value, subtypes) -%}
    {% if label %}<label for="{{id}}">{{label}}</label>{% endif %}
    <input id="{{id}}" controller_type="str" type="text" {% if value %}value="{{value}}"{% endif %} onchange="update_controller_str(this)"/>
{%- endmacro %}


{% macro edit_int(id, label, field, value, subtypes) -%}
    {% if label %}<label for="{{id}}">{{label}}</label>{% endif %}
    <input id="{{id}}" controller_type="int" type="text" {% if value %}value="{{value}}"{% endif %} onchange="update_controller_str(this)"/>
{%- endmacro %}


{% macro edit_float(id, label, field, value, subtypes) -%}
    {% if label %}<label for="{{id}}">{{label}}</label>{% endif %}
    <input id="{{id}}" controller_type="float" type="text" {% if value %}value="{{value}}"{% endif %} onchange="update_controller_str(this)"/>
{%- endmacro %}



{% macro edit_bool(id, label, field, value, subtypes) -%}
    {% if label %}<label for="{{id}}">{{label}}</label>{% endif %}
    <input id="{{id}}" controller_type="bool" type="checkbox" {%- if value -%}checked{% endif %} onchange="update_controller_bool(this)"/>
{%- endmacro %}


{% macro edit_File(id, label, field, value, subtypes) -%}
    {% if label %}<label for="{{id}}">{{label}}</label>{% endif %}
    <div class="button_and_element">
    <button for="{{id}}" onclick="file_selector(this)">📁</button>
    <input id="{{id}}" controller_type="File" {% if value != undefined and value != '' %} value="{{value}}"{% endif %} onchange="update_controller_str(this)"/>
    </div>
{%- endmacro %}


{% macro edit_Directory(id, label, field, value, subtypes) -%}
    {% if label %}<label for="{{id}}">{{label}}</label>{% endif %}
    <div class="button_and_element">
    <button for="{{id}}" onclick="directory_selector(this)">📁</button>
    <input id="{{id}}" controller_type="Directory" {% if value != undefined and value != '' %} value="{{value}}"{% endif %} onchange="update_controller_str(this)"/>
    </div>
{%- endmacro %}


{% macro edit_Literal(id, label, field, value, subtypes) -%}
    {% if label %}<label for="{{id}}">{{label}}</label>{% endif %}
    <select id="{{id}}" controller_type="Literal" onchange="update_controller_str(this)">
{%- for pv in subtypes %}
        <option value="{{pv}}"{% if pv==value %} selected{% endif %}>{{pv}}</option>
{%- endfor %}
    </select>
{%- endmacro %}


{% macro edit_list_str(id, label, field, value, subtypes) -%}
    {% if label %}<label for="{{id}}">{{label}}</label>{% endif %}
    {%- if value == undefined -%}
    {%- set value=[] -%}
    {%- endif %}
    <textarea id="{{id}}" controller_type="list_str" onchange="update_controller_list_str(this)"/>{{'\n'.join(value)}}</textarea>
{%- endmacro %}

{% macro edit_list_int(id, label, field, value, subtypes) -%}
    {% if label %}<label for="{{id}}">{{label}}</label>{% endif %}
    {%- if value == undefined -%}
    {%- set value=[] -%}
    {%- endif %}
    <textarea id="{{id}}" controller_type="list_int" onchange="update_controller_list_int(this)"/>{{'\n'.join(map(str,value))}}</textarea>
{%- endmacro %}

{% macro edit_list_float(id, label, field, value, subtypes) -%}
    {% if label %}<label for="{{id}}">{{label}}</label>{% endif %}
    {%- if value == undefined -%}
    {%- set value=[] -%}
    {%- endif %}
    <textarea id="{{id}}" controller_type="list_float" onchange="update_controller_list_float(this)"/>{{'\n'.join(map(str,value))}}</textarea>
{%- endmacro %}


{% macro edit_generic_list(id, label, field, value, subtypes) -%}
    {%- if value == undefined -%}
    {%- set value=[] -%}
    {%- endif -%}
    <fieldset id="{{id}}" controller_type="list" class="controller
    {%- if id.count('.') > 1 %} collapsed{% endif %}">
    {% if label -%}
    <legend><label for="{{id}}" onclick="this.parentElement.parentElement.classList.toggle('collapsed');">{{label}}</label>
    <button onclick="new_list_element('{{id}}')">⊕</button>
    <button onclick="clear_list('{{id}}')">⊖</button></legend>
    {%- endif %}
    {%- for i in value %}
    {{i|safe}}
    {%- endfor %}
    </fieldset>
{%- endmacro %}
