{
"id": "017",
"prompt": "Draw a labeled button (rect at 20,20 size 120x40, text \"THEME\"). A click INSIDE the button toggles the background between near-black and near-white. Use edge detection (previous pointer_down in a state slot) so holding does not re-toggle.",
"solution_rl": "fn frame(t: i32) {\n let down: i32 = host::display::pointer_down();\n let prev: i32 = host::display::state_get(1);\n let px: i32 = host::display::pointer_x();\n let py: i32 = host::display::pointer_y();\n if down == 1 && prev == 0 {\n if px >= 20 && px < 140 && py >= 20 && py < 60 {\n host::display::state_set(0, 1 - host::display::state_get(0));\n }\n }\n host::display::state_set(1, down);\n let mut bg: i32 = 0x101010;\n let mut fg: i32 = 0xffffff;\n if host::display::state_get(0) == 1 {\n bg = 0xf0f0f0;\n fg = 0x101010;\n }\n host::display::clear(bg);\n host::display::fill_rect(20, 20, 120, 40, 0x3060a0);\n host::display::draw_string(40, 32, \"THEME\", fg, 2);\n host::display::present();\n}\n",
"tags": [
"pointer",
"state",
"ui"
]
}