Changeset 68d68e9 in mainline
- Timestamp:
- 2022-11-23T12:50:27Z (2 years ago)
- Branches:
- master, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- c4a53280
- Parents:
- 6e91475
- Location:
- uspace
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/taskbar/test/wndlist.c
r6e91475 r68d68e9 407 407 } 408 408 409 /** Test wndlist_count() */ 410 PCUT_TEST(count) 411 { 412 errno_t rc; 413 ui_t *ui = NULL; 414 ui_wnd_params_t params; 415 ui_window_t *window = NULL; 416 ui_fixed_t *fixed = NULL; 417 wndlist_t *wndlist; 418 size_t count; 419 420 rc = ui_create_disp(NULL, &ui); 421 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 422 423 ui_wnd_params_init(¶ms); 424 params.caption = "Hello"; 425 426 rc = ui_window_create(ui, ¶ms, &window); 427 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 428 PCUT_ASSERT_NOT_NULL(window); 429 430 rc = ui_fixed_create(&fixed); 431 ui_window_add(window, ui_fixed_ctl(fixed)); 432 433 rc = wndlist_create(window, fixed, &wndlist); 434 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 435 436 count = wndlist_count(wndlist); 437 PCUT_ASSERT_INT_EQUALS(0, count); 438 439 rc = wndlist_append(wndlist, 1, "Foo", true); 440 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 441 442 count = wndlist_count(wndlist); 443 PCUT_ASSERT_INT_EQUALS(1, count); 444 445 rc = wndlist_append(wndlist, 2, "Bar", true); 446 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 447 448 count = wndlist_count(wndlist); 449 PCUT_ASSERT_INT_EQUALS(2, count); 450 451 wndlist_destroy(wndlist); 452 453 ui_window_destroy(window); 454 ui_destroy(ui); 455 } 456 409 457 /** Test repainting window list */ 410 458 PCUT_TEST(repaint) -
uspace/app/taskbar/wndlist.c
r6e91475 r68d68e9 35 35 #include <gfx/coord.h> 36 36 #include <stdbool.h> 37 #include <stddef.h> 37 38 #include <stdio.h> 38 39 #include <stdlib.h> … … 65 66 66 67 enum { 67 /** X distance between left edges of two consecutive buttons */ 68 wndlist_button_pitch = 145, 69 /** X distance between left edges of two consecutive buttons (text) */ 70 wndlist_button_pitch_text = 17, 68 /** Min. X distance between left edges of two consecutive buttons */ 69 wndlist_button_pitch_min = 85, 70 /** Max. X distance between left edges of two consecutive buttons (text) */ 71 wndlist_button_pitch_min_text = 10, 72 /** Min. X distance between left edges of two consecutive buttons */ 73 wndlist_button_pitch_max = 165, 74 /** Max. X distance between left edges of two consecutive buttons (text) */ 75 wndlist_button_pitch_max_text = 17, 71 76 /** Padding between buttons */ 72 77 wndlist_button_pad = 5, … … 197 202 wndlist_entry_t *entry = NULL; 198 203 ui_resource_t *res; 204 wndlist_entry_t *e; 199 205 errno_t rc; 200 206 … … 217 223 entry->visible = false; 218 224 219 /* Set the button rectangle and add it to layout, if applicable */ 220 wndlist_set_entry_rect(wndlist, entry); 225 /* 226 * Update rectangles for all entries, including @a entry, adding 227 * it to the layout, if applicable. 228 */ 229 e = wndlist_first(wndlist); 230 while (e != NULL) { 231 wndlist_set_entry_rect(wndlist, e); 232 e = wndlist_next(e); 233 } 221 234 222 235 /* Set button callbacks */ 223 236 ui_pbutton_set_cb(entry->button, &wndlist_button_cb, (void *)entry); 224 237 225 if (paint && entry->visible) { 226 rc = ui_pbutton_paint(entry->button); 227 if (rc != EOK) 228 goto error; 229 } 238 if (paint) 239 return wndlist_repaint(wndlist); 230 240 231 241 return EOK; … … 249 259 bool paint) 250 260 { 251 wndlist_entry_t * next;261 wndlist_entry_t *e; 252 262 assert(entry->wndlist == wndlist); 253 263 254 next = wndlist_next(entry); 255 256 ui_fixed_remove(wndlist->fixed, ui_pbutton_ctl(entry->button)); 264 if (entry->visible) 265 ui_fixed_remove(wndlist->fixed, ui_pbutton_ctl(entry->button)); 257 266 ui_pbutton_destroy(entry->button); 258 267 list_remove(&entry->lentries); 259 268 free(entry); 260 269 261 /* Update positions of the remaining entries */ 262 while (next != NULL) { 263 wndlist_set_entry_rect(wndlist, next); 264 next = wndlist_next(next); 270 /* Update positions of the all entries */ 271 e = wndlist_first(wndlist); 272 while (e != NULL) { 273 wndlist_set_entry_rect(wndlist, e); 274 e = wndlist_next(e); 265 275 } 266 276 … … 307 317 ui_resource_t *res; 308 318 gfx_coord_t pitch; 319 gfx_coord_t pitch_max; 320 gfx_coord_t pitch_min; 309 321 gfx_coord_t pad; 310 322 size_t idx; 323 size_t nbuttons; 311 324 312 325 /* Determine entry index */ … … 322 335 323 336 if (ui_resource_is_textmode(res)) { 324 pitch = wndlist_button_pitch_text; 337 pitch_max = wndlist_button_pitch_max_text; 338 pitch_min = wndlist_button_pitch_min_text; 325 339 pad = wndlist_button_pad_text; 326 340 } else { 327 pitch = wndlist_button_pitch; 341 pitch_max = wndlist_button_pitch_max; 342 pitch_min = wndlist_button_pitch_min; 328 343 pad = wndlist_button_pad; 329 344 } 345 346 /* Compute pitch that fits all buttons perfectly */ 347 nbuttons = wndlist_count(wndlist); 348 pitch = (wndlist->rect.p1.x - wndlist->rect.p0.x + pad) / nbuttons; 349 if (pitch < pitch_min) 350 pitch = pitch_min; 351 if (pitch > pitch_max) 352 pitch = pitch_max; 330 353 331 354 rect.p0.x = wndlist->rect.p0.x + pitch * idx; … … 478 501 } 479 502 503 /** Get number of window list entries. 504 * 505 * @param wndlist Window list 506 * @return Number of entries 507 */ 508 size_t wndlist_count(wndlist_t *wndlist) 509 { 510 return list_count(&wndlist->entries); 511 } 512 480 513 /** Repaint window list. 481 514 * -
uspace/app/taskbar/wndlist.h
r6e91475 r68d68e9 40 40 #include <gfx/coord.h> 41 41 #include <stdbool.h> 42 #include <stddef.h> 42 43 #include <ui/fixed.h> 43 44 #include <ui/window.h> … … 56 57 extern wndlist_entry_t *wndlist_first(wndlist_t *); 57 58 extern wndlist_entry_t *wndlist_next(wndlist_entry_t *); 59 extern size_t wndlist_count(wndlist_t *); 58 60 extern errno_t wndlist_repaint(wndlist_t *); 59 61 -
uspace/lib/ui/src/pbutton.c
r6e91475 r68d68e9 54 54 enum { 55 55 ui_pb_press_dx = 1, 56 ui_pb_press_dy = 1 56 ui_pb_press_dy = 1, 57 ui_pb_pad_x = 2, 58 ui_pb_pad_x_text = 1 57 59 }; 58 60 … … 323 325 gfx_text_fmt_t fmt; 324 326 gfx_rect_t rect; 327 gfx_rect_t irect; 325 328 gfx_coord_t thickness; 326 329 bool depressed; … … 360 363 } else { 361 364 /* Text decoration */ 365 ui_paint_get_inset_frame_inside(pbutton->res, &rect, &irect); 362 366 gfx_text_fmt_init(&fmt); 363 367 fmt.font = pbutton->res->font; … … 365 369 fmt.halign = gfx_halign_center; 366 370 fmt.valign = gfx_valign_center; 371 fmt.abbreviate = true; 372 fmt.width = irect.p1.x - irect.p0.x - 2 * ui_pb_pad_x; 367 373 368 374 rc = gfx_puttext(&pos, &fmt, pbutton->caption); … … 442 448 fmt.halign = gfx_halign_center; 443 449 fmt.valign = gfx_valign_center; 450 fmt.abbreviate = true; 451 fmt.width = rect.p1.x - rect.p0.x - 2 * ui_pb_pad_x_text; 444 452 445 453 rc = gfx_puttext(&pos, &fmt, pbutton->caption);
Note:
See TracChangeset
for help on using the changeset viewer.