Changes in uspace/lib/ui/src/pbutton.c [174be87:3c54869] in mainline
- File:
-
- 1 edited
-
uspace/lib/ui/src/pbutton.c (modified) (9 diffs)
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/ui/src/pbutton.c
r174be87 r3c54869 1 1 /* 2 * Copyright (c) 202 2Jiri Svoboda2 * Copyright (c) 2023 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 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 … … 114 116 115 117 ui_control_delete(pbutton->control); 118 free(pbutton->caption); 116 119 free(pbutton); 117 120 } … … 183 186 { 184 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; 185 227 } 186 228 … … 303 345 gfx_text_fmt_t fmt; 304 346 gfx_rect_t rect; 347 gfx_rect_t irect; 305 348 gfx_coord_t thickness; 349 gfx_color_t *color; 306 350 bool depressed; 307 351 errno_t rc; … … 315 359 rect.p1.y = pbutton->rect.p1.y - thickness; 316 360 317 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); 318 365 if (rc != EOK) 319 366 goto error; … … 340 387 } else { 341 388 /* Text decoration */ 389 ui_paint_get_inset_frame_inside(pbutton->res, &rect, &irect); 342 390 gfx_text_fmt_init(&fmt); 343 391 fmt.font = pbutton->res->font; … … 345 393 fmt.halign = gfx_halign_center; 346 394 fmt.valign = gfx_valign_center; 395 fmt.abbreviate = true; 396 fmt.width = irect.p1.x - irect.p0.x - 2 * ui_pb_pad_x; 347 397 348 398 rc = gfx_puttext(&pos, &fmt, pbutton->caption); … … 422 472 fmt.halign = gfx_halign_center; 423 473 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; 424 478 425 479 rc = gfx_puttext(&pos, &fmt, pbutton->caption);
Note:
See TracChangeset
for help on using the changeset viewer.
