Changeset 943f032 in mainline
- Timestamp:
- 2021-08-13T22:27:15Z (3 years ago)
- Branches:
- master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- de0c55a
- Parents:
- ce0a5af
- Location:
- uspace
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/uidemo/uidemo.c
rce0a5af r943f032 835 835 ui_slider_set_cb(demo.slider, &slider_cb, (void *) &demo); 836 836 837 rect.p0.x = 15; 838 rect.p0.y = 310; 839 rect.p1.x = 130; 840 rect.p1.y = 330; 837 /* FIXME: Auto layout */ 838 if (ui_is_textmode(ui)) { 839 rect.p0.x = 20; 840 rect.p0.y = 18; 841 rect.p1.x = 40; 842 rect.p1.y = 19; 843 } else { 844 rect.p0.x = 15; 845 rect.p0.y = 310; 846 rect.p1.x = 130; 847 rect.p1.y = 330; 848 } 849 841 850 ui_slider_set_rect(demo.slider, &rect); 842 851 -
uspace/lib/ui/private/slider.h
rce0a5af r943f032 66 66 }; 67 67 68 extern errno_t ui_slider_paint_gfx(ui_slider_t *); 69 extern errno_t ui_slider_paint_text(ui_slider_t *); 70 68 71 #endif 69 72 -
uspace/lib/ui/src/slider.c
rce0a5af r943f032 38 38 #include <gfx/context.h> 39 39 #include <gfx/render.h> 40 #include <gfx/text.h> 40 41 #include <io/pos_event.h> 41 42 #include <stdlib.h> … … 57 58 /** Slider button height */ 58 59 ui_slider_btn_h = 23, 60 /** Slider button width in text mode */ 61 ui_slider_btn_w_text = 3, 59 62 /** Slider button frame thickness */ 60 63 ui_slider_btn_frame_thickness = 1, … … 251 254 { 252 255 gfx_coord2_t dims; 256 gfx_coord_t w; 253 257 254 258 gfx_rect_dims(&slider->rect, &dims); 255 return dims.x - ui_slider_btn_w; 256 } 257 258 /** Paint slider. 259 * 260 * @param slider Slider 261 * @return EOK on success or an error code 262 */ 263 errno_t ui_slider_paint(ui_slider_t *slider) 259 w = slider->res->textmode ? ui_slider_btn_w_text : 260 ui_slider_btn_w; 261 return dims.x - w; 262 } 263 264 /** Paint slider in graphics mode. 265 * 266 * @param slider Slider 267 * @return EOK on success or an error code 268 */ 269 errno_t ui_slider_paint_gfx(ui_slider_t *slider) 264 270 { 265 271 gfx_coord2_t pos; … … 315 321 } 316 322 323 /** Paint slider in text mode. 324 * 325 * @param slider Slider 326 * @return EOK on success or an error code 327 */ 328 errno_t ui_slider_paint_text(ui_slider_t *slider) 329 { 330 gfx_coord2_t pos; 331 gfx_text_fmt_t fmt; 332 gfx_coord_t w, i; 333 char *buf; 334 errno_t rc; 335 336 /* Paint slider groove */ 337 338 pos = slider->rect.p0; 339 340 gfx_text_fmt_init(&fmt); 341 fmt.color = slider->res->wnd_text_color; 342 fmt.halign = gfx_halign_left; 343 fmt.valign = gfx_valign_top; 344 345 w = slider->rect.p1.x - slider->rect.p0.x; 346 buf = malloc(w + 1); 347 if (buf == NULL) 348 return ENOMEM; 349 350 for (i = 0; i < w; i++) 351 buf[i] = '='; 352 buf[w] = '\0'; 353 354 rc = gfx_puttext(slider->res->font, &pos, &fmt, buf); 355 free(buf); 356 if (rc != EOK) 357 goto error; 358 359 /* Paint slider button */ 360 361 pos.x += slider->pos; 362 363 rc = gfx_puttext(slider->res->font, &pos, &fmt, 364 "[O]"); 365 if (rc != EOK) 366 goto error; 367 368 rc = gfx_update(slider->res->gc); 369 if (rc != EOK) 370 goto error; 371 372 return EOK; 373 error: 374 return rc; 375 } 376 377 /** Paint slider. 378 * 379 * @param slider Slider 380 * @return EOK on success or an error code 381 */ 382 errno_t ui_slider_paint(ui_slider_t *slider) 383 { 384 if (slider->res->textmode) 385 return ui_slider_paint_text(slider); 386 else 387 return ui_slider_paint_gfx(slider); 388 } 389 317 390 /** Clear slider button. 318 391 * … … 324 397 gfx_rect_t rect; 325 398 errno_t rc; 399 400 /* No need to clear button in text mode */ 401 if (slider->res->textmode) 402 return EOK; 326 403 327 404 ui_slider_btn_rect(slider, &rect); -
uspace/lib/ui/test/slider.c
rce0a5af r943f032 152 152 } 153 153 154 /** Paint slider */155 PCUT_TEST(paint )154 /** Paint slider in graphics mode */ 155 PCUT_TEST(paint_gfx) 156 156 { 157 157 errno_t rc; … … 172 172 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 173 173 174 rc = ui_slider_paint(slider); 174 rc = ui_slider_paint_gfx(slider); 175 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 176 177 ui_slider_destroy(slider); 178 ui_resource_destroy(resource); 179 180 rc = gfx_context_delete(gc); 181 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 182 } 183 184 /** Paint slider in text mode */ 185 PCUT_TEST(paint_text) 186 { 187 errno_t rc; 188 gfx_context_t *gc = NULL; 189 test_gc_t tgc; 190 ui_resource_t *resource = NULL; 191 ui_slider_t *slider; 192 193 memset(&tgc, 0, sizeof(tgc)); 194 rc = gfx_context_new(&ops, &tgc, &gc); 195 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 196 197 rc = ui_resource_create(gc, false, &resource); 198 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 199 PCUT_ASSERT_NOT_NULL(resource); 200 201 rc = ui_slider_create(resource, "Hello", &slider); 202 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 203 204 rc = ui_slider_paint_text(slider); 175 205 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 176 206
Note:
See TracChangeset
for help on using the changeset viewer.