Changeset 0262f16c in mainline
- Timestamp:
- 2021-04-09T22:41:22Z (4 years ago)
- Branches:
- master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 62223ec
- Parents:
- 214aefb
- git-author:
- Jiri Svoboda <jiri@…> (2021-04-01 16:23:35)
- git-committer:
- jxsvoboda <5887334+jxsvoboda@…> (2021-04-09 22:41:22)
- Location:
- uspace/lib/ui
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/ui/include/ui/menu.h
r214aefb r0262f16c 52 52 extern errno_t ui_menu_paint(ui_menu_t *, gfx_coord2_t *); 53 53 extern errno_t ui_menu_unpaint(ui_menu_t *); 54 extern void ui_menu_press(ui_menu_t *, gfx_coord2_t *, gfx_coord2_t *); 54 extern ui_evclaim_t ui_menu_pos_event(ui_menu_t *, gfx_coord2_t *, 55 pos_event_t *); 55 56 56 57 #endif -
uspace/lib/ui/include/ui/menuentry.h
r214aefb r0262f16c 53 53 extern gfx_coord_t ui_menu_entry_height(ui_menu_entry_t *); 54 54 extern errno_t ui_menu_entry_paint(ui_menu_entry_t *, gfx_coord2_t *); 55 extern void ui_menu_entry_press(ui_menu_entry_t *, gfx_coord2_t *, 56 gfx_coord2_t *); 55 extern void ui_menu_entry_press(ui_menu_entry_t *, gfx_coord2_t *); 56 extern void ui_menu_entry_release(ui_menu_entry_t *); 57 extern void ui_menu_entry_enter(ui_menu_entry_t *, gfx_coord2_t *); 58 extern void ui_menu_entry_leave(ui_menu_entry_t *, gfx_coord2_t *); 59 extern ui_evclaim_t ui_menu_entry_pos_event(ui_menu_entry_t *, gfx_coord2_t *, 60 pos_event_t *); 57 61 58 62 #endif -
uspace/lib/ui/private/menuentry.h
r214aefb r0262f16c 53 53 /** Callbacks */ 54 54 ui_menu_entry_cb_t cb; 55 /** Menu entry is currently held down */ 56 bool held; 57 /** Pointer is currently inside */ 58 bool inside; 55 59 /** Callback argument */ 56 60 void *arg; -
uspace/lib/ui/src/menu.c
r214aefb r0262f16c 292 292 * @param menu Menu 293 293 * @param spos Starting position (top-left corner) 294 * @param ppos Press position 295 */ 296 void ui_menu_press(ui_menu_t *menu, gfx_coord2_t *spos, gfx_coord2_t *ppos) 294 * @param event Position event 295 * @return ui_claimed iff the event was claimed 296 */ 297 ui_evclaim_t ui_menu_pos_event(ui_menu_t *menu, gfx_coord2_t *spos, 298 pos_event_t *event) 297 299 { 298 300 ui_menu_geom_t geom; 299 301 ui_menu_entry_t *mentry; 300 302 gfx_coord2_t pos; 303 gfx_coord2_t epos; 304 ui_evclaim_t claimed; 301 305 302 306 ui_menu_get_geom(menu, spos, &geom); 307 epos.x = event->hpos; 308 epos.y = event->vpos; 303 309 304 310 pos = geom.entries_rect.p0; … … 306 312 mentry = ui_menu_entry_first(menu); 307 313 while (mentry != NULL) { 308 ui_menu_entry_press(mentry, &pos, ppos); 314 claimed = ui_menu_entry_pos_event(mentry, &pos, event); 315 if (claimed == ui_claimed) 316 return ui_claimed; 309 317 310 318 pos.y += ui_menu_entry_height(mentry); 311 319 mentry = ui_menu_entry_next(mentry); 312 320 } 321 322 if (gfx_pix_inside_rect(&epos, &geom.outer_rect)) 323 return ui_claimed; 324 325 return ui_unclaimed; 313 326 } 314 327 -
uspace/lib/ui/src/menubar.c
r214aefb r0262f16c 267 267 * 268 268 * @param mbar Menu bar 269 * @param p pos Press position269 * @param pos_event Position event 270 270 * @return @c ui_claimed iff the event is claimed 271 271 */ 272 static ui_evclaim_t ui_menu_bar_press(ui_menu_bar_t *mbar, gfx_coord2_t *ppos)272 ui_evclaim_t ui_menu_bar_pos_event(ui_menu_bar_t *mbar, pos_event_t *event) 273 273 { 274 274 gfx_coord2_t pos; … … 279 279 gfx_coord_t width; 280 280 gfx_coord_t hpad; 281 gfx_coord2_t ppos; 282 ui_evclaim_t claimed; 283 284 ppos.x = event->hpos; 285 ppos.y = event->vpos; 281 286 282 287 if (mbar->res->textmode) { … … 298 303 299 304 /* Check if press is inside menu bar entry */ 300 if (gfx_pix_inside_rect(ppos, &rect)) { 305 if (event->type == POS_PRESS && 306 gfx_pix_inside_rect(&ppos, &rect)) { 301 307 ui_menu_bar_select(mbar, &pos, menu); 302 308 return ui_claimed; … … 310 316 ui_menu_get_rect(menu, &spos, &rect); 311 317 312 /* Check if press is inside open menu */ 313 if (gfx_pix_inside_rect(ppos, &rect)) { 314 ui_menu_press(menu, &spos, ppos); 318 claimed = ui_menu_pos_event(menu, &spos, event); 319 if (claimed == ui_claimed) 315 320 return ui_claimed; 316 }317 321 } 318 322 319 323 pos.x += width; 320 324 menu = ui_menu_next(menu); 321 }322 323 return ui_unclaimed;324 }325 326 /** Handle menu bar position event.327 *328 * @param mbar Menu bar329 * @param pos_event Position event330 * @return @c ui_claimed iff the event is claimed331 */332 ui_evclaim_t ui_menu_bar_pos_event(ui_menu_bar_t *mbar, pos_event_t *event)333 {334 gfx_coord2_t pos;335 336 pos.x = event->hpos;337 pos.y = event->vpos;338 339 switch (event->type) {340 case POS_PRESS:341 return ui_menu_bar_press(mbar, &pos);342 default:343 break;344 325 } 345 326 -
uspace/lib/ui/src/menuentry.c
r214aefb r0262f16c 217 217 caption = mentry->caption; 218 218 219 if (mentry == mentry->menu->selected) { 219 if ((mentry->held && mentry->inside) || 220 mentry == mentry->menu->selected) { 220 221 fmt.color = res->wnd_sel_text_color; 221 222 bg_color = res->wnd_sel_text_bg_color; … … 249 250 * 250 251 * @param mentry Menu entry 251 * @param pos Position (top-left corner) 252 * @param ppos Press position 253 */ 254 void ui_menu_entry_press(ui_menu_entry_t *mentry, gfx_coord2_t *pos, 255 gfx_coord2_t *ppos) 256 { 257 ui_menu_entry_geom_t geom; 258 259 ui_menu_entry_get_geom(mentry, pos, &geom); 260 261 if (gfx_pix_inside_rect(ppos, &geom.outer_rect)) { 262 /* Press inside menu entry */ 263 252 * @param pos Menu entry position 253 */ 254 void ui_menu_entry_press(ui_menu_entry_t *mentry, gfx_coord2_t *pos) 255 { 256 if (mentry->held) 257 return; 258 259 mentry->inside = true; 260 mentry->held = true; 261 ui_menu_entry_paint(mentry, pos); 262 } 263 264 /** Handle button release in menu entry. 265 * 266 * @param mentry Menu entry 267 */ 268 void ui_menu_entry_release(ui_menu_entry_t *mentry) 269 { 270 if (!mentry->held) 271 return; 272 273 mentry->held = false; 274 275 if (mentry->inside) { 264 276 /* Close menu */ 265 277 ui_menu_bar_select(mentry->menu->mbar, … … 270 282 mentry->cb(mentry, mentry->arg); 271 283 } 284 } 285 286 /** Pointer entered menu entry. 287 * 288 * @param mentry Menu entry 289 * @param pos Menu entry position 290 */ 291 void ui_menu_entry_enter(ui_menu_entry_t *mentry, gfx_coord2_t *pos) 292 { 293 if (mentry->inside) 294 return; 295 296 mentry->inside = true; 297 if (mentry->held) 298 (void) ui_menu_entry_paint(mentry, pos); 299 } 300 301 /** Pointer left menu entry. 302 * 303 * @param mentry Menu entry 304 * @param pos Menu entry position 305 */ 306 void ui_menu_entry_leave(ui_menu_entry_t *mentry, gfx_coord2_t *pos) 307 { 308 if (!mentry->inside) 309 return; 310 311 mentry->inside = false; 312 if (mentry->held) 313 (void) ui_menu_entry_paint(mentry, pos); 314 } 315 316 /** Handle menu entry position event. 317 * 318 * @param mentry Menu entry 319 * @param pos Menu entry position (top-left corner) 320 * @param pos_event Position event 321 * @return @c ui_claimed iff the event is claimed 322 */ 323 ui_evclaim_t ui_menu_entry_pos_event(ui_menu_entry_t *mentry, 324 gfx_coord2_t *pos, pos_event_t *event) 325 { 326 ui_menu_entry_geom_t geom; 327 gfx_coord2_t ppos; 328 bool inside; 329 330 ppos.x = event->hpos; 331 ppos.y = event->vpos; 332 333 ui_menu_entry_get_geom(mentry, pos, &geom); 334 inside = gfx_pix_inside_rect(&ppos, &geom.outer_rect); 335 336 switch (event->type) { 337 case POS_PRESS: 338 if (inside) { 339 ui_menu_entry_press(mentry, pos); 340 return ui_claimed; 341 } 342 break; 343 case POS_RELEASE: 344 if (mentry->held) { 345 ui_menu_entry_release(mentry); 346 return ui_claimed; 347 } 348 break; 349 case POS_UPDATE: 350 if (inside && !mentry->inside) { 351 ui_menu_entry_enter(mentry, pos); 352 return ui_claimed; 353 } else if (!inside && mentry->inside) { 354 ui_menu_entry_leave(mentry, pos); 355 } 356 break; 357 } 358 359 return ui_unclaimed; 272 360 } 273 361
Note:
See TracChangeset
for help on using the changeset viewer.