Changeset 68d68e9 in mainline for uspace/app/taskbar/wndlist.c


Ignore:
Timestamp:
2022-11-23T12:50:27Z (2 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
master, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
c4a53280
Parents:
6e91475
Message:

Vary window button size to fit

If they get too narrow, we stop adding more buttons.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/app/taskbar/wndlist.c

    r6e91475 r68d68e9  
    3535#include <gfx/coord.h>
    3636#include <stdbool.h>
     37#include <stddef.h>
    3738#include <stdio.h>
    3839#include <stdlib.h>
     
    6566
    6667enum {
    67         /** X distance between left edges of two consecutive buttons */
    68         wndlist_button_pitch = 145,
    69         /** X distance between left edges of two consecutive buttons (text) */
    70         wndlist_button_pitch_text = 17,
     68        /** Min. X distance between left edges of two consecutive buttons */
     69        wndlist_button_pitch_min = 85,
     70        /** Max. X distance between left edges of two consecutive buttons (text) */
     71        wndlist_button_pitch_min_text = 10,
     72        /** Min. X distance between left edges of two consecutive buttons */
     73        wndlist_button_pitch_max = 165,
     74        /** Max. X distance between left edges of two consecutive buttons (text) */
     75        wndlist_button_pitch_max_text = 17,
    7176        /** Padding between buttons */
    7277        wndlist_button_pad = 5,
     
    197202        wndlist_entry_t *entry = NULL;
    198203        ui_resource_t *res;
     204        wndlist_entry_t *e;
    199205        errno_t rc;
    200206
     
    217223        entry->visible = false;
    218224
    219         /* Set the button rectangle and add it to layout, if applicable */
    220         wndlist_set_entry_rect(wndlist, entry);
     225        /*
     226         * Update rectangles for all entries, including @a entry, adding
     227         * it to the layout, if applicable.
     228         */
     229        e = wndlist_first(wndlist);
     230        while (e != NULL) {
     231                wndlist_set_entry_rect(wndlist, e);
     232                e = wndlist_next(e);
     233        }
    221234
    222235        /* Set button callbacks */
    223236        ui_pbutton_set_cb(entry->button, &wndlist_button_cb, (void *)entry);
    224237
    225         if (paint && entry->visible) {
    226                 rc = ui_pbutton_paint(entry->button);
    227                 if (rc != EOK)
    228                         goto error;
    229         }
     238        if (paint)
     239                return wndlist_repaint(wndlist);
    230240
    231241        return EOK;
     
    249259    bool paint)
    250260{
    251         wndlist_entry_t *next;
     261        wndlist_entry_t *e;
    252262        assert(entry->wndlist == wndlist);
    253263
    254         next = wndlist_next(entry);
    255 
    256         ui_fixed_remove(wndlist->fixed, ui_pbutton_ctl(entry->button));
     264        if (entry->visible)
     265                ui_fixed_remove(wndlist->fixed, ui_pbutton_ctl(entry->button));
    257266        ui_pbutton_destroy(entry->button);
    258267        list_remove(&entry->lentries);
    259268        free(entry);
    260269
    261         /* Update positions of the remaining entries */
    262         while (next != NULL) {
    263                 wndlist_set_entry_rect(wndlist, next);
    264                 next = wndlist_next(next);
     270        /* Update positions of the all entries */
     271        e = wndlist_first(wndlist);
     272        while (e != NULL) {
     273                wndlist_set_entry_rect(wndlist, e);
     274                e = wndlist_next(e);
    265275        }
    266276
     
    307317        ui_resource_t *res;
    308318        gfx_coord_t pitch;
     319        gfx_coord_t pitch_max;
     320        gfx_coord_t pitch_min;
    309321        gfx_coord_t pad;
    310322        size_t idx;
     323        size_t nbuttons;
    311324
    312325        /* Determine entry index */
     
    322335
    323336        if (ui_resource_is_textmode(res)) {
    324                 pitch = wndlist_button_pitch_text;
     337                pitch_max = wndlist_button_pitch_max_text;
     338                pitch_min = wndlist_button_pitch_min_text;
    325339                pad = wndlist_button_pad_text;
    326340        } else {
    327                 pitch = wndlist_button_pitch;
     341                pitch_max = wndlist_button_pitch_max;
     342                pitch_min = wndlist_button_pitch_min;
    328343                pad = wndlist_button_pad;
    329344        }
     345
     346        /* Compute pitch that fits all buttons perfectly */
     347        nbuttons = wndlist_count(wndlist);
     348        pitch = (wndlist->rect.p1.x - wndlist->rect.p0.x + pad) / nbuttons;
     349        if (pitch < pitch_min)
     350                pitch = pitch_min;
     351        if (pitch > pitch_max)
     352                pitch = pitch_max;
    330353
    331354        rect.p0.x = wndlist->rect.p0.x + pitch * idx;
     
    478501}
    479502
     503/** Get number of window list entries.
     504 *
     505 * @param wndlist Window list
     506 * @return Number of entries
     507 */
     508size_t wndlist_count(wndlist_t *wndlist)
     509{
     510        return list_count(&wndlist->entries);
     511}
     512
    480513/** Repaint window list.
    481514 *
Note: See TracChangeset for help on using the changeset viewer.