File size: 879 Bytes
c05974a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import os
import streamlit.components.v1 as components

_COMPONENT_DIR = os.path.join(os.path.dirname(os.path.abspath(__file__)), "frontend")

_floorplan_editor = components.declare_component(
    "floorplan_editor",
    path=_COMPONENT_DIR,
)


def floor_plan_editor(rooms, plot_w, plot_h, road_side, key=None):
    """
    Interactive drag-and-drop floor plan editor component.

    rooms: list of Room objects with .name, .x, .y, .w, .h attributes
    Returns list of updated room dicts {name, x, y, w, h} or None if no changes applied.
    """
    room_dicts = [
        {"name": r.name, "x": float(r.x), "y": float(r.y), "w": float(r.w), "h": float(r.h)}
        for r in rooms
    ]
    return _floorplan_editor(
        rooms=room_dicts,
        plot_w=float(plot_w),
        plot_h=float(plot_h),
        road_side=road_side,
        key=key,
        default=None,
    )