Changeset bd16113 in mainline for uspace/app/uidemo/uidemo.c
- Timestamp:
- 2022-03-15T10:39:27Z (2 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)
- File:
-
- 1 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");
Note:
See TracChangeset
for help on using the changeset viewer.