Changes in uspace/lib/ui/src/pbutton.c [3c54869:cd74fa8] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/ui/src/pbutton.c
r3c54869 rcd74fa8 1 1 /* 2 * Copyright (c) 202 3Jiri Svoboda2 * Copyright (c) 2021 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 32 32 /** 33 33 * @file Push button 34 *35 * Push button either uses text as decoration, or it can use a caller-provided36 * function to paint the decoration.37 34 */ 38 35 … … 54 51 enum { 55 52 ui_pb_press_dx = 1, 56 ui_pb_press_dy = 1, 57 ui_pb_pad_x = 2, 58 ui_pb_pad_x_text = 1 53 ui_pb_press_dy = 1 59 54 }; 60 55 … … 116 111 117 112 ui_control_delete(pbutton->control); 118 free(pbutton->caption);119 113 free(pbutton); 120 114 } … … 142 136 } 143 137 144 /** Set push button decoration ops.145 *146 * @param pbutton Push button147 * @param ops Push button decoration callbacks148 * @param arg Decoration ops argument149 */150 void ui_pbutton_set_decor_ops(ui_pbutton_t *pbutton,151 ui_pbutton_decor_ops_t *ops, void *arg)152 {153 pbutton->decor_ops = ops;154 pbutton->decor_arg = arg;155 }156 157 /** Set push button flag.s158 *159 * @param pbutton Push button160 * @param flags Flags161 */162 void ui_pbutton_set_flags(ui_pbutton_t *pbutton, ui_pbutton_flags_t flags)163 {164 pbutton->flags = flags;165 }166 167 138 /** Set button rectangle. 168 139 * … … 186 157 { 187 158 pbutton->isdefault = isdefault; 188 }189 190 /** Get button light status.191 *192 * @param pbutton Button193 * @return @c true iff light is on194 */195 bool ui_pbutton_get_light(ui_pbutton_t *pbutton)196 {197 return pbutton->light;198 }199 200 /** Turn button light on or off.201 *202 * @param pbutton Button203 * @param light @c true iff button should be lit204 */205 void ui_pbutton_set_light(ui_pbutton_t *pbutton, bool light)206 {207 pbutton->light = light;208 }209 210 /** Set push button caption.211 *212 * @param pbutton Button213 * @param caption New caption214 * @return EOK on success, ENOMEM if out of memory215 */216 errno_t ui_pbutton_set_caption(ui_pbutton_t *pbutton, const char *caption)217 {218 char *dcaption;219 220 dcaption = str_dup(caption);221 if (dcaption == NULL)222 return ENOMEM;223 224 free(pbutton->caption);225 pbutton->caption = dcaption;226 return EOK;227 159 } 228 160 … … 345 277 gfx_text_fmt_t fmt; 346 278 gfx_rect_t rect; 347 gfx_rect_t irect;348 279 gfx_coord_t thickness; 349 gfx_color_t *color;350 280 bool depressed; 351 281 errno_t rc; … … 359 289 rect.p1.y = pbutton->rect.p1.y - thickness; 360 290 361 color = pbutton->light ? pbutton->res->btn_face_lit_color : 362 pbutton->res->btn_face_color; 363 364 rc = gfx_set_color(pbutton->res->gc, color); 291 rc = gfx_set_color(pbutton->res->gc, pbutton->res->btn_face_color); 365 292 if (rc != EOK) 366 293 goto error; … … 379 306 } 380 307 381 if (pbutton->decor_ops != NULL && pbutton->decor_ops->paint != NULL) { 382 /* Custom decoration */ 383 rc = pbutton->decor_ops->paint(pbutton, pbutton->decor_arg, 384 &pos); 385 if (rc != EOK) 386 goto error; 387 } else { 388 /* Text decoration */ 389 ui_paint_get_inset_frame_inside(pbutton->res, &rect, &irect); 390 gfx_text_fmt_init(&fmt); 391 fmt.font = pbutton->res->font; 392 fmt.color = pbutton->res->btn_text_color; 393 fmt.halign = gfx_halign_center; 394 fmt.valign = gfx_valign_center; 395 fmt.abbreviate = true; 396 fmt.width = irect.p1.x - irect.p0.x - 2 * ui_pb_pad_x; 397 398 rc = gfx_puttext(&pos, &fmt, pbutton->caption); 399 if (rc != EOK) 400 goto error; 401 } 308 gfx_text_fmt_init(&fmt); 309 fmt.color = pbutton->res->btn_text_color; 310 fmt.halign = gfx_halign_center; 311 fmt.valign = gfx_valign_center; 312 313 rc = gfx_puttext(pbutton->res->font, &pos, &fmt, pbutton->caption); 314 if (rc != EOK) 315 goto error; 402 316 403 317 rc = ui_pbutton_paint_frame(pbutton); … … 437 351 errno_t rc; 438 352 439 if ((pbutton->flags & ui_pbf_no_text_depress) == 0) 440 depressed = pbutton->held && pbutton->inside; 441 else 442 depressed = false; 353 depressed = pbutton->held && pbutton->inside; 443 354 444 355 rc = gfx_set_color(pbutton->res->gc, pbutton->res->wnd_face_color); … … 455 366 rect.p1.y = pbutton->rect.p0.y + 1; 456 367 457 rc = gfx_set_color(pbutton->res->gc, pbutton->res->btn_ face_color);368 rc = gfx_set_color(pbutton->res->gc, pbutton->res->btn_highlight_color); 458 369 if (rc != EOK) 459 370 goto error; … … 468 379 469 380 gfx_text_fmt_init(&fmt); 470 fmt.font = pbutton->res->font;471 381 fmt.color = pbutton->res->btn_text_color; 472 382 fmt.halign = gfx_halign_center; 473 383 fmt.valign = gfx_valign_center; 474 fmt.abbreviate = true; 475 fmt.width = rect.p1.x - rect.p0.x - 2 * ui_pb_pad_x_text; 476 if (fmt.width < 1) 477 fmt.width = 1; 478 479 rc = gfx_puttext(&pos, &fmt, pbutton->caption); 384 385 rc = gfx_puttext(pbutton->res->font, &pos, &fmt, pbutton->caption); 480 386 if (rc != EOK) 481 387 goto error; … … 521 427 pbutton->held = true; 522 428 (void) ui_pbutton_paint(pbutton); 523 ui_pbutton_down(pbutton);524 429 } 525 430 … … 534 439 535 440 pbutton->held = false; 536 ui_pbutton_up(pbutton);537 441 538 442 if (pbutton->inside) { … … 570 474 } 571 475 572 /** Send button clicked event.476 /** Button was clicked. 573 477 * 574 478 * @param pbutton Push button … … 578 482 if (pbutton->cb != NULL && pbutton->cb->clicked != NULL) 579 483 pbutton->cb->clicked(pbutton, pbutton->arg); 580 }581 582 /** Send button down event.583 *584 * @param pbutton Push button585 */586 void ui_pbutton_down(ui_pbutton_t *pbutton)587 {588 if (pbutton->cb != NULL && pbutton->cb->down != NULL)589 pbutton->cb->down(pbutton, pbutton->arg);590 }591 592 /** Send button up event.593 *594 * @param pbutton Push button595 */596 void ui_pbutton_up(ui_pbutton_t *pbutton)597 {598 if (pbutton->cb != NULL && pbutton->cb->up != NULL)599 pbutton->cb->up(pbutton, pbutton->arg);600 484 } 601 485 … … 637 521 } 638 522 break; 639 case POS_DCLICK:640 break;641 523 } 642 524
Note:
See TracChangeset
for help on using the changeset viewer.