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


Ignore:
Timestamp:
2021-09-01T09:45:37Z (3 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
1ebcb791
Parents:
b79c91cc
git-author:
Jiri Svoboda <jiri@…> (2021-08-31 19:44:34)
git-committer:
Jiri Svoboda <jiri@…> (2021-09-01 09:45:37)
Message:

Text-style window title bar

File:
1 edited

Legend:

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

    rb79c91cc r45004f3  
    6161        wdecor_edge_h = 4,
    6262        wdecor_tbar_h = 22,
    63         wdecor_tbar_h_text = 1,
    6463        wdecor_frame_w = 4,
    6564        wdecor_frame_w_text = 1
     
    170169        gfx_rect_t rect;
    171170        gfx_rect_t trect;
     171        gfx_rect_t text_rect;
    172172        gfx_text_fmt_t fmt;
    173173        gfx_coord2_t pos;
     
    207207                        if (rc != EOK)
    208208                                return rc;
     209
     210                        rc = gfx_set_color(wdecor->res->gc, wdecor->active ?
     211                            wdecor->res->tbar_act_bg_color :
     212                            wdecor->res->tbar_inact_bg_color);
     213                        if (rc != EOK)
     214                                return rc;
     215
     216                        rc = gfx_fill_rect(wdecor->res->gc, &trect);
     217                        if (rc != EOK)
     218                                return rc;
    209219                }
    210 
    211                 rc = gfx_set_color(wdecor->res->gc, wdecor->active ?
    212                     wdecor->res->tbar_act_bg_color :
    213                     wdecor->res->tbar_inact_bg_color);
    214                 if (rc != EOK)
    215                         return rc;
    216 
    217                 rc = gfx_fill_rect(wdecor->res->gc, &trect);
    218                 if (rc != EOK)
    219                         return rc;
    220220
    221221                gfx_text_fmt_init(&fmt);
     
    229229                pos.y = (trect.p0.y + trect.p1.y) / 2;
    230230
     231                if (wdecor->res->textmode) {
     232                        /* Make space around caption text */
     233                        gfx_text_rect(wdecor->res->font, &pos, &fmt,
     234                            wdecor->caption, &text_rect);
     235
     236                        /* Only make space if caption is non-empty */
     237                        if (text_rect.p0.x < text_rect.p1.x) {
     238                                text_rect.p0.x -= 1;
     239                                text_rect.p1.x += 1;
     240                        }
     241
     242                        rc = gfx_set_color(wdecor->res->gc, wdecor->active ?
     243                            wdecor->res->tbar_act_bg_color :
     244                            wdecor->res->tbar_inact_bg_color);
     245                        if (rc != EOK)
     246                                return rc;
     247
     248                        rc = gfx_fill_rect(wdecor->res->gc, &text_rect);
     249                        if (rc != EOK)
     250                                return rc;
     251                }
     252
    231253                rc = gfx_puttext(wdecor->res->font, &pos, &fmt, wdecor->caption);
    232254                if (rc != EOK)
     
    300322{
    301323        gfx_coord_t frame_w;
    302         gfx_coord_t tbar_h;
    303324
    304325        /* Does window have a frame? */
     
    317338        /* Does window have a title bar? */
    318339        if ((wdecor->style & ui_wds_titlebar) != 0) {
    319                 tbar_h = wdecor->res->textmode ?
    320                     wdecor_tbar_h_text : wdecor_tbar_h;
    321 
    322                 geom->title_bar_rect.p0 = geom->interior_rect.p0;
    323                 geom->title_bar_rect.p1.x = geom->interior_rect.p1.x;
    324                 geom->title_bar_rect.p1.y = geom->interior_rect.p0.y + tbar_h;
     340                if (wdecor->res->textmode) {
     341                        geom->title_bar_rect.p0 = wdecor->rect.p0;
     342                        geom->title_bar_rect.p1.x = wdecor->rect.p1.x;
     343                        geom->title_bar_rect.p1.y = wdecor->rect.p0.y + 1;
     344                } else {
     345                        geom->title_bar_rect.p0 = geom->interior_rect.p0;
     346                        geom->title_bar_rect.p1.x = geom->interior_rect.p1.x;
     347                        geom->title_bar_rect.p1.y = geom->interior_rect.p0.y
     348                            + wdecor_tbar_h;
     349                }
    325350
    326351                geom->app_area_rect.p0.x = geom->interior_rect.p0.x;
Note: See TracChangeset for help on using the changeset viewer.