{
"id": "279",
"prompt": "A scrolling reader for a fetched page: once the GET is ready, http::body_lines(h) says how many lines the host is holding and http::draw_line renders them by index - so build a pager. 14 lines per screen starting at a scroll offset kept in a state slot, edge-detected taps on the top half scroll up and the bottom half scroll down, offset clamped to 0..total-14, and a header bar with the current line number OF the total.",
"solution_rl": "fn frame(t: i32) {\n host::display::clear(0x0f1013);\n if host::display::state_get(0) == 0 {\n let h: i32 = host::http::get(\"https://www.rust-lang.org/\", 26);\n host::display::state_set(1, h);\n if h < 0 {\n host::display::state_set(0, 3);\n } else {\n host::display::state_set(0, 1);\n }\n }\n let h2: i32 = host::display::state_get(1);\n if host::display::state_get(0) == 1 {\n let r: i32 = host::http::ready(h2);\n if r == 1 {\n host::display::state_set(0, 2);\n } else if r < 0 {\n host::display::state_set(0, 3);\n }\n }\n let phase: i32 = host::display::state_get(0);\n if phase == 1 {\n host::display::draw_string(180, 240, \"LOADING\", 0xaa7700, 2);\n } else if phase == 2 {\n let total: i32 = host::http::body_lines(h2);\n let mut maxoff: i32 = total - 14;\n if maxoff < 0 {\n maxoff = 0;\n }\n let down: i32 = host::display::pointer_down();\n let prev: i32 = host::display::state_get(3);\n host::display::state_set(3, down);\n if down == 1 && prev == 0 {\n let mut off: i32 = host::display::state_get(2);\n if host::display::pointer_y() < 256 {\n off = off - 1;\n } else {\n off = off + 1;\n }\n if off < 0 {\n off = 0;\n }\n if off > maxoff {\n off = maxoff;\n }\n host::display::state_set(2, off);\n }\n let off2: i32 = host::display::state_get(2);\n for i in 0..14 {\n host::http::draw_line(h2, off2 + i, 8, 40 + i * 14, 0xcccccc, 1);\n }\n host::display::fill_rect(0, 0, 512, 24, 0x1a1d22);\n host::display::draw_string(8, 8, \"PAGER TOP=UP BOTTOM=DOWN\", 0x888888, 1);\n host::display::draw_number(300, 6, off2 + 1, 0xffffff, 1);\n host::display::draw_string(330, 8, \"OF\", 0x888888, 1);\n host::display::draw_number(354, 6, total, 0xffffff, 1);\n } else {\n host::display::draw_string(150, 240, \"FETCH FAILED\", 0xbb3333, 2);\n }\n host::display::present();\n}\n",
"tags": [
"http",
"pager",
"interaction"
]
}