Changeset 20d2c6c in mainline
- Timestamp:
- 2020-10-21T20:58:52Z (4 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 172188a
- Parents:
- ba09d06
- Location:
- uspace
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/uidemo/uidemo.c
rba09d06 r20d2c6c 66 66 }; 67 67 68 static void wd_close(ui_wdecor_t *, void *); 68 69 static void wd_move(ui_wdecor_t *, void *, gfx_coord2_t *); 69 70 70 71 static ui_wdecor_cb_t wdecor_cb = { 72 .close = wd_close, 71 73 .move = wd_move 72 74 }; 73 75 74 static bool quit = false;75 76 76 /** Print syntax. */ 77 77 static void print_syntax(void) … … 83 83 static void wnd_close_event(void *arg) 84 84 { 85 ui_demo_t *demo = (ui_demo_t *) arg; 86 85 87 printf("Close event\n"); 86 quit = true;88 demo->quit = true; 87 89 } 88 90 … … 101 103 static void wnd_kbd_event(void *arg, kbd_event_t *event) 102 104 { 105 ui_demo_t *demo = (ui_demo_t *) arg; 106 107 (void) demo; 103 108 printf("Keyboard event type=%d key=%d\n", event->type, event->key); 104 if (event->type == KEY_PRESS)105 quit = true;106 109 } 107 110 … … 156 159 } 157 160 161 /** Window decoration requested window closure. 162 * 163 * @param wdecor Window decoration 164 * @param arg Argument (demo) 165 */ 166 static void wd_close(ui_wdecor_t *wdecor, void *arg) 167 { 168 ui_demo_t *demo = (ui_demo_t *) arg; 169 170 printf("Close window requested\n"); 171 demo->quit = true; 172 } 173 158 174 /** Window decoration requested window move. 159 175 * … … 205 221 } 206 222 223 demo.quit = false; 207 224 demo.dwindow = window; 208 225 … … 318 335 } 319 336 320 while (! quit) {337 while (!demo.quit) { 321 338 fibril_usleep(100 * 1000); 322 339 } -
uspace/app/uidemo/uidemo.h
rba09d06 r20d2c6c 49 49 ui_pbutton_t *pb1; 50 50 ui_pbutton_t *pb2; 51 bool quit; 51 52 } ui_demo_t; 52 53 -
uspace/lib/ui/private/wdecor.h
rba09d06 r20d2c6c 56 56 gfx_rect_t rect; 57 57 /** Caption */ 58 c onst char *caption;58 char *caption; 59 59 /** Window is active */ 60 60 bool active; 61 /** Close button */ 62 struct ui_pbutton *btn_close; 61 63 }; 62 64 65 extern void ui_wdecor_close(ui_wdecor_t *); 63 66 extern void ui_wdecor_move(ui_wdecor_t *, gfx_coord2_t *); 64 67 -
uspace/lib/ui/src/wdecor.c
rba09d06 r20d2c6c 43 43 #include <str.h> 44 44 #include <ui/paint.h> 45 #include <ui/pbutton.h> 45 46 #include <ui/wdecor.h> 46 47 #include "../private/resource.h" 47 48 #include "../private/wdecor.h" 49 50 static void ui_wdecor_btn_clicked(ui_pbutton_t *, void *); 51 52 static ui_pbutton_cb_t ui_wdecor_btn_close_cb = { 53 .clicked = ui_wdecor_btn_clicked 54 }; 48 55 49 56 /** Create new window decoration. … … 58 65 { 59 66 ui_wdecor_t *wdecor; 67 errno_t rc; 60 68 61 69 wdecor = calloc(1, sizeof(ui_wdecor_t)); … … 69 77 } 70 78 79 rc = ui_pbutton_create(resource, "X", &wdecor->btn_close); 80 if (rc != EOK) { 81 free(wdecor->caption); 82 free(wdecor); 83 return rc; 84 } 85 86 ui_pbutton_set_cb(wdecor->btn_close, &ui_wdecor_btn_close_cb, 87 (void *)wdecor); 88 71 89 wdecor->res = resource; 72 90 wdecor->active = true; … … 84 102 return; 85 103 104 ui_pbutton_destroy(wdecor->btn_close); 105 free(wdecor->caption); 86 106 free(wdecor); 87 107 } … … 106 126 void ui_wdecor_set_rect(ui_wdecor_t *wdecor, gfx_rect_t *rect) 107 127 { 128 gfx_rect_t crect; 129 108 130 wdecor->rect = *rect; 131 crect.p0.x = rect->p1.x - 5 - 20; 132 crect.p0.y = rect->p0.y + 5; 133 crect.p1.x = rect->p1.x - 5; 134 crect.p1.y = rect->p0.y + 5 + 20; 135 136 ui_pbutton_set_rect(wdecor->btn_close, &crect); 109 137 } 110 138 … … 191 219 return rc; 192 220 221 rc = ui_pbutton_paint(wdecor->btn_close); 222 if (rc != EOK) 223 return rc; 224 193 225 return EOK; 226 } 227 228 /** Send decoration close event. 229 * 230 * @param wdecor Window decoration 231 * @param pos Position where the title bar was pressed 232 */ 233 void ui_wdecor_close(ui_wdecor_t *wdecor) 234 { 235 if (wdecor->cb != NULL && wdecor->cb->close != NULL) 236 wdecor->cb->close(wdecor, wdecor->arg); 194 237 } 195 238 … … 213 256 { 214 257 gfx_rect_t trect; 258 gfx_rect_t cbrect; 215 259 gfx_coord2_t pos; 216 260 … … 220 264 trect.p1.y = trect.p0.y + 22; 221 265 266 cbrect.p0.x = wdecor->rect.p1.x - 5 - 20; 267 cbrect.p0.y = wdecor->rect.p0.y + 5; 268 cbrect.p1.x = wdecor->rect.p1.x - 5; 269 cbrect.p1.y = wdecor->rect.p0.y + 5 + 20; 270 222 271 pos.x = event->hpos; 223 272 pos.y = event->vpos; 224 273 274 if (gfx_pix_inside_rect(&pos, &cbrect)) { 275 ui_pbutton_pos_event(wdecor->btn_close, event); 276 return; 277 } 278 225 279 if (event->type == POS_PRESS && gfx_pix_inside_rect(&pos, &trect)) 226 280 ui_wdecor_move(wdecor, &pos); 227 281 } 228 282 283 /** Window decoration close button was clicked. 284 * 285 * @param pbutton Close button 286 * @param arg Argument (ui_wdecor_t) 287 */ 288 static void ui_wdecor_btn_clicked(ui_pbutton_t *pbutton, void *arg) 289 { 290 ui_wdecor_t *wdecor = (ui_wdecor_t *) arg; 291 292 (void) pbutton; 293 ui_wdecor_close(wdecor); 294 } 295 229 296 /** @} 230 297 */ -
uspace/lib/ui/test/wdecor.c
rba09d06 r20d2c6c 32 32 #include <pcut/pcut.h> 33 33 #include <stdbool.h> 34 #include <ui/pbutton.h> 34 35 #include <ui/resource.h> 35 36 #include <ui/wdecor.h> … … 57 58 }; 58 59 60 static void test_wdecor_close(ui_wdecor_t *, void *); 59 61 static void test_wdecor_move(ui_wdecor_t *, void *, gfx_coord2_t *); 60 62 61 63 static ui_wdecor_cb_t test_wdecor_cb = { 64 .close = test_wdecor_close, 62 65 .move = test_wdecor_move 63 66 }; … … 84 87 85 88 typedef struct { 89 bool close; 86 90 bool move; 87 91 gfx_coord2_t pos; … … 179 183 rc = gfx_context_delete(gc); 180 184 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 185 } 186 187 /** Test ui_wdecor_close() */ 188 PCUT_TEST(close) 189 { 190 errno_t rc; 191 ui_wdecor_t *wdecor; 192 test_cb_resp_t resp; 193 194 rc = ui_wdecor_create(NULL, "Hello", &wdecor); 195 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 196 197 /* Close callback with no callbacks set */ 198 ui_wdecor_close(wdecor); 199 200 /* Close callback with close callback not implemented */ 201 ui_wdecor_set_cb(wdecor, &dummy_wdecor_cb, NULL); 202 ui_wdecor_close(wdecor); 203 204 /* Close callback with real callback set */ 205 resp.close = false; 206 ui_wdecor_set_cb(wdecor, &test_wdecor_cb, &resp); 207 ui_wdecor_close(wdecor); 208 PCUT_ASSERT_TRUE(resp.close); 209 210 ui_wdecor_destroy(wdecor); 181 211 } 182 212 … … 211 241 PCUT_ASSERT_INT_EQUALS(pos.x, resp.pos.x); 212 242 PCUT_ASSERT_INT_EQUALS(pos.y, resp.pos.y); 243 244 ui_wdecor_destroy(wdecor); 245 } 246 247 /** Clicking the close button generates close callback */ 248 PCUT_TEST(close_btn_clicked) 249 { 250 ui_wdecor_t *wdecor; 251 gfx_rect_t rect; 252 test_cb_resp_t resp; 253 errno_t rc; 254 255 rc = ui_wdecor_create(NULL, "Hello", &wdecor); 256 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 257 258 rect.p0.x = 10; 259 rect.p0.y = 20; 260 rect.p1.x = 100; 261 rect.p1.y = 200; 262 263 ui_wdecor_set_rect(wdecor, &rect); 264 265 ui_wdecor_set_cb(wdecor, &test_wdecor_cb, (void *) &resp); 266 267 resp.close = false; 268 269 ui_pbutton_clicked(wdecor->btn_close); 270 PCUT_ASSERT_TRUE(resp.close); 213 271 214 272 ui_wdecor_destroy(wdecor); … … 328 386 } 329 387 388 static void test_wdecor_close(ui_wdecor_t *wdecor, void *arg) 389 { 390 test_cb_resp_t *resp = (test_cb_resp_t *) arg; 391 392 resp->close = true; 393 } 394 330 395 static void test_wdecor_move(ui_wdecor_t *wdecor, void *arg, gfx_coord2_t *pos) 331 396 {
Note:
See TracChangeset
for help on using the changeset viewer.