{
"id": "048",
"prompt": "Window-manager parent: spawn another subdomain's cartridge (\"clock\") INTO A RECT with host::compose::spawn_module(name, x, y, w, h) (latched once, handle in a slot), show LOADING/READY/FAILED from status(h), and while the pointer is held inside the rect give the child focus with focus_module(h), else focus_module(-1) back to the parent. Draw a frame around the embed.",
"solution_rl": "fn frame(t: i32) {\n let w: i32 = host::display::width();\n host::display::clear(0x101018);\n host::display::draw_string(8, 8, \"PARENT SHELL\", 0xffffff, 2);\n if host::display::state_get(0) == 0 {\n host::display::state_set(0, 1);\n host::display::state_set(1, host::compose::spawn_module(\"clock\", 40, 60, 256, 192));\n }\n let h: i32 = host::display::state_get(1);\n let st: i32 = host::compose::status(h);\n host::display::fill_rect(36, 56, 264, 2, 0x404040);\n host::display::fill_rect(36, 254, 264, 2, 0x404040);\n host::display::fill_rect(36, 56, 2, 200, 0x404040);\n host::display::fill_rect(298, 56, 2, 200, 0x404040);\n if st == 0 {\n host::display::draw_string(48, 130, \"LOADING...\", 0xffff00, 1);\n }\n if st == 2 {\n host::display::draw_string(48, 130, \"EMBED FAILED\", 0xff0000, 1);\n }\n if host::display::pointer_down() == 1 {\n let px: i32 = host::display::pointer_x();\n let py: i32 = host::display::pointer_y();\n if px >= 40 && px < 296 && py >= 60 && py < 252 {\n host::compose::focus_module(h);\n } else {\n host::compose::focus_module(-1);\n }\n }\n host::display::draw_number(w - 30, 8, host::compose::module_count(), 0x808080, 1);\n host::display::present();\n}\n",
"tags": [
"compose",
"state",
"pointer"
]
}