neovim

Neovim text editor
git clone https://git.dasho.dev/neovim.git
Log | Files | Refs | README

grid_defs.h (3803B)


      1 #pragma once
      2 
      3 #include <stdbool.h>
      4 #include <stddef.h>
      5 #include <stdint.h>
      6 
      7 #include "nvim/pos_defs.h"
      8 #include "nvim/types_defs.h"
      9 
     10 enum {
     11  kZIndexDefaultGrid = 0,
     12  kZIndexFloatDefault = 50,
     13  kZIndexPopupMenu = 100,
     14  kZIndexMessages = 200,
     15  kZIndexCmdlinePopupMenu = 250,
     16 };
     17 
     18 /// ScreenGrid represents a resizable rectuangular grid displayed by UI clients.
     19 ///
     20 /// chars[] contains the UTF-8 text that is currently displayed on the grid.
     21 /// It is stored as a single block of cells. When redrawing a part of the grid,
     22 /// the new state can be compared with the existing state of the grid. This way
     23 /// we can avoid sending bigger updates than necessary to the Ul layer.
     24 ///
     25 /// Screen cells are stored as NUL-terminated UTF-8 strings, and a cell can
     26 /// contain composing characters as many as fits in MAX_SCHAR_SIZE-1 bytes
     27 /// The composing characters are to be drawn on top of the original character.
     28 /// The content after the NUL is not defined (so comparison must be done a
     29 /// single cell at a time). Double-width characters are stored in the left cell,
     30 /// and the right cell should only contain the empty string. When a part of the
     31 /// screen is cleared, the cells should be filled with a single whitespace char.
     32 ///
     33 /// attrs[] contains the highlighting attribute for each cell.
     34 ///
     35 /// vcols[] contains the virtual columns in the line. -1 means not available
     36 /// or before buffer text.
     37 /// -2 or -3 means in fold column and a mouse click should:
     38 ///  -2: open a fold
     39 ///  -3: close a fold
     40 ///
     41 /// line_offset[n] is the offset from chars[], attrs[] and vcols[] for the start
     42 /// of line 'n'. These offsets are in general not linear, as full screen scrolling
     43 /// is implemented by rotating the offsets in the line_offset array.
     44 typedef struct ScreenGrid ScreenGrid;
     45 struct ScreenGrid {
     46  handle_T handle;
     47 
     48  schar_T *chars;
     49  sattr_T *attrs;
     50  colnr_T *vcols;
     51  size_t *line_offset;
     52 
     53  // last column that was drawn (not cleared with the default background).
     54  // only used when "throttled" is set. Not allocated by grid_alloc!
     55  int *dirty_col;
     56 
     57  // the size of the allocated grid.
     58  int rows;
     59  int cols;
     60 
     61  // The state of the grid is valid. Otherwise it needs to be redrawn.
     62  bool valid;
     63 
     64  // only draw internally and don't send updates yet to the compositor or
     65  // external UI.
     66  bool throttled;
     67 
     68  // whether the compositor should blend the grid with the background grid
     69  bool blending;
     70 
     71  // whether the grid interacts with mouse events.
     72  bool mouse_enabled;
     73 
     74  // z-index: the order in the stack of grids.
     75  int zindex;
     76 
     77  // Below is state owned by the compositor. Should generally not be set/read
     78  // outside this module, except for specific compatibility hacks
     79 
     80  // position of the grid on the composed screen.
     81  int comp_row;
     82  int comp_col;
     83 
     84  // Requested width and height of the grid upon resize. Used by
     85  // `ui_compositor` to correctly determine which regions need to
     86  // be redrawn.
     87  int comp_width;
     88  int comp_height;
     89 
     90  // z-index of the grid. Grids with higher index is draw on top.
     91  // default_grid.comp_index is always zero.
     92  size_t comp_index;
     93 
     94  // compositor should momentarily ignore the grid. Used internally when
     95  // moving around grids etc.
     96  bool comp_disabled;
     97 
     98  // need to resend win_float_pos or similar due to comp_index change
     99  bool pending_comp_index_update;
    100 };
    101 
    102 #define SCREEN_GRID_INIT { 0, NULL, NULL, NULL, NULL, NULL, 0, 0, false, \
    103                           false, false, true, 0, \
    104                           0, 0, 0, 0, 0,  false, true }
    105 
    106 /// Represents the position of a viewport within a ScreenGrid
    107 typedef struct {
    108  ScreenGrid *target;
    109  int row_offset;
    110  int col_offset;
    111 } GridView;
    112 
    113 typedef struct {
    114  int args[3];
    115  int icell;
    116  int ncells;
    117  int coloff;
    118  int cur_attr;
    119  int clear_width;
    120  bool wrap;
    121 } GridLineEvent;