Fork us on GitHub Follow us on Facebook Follow us on Twitter

Changeset e0377075 in mainline for uspace/app/nav/panel.c


Ignore:
Timestamp:
2021-10-25T00:32:45Z (15 months ago)
Author:
jxsvoboda <5887334+jxsvoboda@…>
Branches:
master, serial
Children:
9ee55cd
Parents:
39ab17c
git-author:
Jiri Svoboda <jiri@…> (2021-10-22 18:25:44)
git-committer:
jxsvoboda <5887334+jxsvoboda@…> (2021-10-25 00:32:45)
Message:

Select entry using the mouse

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/app/nav/panel.c

    r39ab17c re0377075  
    324324{
    325325        gfx_coord2_t pos;
     326        gfx_rect_t irect;
     327        panel_entry_t *entry;
     328        size_t entry_idx;
     329        int n;
    326330
    327331        pos.x = event->hpos;
     
    330334                return ui_unclaimed;
    331335
    332         if (!panel->active) {
     336        if (!panel->active && event->type == POS_PRESS)
    333337                panel_activate_req(panel);
     338
     339        if (event->type == POS_PRESS) {
     340                irect.p0.x = panel->rect.p0.x + 1;
     341                irect.p0.y = panel->rect.p0.y + 1;
     342                irect.p1.x = panel->rect.p1.x - 1;
     343                irect.p1.y = panel->rect.p1.y - 1;
     344
     345                /* Did we click on one of the entries? */
     346                if (gfx_pix_inside_rect(&pos, &irect)) {
     347                        /* Index within page */
     348                        n = pos.y - irect.p0.y;
     349
     350                        /* Entry and its index within entire listing */
     351                        entry = panel_page_nth_entry(panel, n, &entry_idx);
     352
     353                        /* Move to the entry found */
     354                        panel_cursor_move(panel, entry, entry_idx);
     355                }
    334356        }
    335357
     
    800822}
    801823
     824/** Find the n-th entry of the current panel page.
     825 *
     826 * If the page is short and has less than n+1 entries, return the last entry.
     827 *
     828 * @param panel Panel
     829 * @param n Which entry to get (starting from 0)
     830 * @param ridx Place to store index (within listing) of the entry
     831 * @return n-th entry of the page
     832 */
     833panel_entry_t *panel_page_nth_entry(panel_t *panel, size_t n, size_t *ridx)
     834{
     835        panel_entry_t *entry;
     836        panel_entry_t *next;
     837        size_t i;
     838        size_t idx;
     839
     840        assert(n < panel_page_size(panel));
     841
     842        entry = panel->page;
     843        idx = panel->page_idx;
     844        for (i = 0; i < n; i++) {
     845                next = panel_next(entry);
     846                if (next == NULL)
     847                        break;
     848
     849                entry = next;
     850                ++idx;
     851        }
     852
     853        *ridx = idx;
     854        return entry;
     855}
     856
    802857/** Move cursor to a new position, possibly scrolling.
    803858 *
Note: See TracChangeset for help on using the changeset viewer.