Changeset 307d4d2 in mainline
- Timestamp:
- 2021-08-13T10:57:34Z (3 years ago)
- Branches:
- master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 297b1b3
- Parents:
- 5e109e1
- git-author:
- Jiri Svoboda <jiri@…> (2020-08-12 19:55:53)
- git-committer:
- Jiri Svoboda <jiri@…> (2021-08-13 10:57:34)
- Location:
- uspace
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/uidemo/uidemo.c
r5e109e1 r307d4d2 229 229 } 230 230 231 232 231 /** File/load menu entry selected. 233 232 * … … 717 716 ui_checkbox_set_cb(demo.checkbox, &checkbox_cb, (void *) &demo); 718 717 719 rect.p0.x = 15; 720 rect.p0.y = 190; 721 rect.p1.x = 140; 722 rect.p1.y = 210; 718 /* FIXME: Auto layout */ 719 if (ui_is_textmode(ui)) { 720 rect.p0.x = 20; 721 rect.p0.y = 12; 722 rect.p1.x = 40; 723 rect.p1.y = 13; 724 } else { 725 rect.p0.x = 15; 726 rect.p0.y = 190; 727 rect.p1.x = 140; 728 rect.p1.y = 210; 729 } 723 730 ui_checkbox_set_rect(demo.checkbox, &rect); 724 731 -
uspace/lib/ui/private/checkbox.h
r5e109e1 r307d4d2 1 1 /* 2 * Copyright (c) 202 0Jiri Svoboda2 * Copyright (c) 2021 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 66 66 }; 67 67 68 extern errno_t ui_checkbox_paint_gfx(ui_checkbox_t *); 69 extern errno_t ui_checkbox_paint_text(ui_checkbox_t *); 70 68 71 #endif 69 72 -
uspace/lib/ui/src/checkbox.c
r5e109e1 r307d4d2 146 146 } 147 147 148 /** Paint check box .148 /** Paint check box in graphics mode. 149 149 * 150 150 * @param checkbox Check box 151 151 * @return EOK on success or an error code 152 152 */ 153 errno_t ui_checkbox_paint (ui_checkbox_t *checkbox)153 errno_t ui_checkbox_paint_gfx(ui_checkbox_t *checkbox) 154 154 { 155 155 gfx_coord2_t pos; … … 222 222 error: 223 223 return rc; 224 } 225 226 /** Paint check box in text mode. 227 * 228 * @param checkbox Check box 229 * @return EOK on success or an error code 230 */ 231 errno_t ui_checkbox_paint_text(ui_checkbox_t *checkbox) 232 { 233 gfx_coord2_t pos; 234 gfx_text_fmt_t fmt; 235 bool depressed; 236 errno_t rc; 237 238 /* Paint checkbox */ 239 240 depressed = checkbox->held && checkbox->inside; 241 242 pos.x = checkbox->rect.p0.x; 243 pos.y = checkbox->rect.p0.y; 244 245 gfx_text_fmt_init(&fmt); 246 fmt.color = depressed ? checkbox->res->entry_act_bg_color : 247 checkbox->res->wnd_text_color; 248 fmt.halign = gfx_halign_left; 249 fmt.valign = gfx_valign_top; 250 251 rc = gfx_puttext(checkbox->res->font, &pos, &fmt, 252 checkbox->checked ? "[X]" : "[ ]"); 253 if (rc != EOK) 254 goto error; 255 256 /* Paint checkbox label */ 257 258 pos.x += 4; 259 fmt.color = checkbox->res->wnd_text_color; 260 261 rc = gfx_puttext(checkbox->res->font, &pos, &fmt, checkbox->caption); 262 if (rc != EOK) 263 goto error; 264 265 rc = gfx_update(checkbox->res->gc); 266 if (rc != EOK) 267 goto error; 268 269 return EOK; 270 error: 271 return rc; 272 } 273 274 /** Paint check box. 275 * 276 * @param checkbox Check box 277 * @return EOK on success or an error code 278 */ 279 errno_t ui_checkbox_paint(ui_checkbox_t *checkbox) 280 { 281 if (checkbox->res->textmode) 282 return ui_checkbox_paint_text(checkbox); 283 else 284 return ui_checkbox_paint_gfx(checkbox); 224 285 } 225 286 -
uspace/lib/ui/test/checkbox.c
r5e109e1 r307d4d2 151 151 } 152 152 153 /** Paint check box */154 PCUT_TEST(paint )153 /** Paint check box in graphics mode */ 154 PCUT_TEST(paint_gfx) 155 155 { 156 156 errno_t rc; … … 171 171 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 172 172 173 rc = ui_checkbox_paint(checkbox); 173 rc = ui_checkbox_paint_gfx(checkbox); 174 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 175 176 ui_checkbox_destroy(checkbox); 177 ui_resource_destroy(resource); 178 179 rc = gfx_context_delete(gc); 180 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 181 } 182 183 /** Paint check box in text mode */ 184 PCUT_TEST(paint_text) 185 { 186 errno_t rc; 187 gfx_context_t *gc = NULL; 188 test_gc_t tgc; 189 ui_resource_t *resource = NULL; 190 ui_checkbox_t *checkbox; 191 192 memset(&tgc, 0, sizeof(tgc)); 193 rc = gfx_context_new(&ops, &tgc, &gc); 194 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 195 196 rc = ui_resource_create(gc, true, &resource); 197 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 198 PCUT_ASSERT_NOT_NULL(resource); 199 200 rc = ui_checkbox_create(resource, "Hello", &checkbox); 201 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 202 203 rc = ui_checkbox_paint_text(checkbox); 174 204 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 175 205
Note:
See TracChangeset
for help on using the changeset viewer.