Changeset bd16113 in mainline
- Timestamp:
- 2022-03-15T10:39:27Z (3 years ago)
- Branches:
- master, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 0eca788
- Parents:
- b3b48f4
- git-author:
- Jiri Svoboda <jiri@…> (2022-03-14 19:39:16)
- git-committer:
- Jiri Svoboda <jiri@…> (2022-03-15 10:39:27)
- Location:
- uspace
- Files:
-
- 4 added
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/uidemo/uidemo.c
rb3b48f4 rbd16113 87 87 }; 88 88 89 static void scrollbar_up(ui_scrollbar_t *, void *); 90 static void scrollbar_down(ui_scrollbar_t *, void *); 91 static void scrollbar_moved(ui_scrollbar_t *, void *, gfx_coord_t); 92 93 static ui_scrollbar_cb_t scrollbar_cb = { 94 .up = scrollbar_up, 95 .down = scrollbar_down, 96 .moved = scrollbar_moved 97 }; 98 89 99 static void uidemo_file_load(ui_menu_entry_t *, void *); 90 100 static void uidemo_file_message(ui_menu_entry_t *, void *); … … 202 212 rv = asprintf(&str, "Slider at %d of %d", (int) pos, 203 213 ui_slider_length(slider)); 214 if (rv < 0) { 215 printf("Out of memory.\n"); 216 return; 217 } 218 219 rc = ui_entry_set_text(demo->entry, str); 220 if (rc != EOK) 221 printf("Error changing entry text.\n"); 222 (void) ui_entry_paint(demo->entry); 223 224 free(str); 225 } 226 227 /** Scrollbar up button pressed. 228 * 229 * @param scrollbar Scrollbar 230 * @param arg Argument (demo) 231 */ 232 static void scrollbar_up(ui_scrollbar_t *scrollbar, void *arg) 233 { 234 ui_demo_t *demo = (ui_demo_t *) arg; 235 gfx_coord_t pos; 236 char *str; 237 errno_t rc; 238 int rv; 239 240 pos = ui_scrollbar_get_pos(scrollbar); 241 ui_scrollbar_set_pos(scrollbar, pos - 1); 242 243 pos = ui_scrollbar_get_pos(scrollbar); 244 245 rv = asprintf(&str, "Scrollbar: %d of %d", (int) pos, 246 ui_scrollbar_move_length(scrollbar)); 247 if (rv < 0) { 248 printf("Out of memory.\n"); 249 return; 250 } 251 252 rc = ui_entry_set_text(demo->entry, str); 253 if (rc != EOK) 254 printf("Error changing entry text.\n"); 255 (void) ui_entry_paint(demo->entry); 256 257 free(str); 258 } 259 260 /** Scrollbar down button pressed. 261 * 262 * @param scrollbar Scrollbar 263 * @param arg Argument (demo) 264 */ 265 static void scrollbar_down(ui_scrollbar_t *scrollbar, void *arg) 266 { 267 ui_demo_t *demo = (ui_demo_t *) arg; 268 gfx_coord_t pos; 269 char *str; 270 errno_t rc; 271 int rv; 272 273 pos = ui_scrollbar_get_pos(scrollbar); 274 ui_scrollbar_set_pos(scrollbar, pos + 1); 275 276 pos = ui_scrollbar_get_pos(scrollbar); 277 278 rv = asprintf(&str, "Scrollbar: %d of %d", (int) pos, 279 ui_scrollbar_move_length(scrollbar)); 280 if (rv < 0) { 281 printf("Out of memory.\n"); 282 return; 283 } 284 285 rc = ui_entry_set_text(demo->entry, str); 286 if (rc != EOK) 287 printf("Error changing entry text.\n"); 288 (void) ui_entry_paint(demo->entry); 289 290 free(str); 291 } 292 293 /** Scrollbar was moved. 294 * 295 * @param scrollbar Scrollbar 296 * @param arg Argument (demo) 297 * @param pos Position 298 */ 299 static void scrollbar_moved(ui_scrollbar_t *scrollbar, void *arg, 300 gfx_coord_t pos) 301 { 302 ui_demo_t *demo = (ui_demo_t *) arg; 303 char *str; 304 errno_t rc; 305 int rv; 306 307 rv = asprintf(&str, "Scrollbar: %d of %d", (int) pos, 308 ui_scrollbar_move_length(scrollbar)); 204 309 if (rv < 0) { 205 310 printf("Out of memory.\n"); … … 507 612 params.rect.p0.y = 0; 508 613 params.rect.p1.x = 44; 509 params.rect.p1.y = 2 1;614 params.rect.p1.y = 23; 510 615 } else { 511 616 params.rect.p0.x = 0; 512 617 params.rect.p0.y = 0; 513 618 params.rect.p1.x = 220; 514 params.rect.p1.y = 3 50;619 params.rect.p1.y = 370; 515 620 } 516 621 … … 956 1061 957 1062 rc = ui_fixed_add(demo.fixed, ui_slider_ctl(demo.slider)); 1063 if (rc != EOK) { 1064 printf("Error adding control to layout.\n"); 1065 return rc; 1066 } 1067 1068 rc = ui_scrollbar_create(ui_res, &demo.scrollbar); 1069 if (rc != EOK) { 1070 printf("Error creating button.\n"); 1071 return rc; 1072 } 1073 1074 ui_scrollbar_set_cb(demo.scrollbar, &scrollbar_cb, (void *) &demo); 1075 1076 /* FIXME: Auto layout */ 1077 if (ui_is_textmode(ui)) { 1078 rect.p0.x = 2; 1079 rect.p0.y = 20; 1080 rect.p1.x = 12; 1081 rect.p1.y = 21; 1082 } else { 1083 rect.p0.x = 15; 1084 rect.p0.y = 340; 1085 rect.p1.x = 210; 1086 rect.p1.y = 362; 1087 } 1088 1089 ui_scrollbar_set_rect(demo.scrollbar, &rect); 1090 1091 ui_scrollbar_set_thumb_length(demo.scrollbar, 1092 ui_scrollbar_through_length(demo.scrollbar) / 4); 1093 1094 rc = ui_fixed_add(demo.fixed, ui_scrollbar_ctl(demo.scrollbar)); 958 1095 if (rc != EOK) { 959 1096 printf("Error adding control to layout.\n"); -
uspace/app/uidemo/uidemo.h
rb3b48f4 rbd16113 1 1 /* 2 * Copyright (c) 202 1Jiri Svoboda2 * Copyright (c) 2022 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 46 46 #include <ui/pbutton.h> 47 47 #include <ui/rbutton.h> 48 #include <ui/scrollbar.h> 48 49 #include <ui/slider.h> 49 50 #include <ui/ui.h> … … 71 72 ui_rbutton_t *rbright; 72 73 ui_slider_t *slider; 74 ui_scrollbar_t *scrollbar; 73 75 } ui_demo_t; 74 76 -
uspace/lib/ui/meson.build
rb3b48f4 rbd16113 48 48 'src/rbutton.c', 49 49 'src/resource.c', 50 'src/scrollbar.c', 50 51 'src/slider.c', 51 52 'src/ui.c', -
uspace/lib/ui/private/resource.h
rb3b48f4 rbd16113 1 1 /* 2 * Copyright (c) 202 1Jiri Svoboda2 * Copyright (c) 2022 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 114 114 gfx_color_t *entry_sel_text_bg_color; 115 115 116 /** Scrollbar through color */ 117 gfx_color_t *sbar_through_color; 118 116 119 /** Expose callback or @c NULL */ 117 120 ui_expose_cb_t expose_cb; -
uspace/lib/ui/src/resource.c
rb3b48f4 rbd16113 84 84 gfx_color_t *entry_sel_text_fg_color = NULL; 85 85 gfx_color_t *entry_sel_text_bg_color = NULL; 86 gfx_color_t *sbar_through_color = NULL; 86 87 errno_t rc; 87 88 … … 205 206 206 207 rc = gfx_color_new_rgb_i16(0, 0, 0xffff, &entry_sel_text_bg_color); 208 if (rc != EOK) 209 goto error; 210 211 rc = gfx_color_new_rgb_i16(0xe4e4, 0xe4e4, 0xe4e4, 212 &sbar_through_color); 207 213 if (rc != EOK) 208 214 goto error; … … 240 246 resource->entry_sel_text_fg_color = entry_sel_text_fg_color; 241 247 resource->entry_sel_text_bg_color = entry_sel_text_bg_color; 248 249 resource->sbar_through_color = sbar_through_color; 242 250 243 251 *rresource = resource; … … 295 303 if (entry_act_bg_color != NULL) 296 304 gfx_color_delete(entry_act_bg_color); 305 306 if (sbar_through_color != NULL) 307 gfx_color_delete(sbar_through_color); 297 308 298 309 if (tface != NULL) … … 338 349 gfx_color_t *entry_sel_text_bg_color = NULL; 339 350 gfx_color_t *entry_act_bg_color = NULL; 351 gfx_color_t *sbar_through_color = NULL; 340 352 errno_t rc; 341 353 … … 446 458 447 459 rc = gfx_color_new_ega(0x37, &entry_act_bg_color); 460 if (rc != EOK) 461 goto error; 462 463 rc = gfx_color_new_ega(0x07, &sbar_through_color); 448 464 if (rc != EOK) 449 465 goto error; … … 481 497 resource->entry_sel_text_fg_color = entry_sel_text_fg_color; 482 498 resource->entry_sel_text_bg_color = entry_sel_text_bg_color; 499 500 resource->sbar_through_color = sbar_through_color; 483 501 484 502 *rresource = resource; … … 536 554 if (entry_sel_text_bg_color != NULL) 537 555 gfx_color_delete(entry_sel_text_bg_color); 556 if (sbar_through_color != NULL) 557 gfx_color_delete(sbar_through_color); 538 558 539 559 if (tface != NULL) … … 594 614 gfx_color_delete(resource->entry_sel_text_bg_color); 595 615 616 gfx_color_delete(resource->sbar_through_color); 617 596 618 gfx_font_close(resource->font); 597 619 gfx_typeface_destroy(resource->tface); -
uspace/lib/ui/src/slider.c
rb3b48f4 rbd16113 1 1 /* 2 * Copyright (c) 202 1Jiri Svoboda2 * Copyright (c) 2022 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 60 60 /** Slider button width in text mode */ 61 61 ui_slider_btn_w_text = 3, 62 /** Slider button height in text mode */ 63 ui_slider_btn_h_text = 1, 62 64 /** Slider button frame thickness */ 63 65 ui_slider_btn_frame_thickness = 1, … … 242 244 rect->p0.x = pos.x; 243 245 rect->p0.y = pos.y; 244 rect->p1.x = pos.x + ui_slider_btn_w; 245 rect->p1.y = pos.y + ui_slider_btn_h; 246 247 if (slider->res->textmode) { 248 rect->p1.x = pos.x + ui_slider_btn_w_text; 249 rect->p1.y = pos.y + ui_slider_btn_h_text; 250 } else { 251 rect->p1.x = pos.x + ui_slider_btn_w; 252 rect->p1.y = pos.y + ui_slider_btn_h; 253 } 246 254 } 247 255
Note:
See TracChangeset
for help on using the changeset viewer.