Changeset a35b458 in mainline for uspace/lib/gui/grid.c


Ignore:
Timestamp:
2018-03-02T20:10:49Z (7 years ago)
Author:
Jiří Zárevúcky <zarevucky.jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
f1380b7
Parents:
3061bc1
git-author:
Jiří Zárevúcky <zarevucky.jiri@…> (2018-02-28 17:38:31)
git-committer:
Jiří Zárevúcky <zarevucky.jiri@…> (2018-03-02 20:10:49)
Message:

style: Remove trailing whitespace on _all_ lines, including empty ones, for particular file types.

Command used: tools/srepl '\s\+$' '' -- *.c *.h *.py *.sh *.s *.S *.ag

Currently, whitespace on empty lines is very inconsistent.
There are two basic choices: Either remove the whitespace, or keep empty lines
indented to the level of surrounding code. The former is AFAICT more common,
and also much easier to do automatically.

Alternatively, we could write script for automatic indentation, and use that
instead. However, if such a script exists, it's possible to use the indented
style locally, by having the editor apply relevant conversions on load/save,
without affecting remote repository. IMO, it makes more sense to adopt
the simpler rule.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/gui/grid.c

    r3061bc1 ra35b458  
    5151{
    5252        grid_t *grid = (grid_t *) widget;
    53        
     53
    5454        surface_t *surface = window_claim(grid->widget.window);
    5555        if (!surface) {
     
    5757                return;
    5858        }
    59        
     59
    6060        // FIXME: Replace with (accelerated) rectangle fill
    6161        for (sysarg_t y = widget->vpos; y < widget->vpos + widget->height; y++) {
     
    6363                        surface_put_pixel(surface, x, y, grid->background);
    6464        }
    65        
     65
    6666        window_yield(grid->widget.window);
    6767}
     
    7171        if ((col < grid->cols) && (row < grid->rows))
    7272                return grid->layout + (row * grid->cols + col);
    73        
     73
    7474        return NULL;
    7575}
     
    8282                        if (cell) {
    8383                                widget_t *widget = cell->widget;
    84                                
     84
    8585                                if ((widget) && (hpos >= widget->hpos) &&
    8686                                    (vpos >= widget->vpos) &&
     
    9191                }
    9292        }
    93        
     93
    9494        return NULL;
    9595}
     
    104104{
    105105        grid_t *grid = (grid_t *) widget;
    106        
     106
    107107        deinit_grid(grid);
    108108        free(grid);
     
    118118{
    119119        assert(run > 0);
    120        
     120
    121121        sysarg_t dim_min_part = dim_min / run;
    122122        sysarg_t dim_min_rem = dim_min % run;
    123        
     123
    124124        sysarg_t dim_max_part = dim_max / run;
    125125        sysarg_t dim_max_rem = dim_max % run;
    126        
     126
    127127        for (size_t i = 0; i < run; i++) {
    128128                sysarg_t dim_min_cur = dim_min_part;
    129129                sysarg_t dim_max_cur = dim_max_part;
    130                
     130
    131131                if (i == run - 1) {
    132132                        dim_min_cur += dim_min_rem;
    133133                        dim_max_cur += dim_max_rem;
    134134                }
    135                
     135
    136136                /*
    137137                 * We want the strongest constraint
     
    140140                if (cons[i].min < dim_min_cur)
    141141                        cons[i].min = dim_min_cur;
    142                
     142
    143143                /*
    144144                 * The comparison is correct, we want
     
    155155        /* Initial solution */
    156156        sysarg_t cur_sum = 0;
    157        
     157
    158158        for (size_t i = 0; i < run; i++) {
    159159                cons[i].val = cons[i].min;
    160160                cur_sum += cons[i].val;
    161161        }
    162        
     162
    163163        /* Iterative improvement */
    164164        while (cur_sum < sum) {
     
    166166                if (delta == 0)
    167167                        break;
    168                
     168
    169169                cur_sum = 0;
    170                
     170
    171171                for (size_t i = 0; i < run; i++) {
    172172                        if (cons[i].val + delta < cons[i].max)
    173173                                cons[i].val += delta;
    174                        
     174
    175175                        cur_sum += cons[i].val;
    176176                }
     
    182182{
    183183        grid_t *grid = (grid_t *) widget;
    184        
     184
    185185        widget_modify(widget, hpos, vpos, width, height);
    186186        paint_internal(widget);
    187        
     187
    188188        /* Compute column widths */
    189189        constraints_t *widths =
     
    193193                for (size_t c = 0; c < grid->cols; c++) {
    194194                        widths[c].min = 0;
    195                        
     195
    196196                        for (size_t r = 0; r < grid->rows; r++) {
    197197                                grid_cell_t *cell = grid_cell_at(grid, c, r);
    198198                                if (!cell)
    199199                                        continue;
    200                                
     200
    201201                                widget_t *widget = cell->widget;
    202202                                if (widget)
     
    205205                        }
    206206                }
    207                
     207
    208208                solve_constraints(widths, grid->cols, width);
    209209        }
    210        
     210
    211211        /* Compute row heights */
    212212        constraints_t *heights =
     
    216216                for (size_t r = 0; r < grid->rows; r++) {
    217217                        heights[r].min = 0;
    218                        
     218
    219219                        for (size_t c = 0; c < grid->cols; c++) {
    220220                                grid_cell_t *cell = grid_cell_at(grid, c, r);
    221221                                if (!cell)
    222222                                        continue;
    223                                
     223
    224224                                widget_t *widget = cell->widget;
    225225                                if (widget) {
     
    229229                        }
    230230                }
    231                
     231
    232232                solve_constraints(heights, grid->rows, height);
    233233        }
    234        
     234
    235235        /* Rearrange widgets */
    236236        if ((widths) && (heights)) {
    237237                sysarg_t cur_vpos = vpos;
    238                
     238
    239239                for (size_t r = 0; r < grid->rows; r++) {
    240240                        sysarg_t cur_hpos = hpos;
    241                        
     241
    242242                        for (size_t c = 0; c < grid->cols; c++) {
    243243                                grid_cell_t *cell = grid_cell_at(grid, c, r);
    244244                                if (!cell)
    245245                                        continue;
    246                                
     246
    247247                                widget_t *widget = cell->widget;
    248248                                if (widget) {
    249249                                        sysarg_t cur_width = 0;
    250250                                        sysarg_t cur_height = 0;
    251                                        
     251
    252252                                        for (size_t cd = 0; cd < cell->cols; cd++)
    253253                                                cur_width += widths[c + cd].val;
    254                                        
     254
    255255                                        for (size_t rd = 0; rd < cell->rows; rd++)
    256256                                                cur_height += heights[r + rd].val;
    257                                        
     257
    258258                                        if ((cur_width > 0) && (cur_height > 0)) {
    259259                                                sysarg_t wwidth = cur_width;
    260260                                                sysarg_t wheight = cur_height;
    261                                                
     261
    262262                                                /*
    263263                                                 * Make sure the widget is respects its
    264264                                                 * maximal constrains.
    265265                                                 */
    266                                                
     266
    267267                                                if ((widget->width_max > 0) &&
    268268                                                    (wwidth > widget->width_max))
    269269                                                        wwidth = widget->width_max;
    270                                                
     270
    271271                                                if ((widget->height_max > 0) &&
    272272                                                    (wheight > widget->height_max))
    273273                                                        wheight = widget->height_max;
    274                                                
     274
    275275                                                widget->rearrange(widget, cur_hpos, cur_vpos,
    276276                                                    wwidth, wheight);
    277277                                        }
    278                                        
    279                                        
     278
     279
    280280                                }
    281                                
     281
    282282                                cur_hpos += widths[c].val;
    283283                        }
    284                        
     284
    285285                        cur_vpos += heights[r].val;
    286286                }
    287287        }
    288        
     288
    289289        if (widths)
    290290                free(widths);
    291        
     291
    292292        if (heights)
    293293                free(heights);
     
    297297{
    298298        paint_internal(widget);
    299        
     299
    300300        list_foreach(widget->children, link, widget_t, child) {
    301301                child->repaint(child);
    302302        }
    303        
     303
    304304        window_damage(widget->window);
    305305}
     
    313313{
    314314        grid_t *grid = (grid_t *) widget;
    315        
     315
    316316        grid_cell_t *cell = grid_coords_at(grid, event.hpos, event.vpos);
    317317        if ((cell) && (cell->widget))
     
    325325            (row + rows > grid->rows))
    326326                return false;
    327        
     327
    328328        grid_cell_t *cell = grid_cell_at(grid, col, row);
    329329        if (!cell)
    330330                return false;
    331        
     331
    332332        /*
    333333         * Check whether the cell is not occupied by an
     
    336336        if ((!cell->widget) && (cell->cols > 0) && (cell->rows > 0))
    337337                return false;
    338        
     338
    339339        widget->parent = (widget_t *) grid;
    340        
     340
    341341        list_append(&widget->link, &grid->widget.children);
    342342        widget->window = grid->widget.window;
    343        
     343
    344344        /* Mark cells in layout */
    345345        for (size_t r = row; r < row + rows; r++) {
     
    359359                }
    360360        }
    361        
     361
    362362        return true;
    363363}
     
    368368        if ((cols == 0) || (rows == 0))
    369369                return false;
    370        
     370
    371371        grid->layout =
    372372            (grid_cell_t *) calloc(cols * rows, sizeof(grid_cell_t));
    373373        if (!grid->layout)
    374374                return false;
    375        
     375
    376376        memset(grid->layout, 0, cols * rows * sizeof(grid_cell_t));
    377        
     377
    378378        widget_init(&grid->widget, parent, data);
    379        
     379
    380380        grid->widget.destroy = grid_destroy;
    381381        grid->widget.reconfigure = grid_reconfigure;
     
    384384        grid->widget.handle_keyboard_event = grid_handle_keyboard_event;
    385385        grid->widget.handle_position_event = grid_handle_position_event;
    386        
     386
    387387        grid->add = grid_add;
    388388        grid->background = background;
    389389        grid->cols = cols;
    390390        grid->rows = rows;
    391        
     391
    392392        return true;
    393393}
     
    399399        if (!grid)
    400400                return NULL;
    401        
     401
    402402        if (init_grid(grid, parent, data, cols, rows, background))
    403403                return grid;
    404        
     404
    405405        free(grid);
    406406        return NULL;
Note: See TracChangeset for help on using the changeset viewer.