robin/laufey
git clone https://git.robinwobin.dev/robin/laufey
aa1d8a2702
master
1#pragma once 2 3#include <stdbool.h> 4#include <stdint.h> 5 6#include "nvim/marktree_defs.h" 7#include "nvim/pos_defs.h" 8#include "nvim/types_defs.h" 9 10typedef bool CSType ; 11 12enum { 13kCharsizeRegular , 14kCharsizeFast , 15}; 16 17/// Argument for char size functions. 18typedef struct { 19win_T * win ; 20char * line ;///< Start of the line. 21 22bool use_tabstop ;///< Use 'tabstop' instead of char2cells() for a TAB. 23int indent_width ;///< Width of 'showbreak' and 'breakindent' on wrapped 24///< parts of lines, INT_MIN if not yet calculated. 25 26int virt_row ;///< Row for virtual text, -1 if no virtual text. 27bool skip_cur_text ;///< Don't count inline text at the measured character or advance iter. 28///< A CharsizeArg with this set cannot be reused for a later character. 29int cur_text_width_left ;///< Width of virtual text left of cursor. 30int cur_text_width_right ;///< Width of virtual text right of cursor. 31 32int max_head_vcol ;///< See charsize_regular(). 33MarkTreeIter iter [1 ]; 34}CharsizeArg ; 35 36typedef struct { 37int width ; 38int head ;///< Size of 'breakindent' etc. before the character (included in width). 39int tail ;///< Size of 'linebreak' after the character (included in width). 40}CharSize ; 41 42#include "plines.h.generated.h" 43#include "plines.h.inline.generated.h" 44 45/// Get the number of cells taken up on the screen by the given character at vcol. 46/// "csarg->cur_text_width_left" and "csarg->cur_text_width_right" are set 47/// to the extra size for inline virtual text. 48/// 49/// When "csarg->max_head_vcol" is positive, only count in "head" the size 50/// of 'showbreak'/'breakindent' before "csarg->max_head_vcol". 51/// When "csarg->max_head_vcol" is negative, only count in "head" the size 52/// of 'showbreak'/'breakindent' before where cursor should be placed. 53static inline CharSize win_charsize (CSType cstype ,int vcol ,char * ptr ,int32_t chr , 54CharsizeArg * csarg ,int mb_width ) 55FUNC_ATTR_NONNULL_ALL FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_ALWAYS_INLINE 56{ 57if (cstype == kCharsizeFast ) { 58return charsize_fast (csarg ,ptr ,vcol ,chr ,mb_width ); 59 }else { 60return charsize_regular (csarg ,ptr ,vcol ,chr ,mb_width ); 61 } 62} 63 64/// Return the number of cells the string "s" will take on the screen, 65/// taking into account the size of a tab. 66/// 67/// @param s 68/// 69/// @return Number of cells the string will take on the screen. 70static inline int linetabsize_str (char * s ) 71FUNC_ATTR_NONNULL_ALL FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_ALWAYS_INLINE 72{ 73return linetabsize_col (0 ,s ); 74} 75 76/// Like linetabsize_str(), but for a given window instead of the current one. 77/// Doesn't count the size of 'listchars' "eol". 78/// 79/// @param wp 80/// @param line 81/// @param len 82/// 83/// @return Number of cells the string will take on the screen. 84static inline int win_linetabsize (win_T * wp ,linenr_T lnum ,char * line ,colnr_T len ) 85FUNC_ATTR_NONNULL_ALL FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_ALWAYS_INLINE 86{ 87CharsizeArg csarg ; 88CSType const cstype = init_charsize_arg (& csarg ,wp ,lnum ,line ); 89if (cstype == kCharsizeFast ) { 90return linesize_fast (& csarg ,0 ,len ); 91 }else { 92return linesize_regular (& csarg ,0 ,len ); 93 } 94} 95 96/// Flags used by getvcol() 97enum { 98GETVCOL_END_EXCL_LBR = 1 , 99};