Changeset a130983 in mainline for uspace/lib/ui/src/wdecor.c


Ignore:
Timestamp:
2022-11-17T19:56:07Z (16 months ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
master, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
901b302
Parents:
5d62130
Message:

Implement text abbreviation

When rendering text, gfx_puttext can now abbreviate it with …
to fit within the specified width. Use on window captions.
Now Barber Pole can have a proper caption.

Note that now the caption is centered on the space between the left
edge and the buttons, instead on the entire title bar, so it
may look a little lopsided. It will look better once we put
something to the left side of the title bar.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/ui/src/wdecor.c

    r5d62130 ra130983  
    8888        /** Window frame width in text mode */
    8989        wdecor_frame_w_text = 1,
     90        /** Window caption horizontal margin */
     91        wdecor_cap_hmargin = 4,
     92        /** Window caption horizontal margin in text mode */
     93        wdecor_cap_hmargin_text = 1,
    9094        /** Close button cross leg length */
    9195        wdecor_close_cross_n = 5,
     
    326330                fmt.halign = gfx_halign_center;
    327331                fmt.valign = gfx_valign_center;
    328 
    329                 pos.x = (trect.p0.x + trect.p1.x) / 2;
    330                 pos.y = (trect.p0.y + trect.p1.y) / 2;
     332                fmt.abbreviate = true;
     333                fmt.width = geom.caption_rect.p1.x -
     334                    geom.caption_rect.p0.x;
     335
     336                pos.x = (geom.caption_rect.p0.x + geom.caption_rect.p1.x) / 2;
     337                pos.y = (geom.caption_rect.p0.y + geom.caption_rect.p1.y) / 2;
    331338
    332339                if (wdecor->res->textmode) {
     
    450457        gfx_coord_t btn_x;
    451458        gfx_coord_t btn_y;
     459        gfx_coord_t cap_hmargin;
    452460
    453461        /* Does window have a frame? */
     
    529537                        geom->btn_max_rect.p1.x = btn_x;
    530538                        geom->btn_max_rect.p1.y = btn_y + 20;
     539
     540                        btn_x -= 20;
    531541                } else {
    532542                        geom->btn_max_rect.p0.x = btn_x - 3;
     
    534544                        geom->btn_max_rect.p1.x = btn_x;
    535545                        geom->btn_max_rect.p1.y = btn_y + 1;
     546
     547                        btn_x -= 3;
    536548                }
    537549        } else {
     
    541553                geom->btn_max_rect.p1.y = 0;
    542554        }
     555
     556        if (wdecor->res->textmode == false)
     557                cap_hmargin = wdecor_cap_hmargin;
     558        else
     559                cap_hmargin = wdecor_cap_hmargin_text;
     560
     561        geom->caption_rect.p0.x = geom->title_bar_rect.p0.x +
     562            cap_hmargin;
     563        geom->caption_rect.p0.y = geom->title_bar_rect.p0.y;
     564        geom->caption_rect.p1.x = btn_x - cap_hmargin;
     565        geom->caption_rect.p1.y = geom->title_bar_rect.p1.y;
    543566}
    544567
Note: See TracChangeset for help on using the changeset viewer.