diff options
| author | Albert Cervin <albert@acervin.com> | 2023-07-12 16:20:50 +0200 |
|---|---|---|
| committer | Albert Cervin <albert@acervin.com> | 2023-10-19 22:41:33 +0200 |
| commit | 54c9b4b533210b77be998f458ff96bdc54272f64 (patch) | |
| tree | eb434343bb1083172af50b7372d1e2745af00f8f /src/dged/location.h | |
| parent | 3a8ae83aa13636679c151027cace905fa87ebd8e (diff) | |
| download | dged-54c9b4b533210b77be998f458ff96bdc54272f64.tar.gz dged-54c9b4b533210b77be998f458ff96bdc54272f64.tar.xz dged-54c9b4b533210b77be998f458ff96bdc54272f64.zip | |
big buffer/buffer_view rework
A buffer is only the text and the corresponding operation. A buffer view
holds information about scroll, dot and mark positions. One way to think
about it is that a buffer is stateless whereas a buffer view is stateful.
Diffstat (limited to 'src/dged/location.h')
| -rw-r--r-- | src/dged/location.h | 81 |
1 files changed, 81 insertions, 0 deletions
diff --git a/src/dged/location.h b/src/dged/location.h new file mode 100644 index 0000000..d11dd94 --- /dev/null +++ b/src/dged/location.h @@ -0,0 +1,81 @@ +#ifndef _LOCATION_H +#define _LOCATION_H + +#include <stdbool.h> +#include <stdint.h> + +/** + * A location inside text. + */ +struct location { + /** The line in the text (0..) */ + uint32_t line; + + /** The column in the text (0..) */ + uint32_t col; +}; + +/** + * Is the location between two other locations. + * + * @param [in] location The location to test. + * @param [in] l1 The first location. + * @param [in] l2 The other location. + * @returns True if @ref location is between @ref l1 and @ref l2. + */ +bool location_is_between(struct location location, struct location l1, + struct location l2); + +/** + * Compare two locations. + * + * @param [in] l1 The first location. + * @param [in] l2 The second location. + * + * @returns -1 if @ref l1 is before @ref l2, 0 if @ref l1 is equal to @ref l2 + * and +1 if @ref l1 is after @ref l2. + */ +int location_compare(struct location l1, struct location l2); + +/** + * A region (area) in text. + */ +struct region { + /** The top left corner of the region. */ + struct location begin; + + /** The bottom right corner of the region. */ + struct location end; +}; + +/** + * Create a new region. + * + * Note that if begin is after end, their order will be reversed. + * + * @param [in] begin The point in the text where this region begins. + * @param [in] end The point in the text where this region ends. + * @returns a new region. + */ +struct region region_new(struct location begin, struct location end); + +/** + * Is this region covering anything? + * + * @param [in] region The region to check. + * @returns True if the region has a size > 0. + */ +bool region_has_size(struct region region); + +/** + * Is the location inside the region? + * + * @param [in] region The region to test. + * @param [in] location The location to test. + * @returns True if @ref location is inside @ref region. + */ +bool region_is_inside(struct region region, struct location location); + +bool region_is_inside_rect(struct region region, struct location location); + +#endif |
