Changeset 8922b76 in mainline
- Timestamp:
- 2021-10-22T18:25:44Z (3 years ago)
- Children:
- 5e221a77
- Parents:
- 966a27d3
- Location:
- uspace/app/nav
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/nav/panel.c
r966a27d3 r8922b76 324 324 { 325 325 gfx_coord2_t pos; 326 gfx_rect_t irect; 327 panel_entry_t *entry; 328 size_t entry_idx; 329 int n; 326 330 327 331 pos.x = event->hpos; … … 330 334 return ui_unclaimed; 331 335 332 if (!panel->active ) {336 if (!panel->active && event->type == POS_PRESS) 333 337 panel_activate_req(panel); 338 339 if (event->type == POS_PRESS) { 340 irect.p0.x = panel->rect.p0.x + 1; 341 irect.p0.y = panel->rect.p0.y + 1; 342 irect.p1.x = panel->rect.p1.x - 1; 343 irect.p1.y = panel->rect.p1.y - 1; 344 345 /* Did we click on one of the entries? */ 346 if (gfx_pix_inside_rect(&pos, &irect)) { 347 /* Index within page */ 348 n = pos.y - irect.p0.y; 349 350 /* Entry and its index within entire listing */ 351 entry = panel_page_nth_entry(panel, n, &entry_idx); 352 353 /* Move to the entry found */ 354 panel_cursor_move(panel, entry, entry_idx); 355 } 334 356 } 335 357 … … 800 822 } 801 823 824 /** Find the n-th entry of the current panel page. 825 * 826 * If the page is short and has less than n+1 entries, return the last entry. 827 * 828 * @param panel Panel 829 * @param n Which entry to get (starting from 0) 830 * @param ridx Place to store index (within listing) of the entry 831 * @return n-th entry of the page 832 */ 833 panel_entry_t *panel_page_nth_entry(panel_t *panel, size_t n, size_t *ridx) 834 { 835 panel_entry_t *entry; 836 panel_entry_t *next; 837 size_t i; 838 size_t idx; 839 840 assert(n < panel_page_size(panel)); 841 842 entry = panel->page; 843 idx = panel->page_idx; 844 for (i = 0; i < n; i++) { 845 next = panel_next(entry); 846 if (next == NULL) 847 break; 848 849 entry = next; 850 ++idx; 851 } 852 853 *ridx = idx; 854 return entry; 855 } 856 802 857 /** Move cursor to a new position, possibly scrolling. 803 858 * -
uspace/app/nav/panel.h
r966a27d3 r8922b76 70 70 extern panel_entry_t *panel_next(panel_entry_t *); 71 71 extern panel_entry_t *panel_prev(panel_entry_t *); 72 extern panel_entry_t *panel_page_nth_entry(panel_t *, size_t, size_t *); 72 73 extern void panel_cursor_move(panel_t *, panel_entry_t *, size_t); 73 74 extern void panel_cursor_up(panel_t *); -
uspace/app/nav/test/panel.c
r966a27d3 r8922b76 205 205 PCUT_TEST(pos_event) 206 206 { 207 ui_t *ui; 208 ui_window_t *window; 209 ui_wnd_params_t params; 207 210 panel_t *panel; 208 211 ui_evclaim_t claimed; 209 212 pos_event_t event; 210 errno_t rc; 211 212 rc = panel_create(NULL, true, &panel); 213 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 213 gfx_rect_t rect; 214 panel_entry_attr_t attr; 215 errno_t rc; 216 217 rc = ui_create_disp(NULL, &ui); 218 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 219 220 ui_wnd_params_init(¶ms); 221 params.caption = "Test"; 222 223 rc = ui_window_create(ui, ¶ms, &window); 224 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 225 226 rc = panel_create(window, true, &panel); 227 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 228 229 rect.p0.x = 0; 230 rect.p0.y = 0; 231 rect.p1.x = 10; 232 rect.p1.y = 10; 233 panel_set_rect(panel, &rect); 234 235 panel_entry_attr_init(&attr); 236 attr.name = "a"; 237 attr.size = 1; 238 rc = panel_entry_append(panel, &attr); 239 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 240 241 attr.name = "b"; 242 attr.size = 2; 243 rc = panel_entry_append(panel, &attr); 244 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 245 246 attr.name = "c"; 247 attr.size = 3; 248 rc = panel_entry_append(panel, &attr); 249 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 250 251 panel->cursor = panel_first(panel); 252 panel->cursor_idx = 0; 253 panel->page = panel_first(panel); 254 panel->page_idx = 0; 214 255 215 256 event.pos_id = 0; 216 257 event.type = POS_PRESS; 217 258 event.btn_num = 1; 218 event.hpos = 0; 219 event.vpos = 0; 259 260 /* Clicking on the middle entry should select it */ 261 event.hpos = 1; 262 event.vpos = 2; 220 263 221 264 claimed = panel_pos_event(panel, &event); 222 PCUT_ASSERT_EQUALS(ui_unclaimed, claimed); 223 224 panel_destroy(panel); 265 PCUT_ASSERT_EQUALS(ui_claimed, claimed); 266 267 PCUT_ASSERT_NOT_NULL(panel->cursor); 268 PCUT_ASSERT_STR_EQUALS("b", panel->cursor->name); 269 PCUT_ASSERT_INT_EQUALS(2, panel->cursor->size); 270 271 /* Clicking below the last entry should select it */ 272 event.hpos = 1; 273 event.vpos = 4; 274 claimed = panel_pos_event(panel, &event); 275 PCUT_ASSERT_EQUALS(ui_claimed, claimed); 276 277 PCUT_ASSERT_NOT_NULL(panel->cursor); 278 PCUT_ASSERT_STR_EQUALS("c", panel->cursor->name); 279 PCUT_ASSERT_INT_EQUALS(3, panel->cursor->size); 280 281 panel_destroy(panel); 282 ui_window_destroy(window); 283 ui_destroy(ui); 225 284 } 226 285 … … 839 898 PCUT_ASSERT_STR_EQUALS("a", entry->name); 840 899 PCUT_ASSERT_INT_EQUALS(1, entry->size); 900 901 panel_destroy(panel); 902 } 903 904 /** panel_page_nth_entry() .. */ 905 PCUT_TEST(page_nth_entry) 906 { 907 panel_t *panel; 908 panel_entry_t *entry; 909 panel_entry_attr_t attr; 910 size_t idx; 911 errno_t rc; 912 913 rc = panel_create(NULL, true, &panel); 914 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 915 916 panel_entry_attr_init(&attr); 917 918 /* Add some entries */ 919 attr.name = "a"; 920 attr.size = 1; 921 rc = panel_entry_append(panel, &attr); 922 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 923 924 attr.name = "b"; 925 attr.size = 2; 926 rc = panel_entry_append(panel, &attr); 927 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 928 929 attr.name = "c"; 930 attr.size = 3; 931 rc = panel_entry_append(panel, &attr); 932 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 933 934 panel->page = panel_next(panel_first(panel)); 935 panel->page_idx = 1; 936 937 entry = panel_page_nth_entry(panel, 0, &idx); 938 PCUT_ASSERT_STR_EQUALS("b", entry->name); 939 PCUT_ASSERT_INT_EQUALS(1, idx); 940 941 entry = panel_page_nth_entry(panel, 1, &idx); 942 PCUT_ASSERT_STR_EQUALS("c", entry->name); 943 PCUT_ASSERT_INT_EQUALS(2, idx); 944 945 entry = panel_page_nth_entry(panel, 2, &idx); 946 PCUT_ASSERT_STR_EQUALS("c", entry->name); 947 PCUT_ASSERT_INT_EQUALS(2, idx); 948 949 entry = panel_page_nth_entry(panel, 3, &idx); 950 PCUT_ASSERT_STR_EQUALS("c", entry->name); 951 PCUT_ASSERT_INT_EQUALS(2, idx); 841 952 842 953 panel_destroy(panel);
Note:
See TracChangeset
for help on using the changeset viewer.