Changes in uspace/lib/ui/src/pbutton.c [bc52b5b:3c54869] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/ui/src/pbutton.c
rbc52b5b r3c54869 1 1 /* 2 * Copyright (c) 202 1Jiri Svoboda2 * Copyright (c) 2023 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-provided 36 * function to paint the decoration. 34 37 */ 35 38 … … 51 54 enum { 52 55 ui_pb_press_dx = 1, 53 ui_pb_press_dy = 1 56 ui_pb_press_dy = 1, 57 ui_pb_pad_x = 2, 58 ui_pb_pad_x_text = 1 54 59 }; 55 60 … … 111 116 112 117 ui_control_delete(pbutton->control); 118 free(pbutton->caption); 113 119 free(pbutton); 114 120 } … … 136 142 } 137 143 144 /** Set push button decoration ops. 145 * 146 * @param pbutton Push button 147 * @param ops Push button decoration callbacks 148 * @param arg Decoration ops argument 149 */ 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.s 158 * 159 * @param pbutton Push button 160 * @param flags Flags 161 */ 162 void ui_pbutton_set_flags(ui_pbutton_t *pbutton, ui_pbutton_flags_t flags) 163 { 164 pbutton->flags = flags; 165 } 166 138 167 /** Set button rectangle. 139 168 * … … 157 186 { 158 187 pbutton->isdefault = isdefault; 188 } 189 190 /** Get button light status. 191 * 192 * @param pbutton Button 193 * @return @c true iff light is on 194 */ 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 Button 203 * @param light @c true iff button should be lit 204 */ 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 Button 213 * @param caption New caption 214 * @return EOK on success, ENOMEM if out of memory 215 */ 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; 159 227 } 160 228 … … 277 345 gfx_text_fmt_t fmt; 278 346 gfx_rect_t rect; 347 gfx_rect_t irect; 279 348 gfx_coord_t thickness; 349 gfx_color_t *color; 280 350 bool depressed; 281 351 errno_t rc; … … 289 359 rect.p1.y = pbutton->rect.p1.y - thickness; 290 360 291 rc = gfx_set_color(pbutton->res->gc, pbutton->res->btn_face_color); 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); 292 365 if (rc != EOK) 293 366 goto error; … … 306 379 } 307 380 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; 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 } 316 402 317 403 rc = ui_pbutton_paint_frame(pbutton); … … 351 437 errno_t rc; 352 438 353 depressed = pbutton->held && pbutton->inside; 439 if ((pbutton->flags & ui_pbf_no_text_depress) == 0) 440 depressed = pbutton->held && pbutton->inside; 441 else 442 depressed = false; 354 443 355 444 rc = gfx_set_color(pbutton->res->gc, pbutton->res->wnd_face_color); … … 379 468 380 469 gfx_text_fmt_init(&fmt); 470 fmt.font = pbutton->res->font; 381 471 fmt.color = pbutton->res->btn_text_color; 382 472 fmt.halign = gfx_halign_center; 383 473 fmt.valign = gfx_valign_center; 384 385 rc = gfx_puttext(pbutton->res->font, &pos, &fmt, pbutton->caption); 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); 386 480 if (rc != EOK) 387 481 goto error; … … 427 521 pbutton->held = true; 428 522 (void) ui_pbutton_paint(pbutton); 523 ui_pbutton_down(pbutton); 429 524 } 430 525 … … 439 534 440 535 pbutton->held = false; 536 ui_pbutton_up(pbutton); 441 537 442 538 if (pbutton->inside) { … … 474 570 } 475 571 476 /** Button was clicked.572 /** Send button clicked event. 477 573 * 478 574 * @param pbutton Push button … … 482 578 if (pbutton->cb != NULL && pbutton->cb->clicked != NULL) 483 579 pbutton->cb->clicked(pbutton, pbutton->arg); 580 } 581 582 /** Send button down event. 583 * 584 * @param pbutton Push button 585 */ 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 button 595 */ 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); 484 600 } 485 601 … … 521 637 } 522 638 break; 639 case POS_DCLICK: 640 break; 523 641 } 524 642
Note:
See TracChangeset
for help on using the changeset viewer.