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

Changeset 68d68e9 in mainline


Ignore:
Timestamp:
2022-11-23T12:50:27Z (2 months ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
master
Children:
c4a53280
Parents:
6e91475
Message:

Vary window button size to fit

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

Location:
uspace
Files:
4 edited

Legend:

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

    r6e91475 r68d68e9  
    407407}
    408408
     409/** Test wndlist_count() */
     410PCUT_TEST(count)
     411{
     412        errno_t rc;
     413        ui_t *ui = NULL;
     414        ui_wnd_params_t params;
     415        ui_window_t *window = NULL;
     416        ui_fixed_t *fixed = NULL;
     417        wndlist_t *wndlist;
     418        size_t count;
     419
     420        rc = ui_create_disp(NULL, &ui);
     421        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     422
     423        ui_wnd_params_init(&params);
     424        params.caption = "Hello";
     425
     426        rc = ui_window_create(ui, &params, &window);
     427        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     428        PCUT_ASSERT_NOT_NULL(window);
     429
     430        rc = ui_fixed_create(&fixed);
     431        ui_window_add(window, ui_fixed_ctl(fixed));
     432
     433        rc = wndlist_create(window, fixed, &wndlist);
     434        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     435
     436        count = wndlist_count(wndlist);
     437        PCUT_ASSERT_INT_EQUALS(0, count);
     438
     439        rc = wndlist_append(wndlist, 1, "Foo", true);
     440        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     441
     442        count = wndlist_count(wndlist);
     443        PCUT_ASSERT_INT_EQUALS(1, count);
     444
     445        rc = wndlist_append(wndlist, 2, "Bar", true);
     446        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     447
     448        count = wndlist_count(wndlist);
     449        PCUT_ASSERT_INT_EQUALS(2, count);
     450
     451        wndlist_destroy(wndlist);
     452
     453        ui_window_destroy(window);
     454        ui_destroy(ui);
     455}
     456
    409457/** Test repainting window list */
    410458PCUT_TEST(repaint)
  • 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 *
  • uspace/app/taskbar/wndlist.h

    r6e91475 r68d68e9  
    4040#include <gfx/coord.h>
    4141#include <stdbool.h>
     42#include <stddef.h>
    4243#include <ui/fixed.h>
    4344#include <ui/window.h>
     
    5657extern wndlist_entry_t *wndlist_first(wndlist_t *);
    5758extern wndlist_entry_t *wndlist_next(wndlist_entry_t *);
     59extern size_t wndlist_count(wndlist_t *);
    5860extern errno_t wndlist_repaint(wndlist_t *);
    5961
  • uspace/lib/ui/src/pbutton.c

    r6e91475 r68d68e9  
    5454enum {
    5555        ui_pb_press_dx = 1,
    56         ui_pb_press_dy = 1
     56        ui_pb_press_dy = 1,
     57        ui_pb_pad_x = 2,
     58        ui_pb_pad_x_text = 1
    5759};
    5860
     
    323325        gfx_text_fmt_t fmt;
    324326        gfx_rect_t rect;
     327        gfx_rect_t irect;
    325328        gfx_coord_t thickness;
    326329        bool depressed;
     
    360363        } else {
    361364                /* Text decoration */
     365                ui_paint_get_inset_frame_inside(pbutton->res, &rect, &irect);
    362366                gfx_text_fmt_init(&fmt);
    363367                fmt.font = pbutton->res->font;
     
    365369                fmt.halign = gfx_halign_center;
    366370                fmt.valign = gfx_valign_center;
     371                fmt.abbreviate = true;
     372                fmt.width = irect.p1.x - irect.p0.x - 2 * ui_pb_pad_x;
    367373
    368374                rc = gfx_puttext(&pos, &fmt, pbutton->caption);
     
    442448        fmt.halign = gfx_halign_center;
    443449        fmt.valign = gfx_valign_center;
     450        fmt.abbreviate = true;
     451        fmt.width = rect.p1.x - rect.p0.x - 2 * ui_pb_pad_x_text;
    444452
    445453        rc = gfx_puttext(&pos, &fmt, pbutton->caption);
Note: See TracChangeset for help on using the changeset viewer.