#pragma once
#include <stdint.h>
#include <memory>
#include "Syntax.h"
// TODO remove unique_ptr
class Buffer;
class Text;
using uint = uint32_t;
/// Line objects are temporary and should NOT be stored
/// Any modification to the linked Data would break the class
class Line {
protected:
Text* m_doc;
/// Line start in document
uint m_start;
/// Line length
uint m_size = 0;
/// Line number
uint m_number = 1;
/// Initializes m_size
void calc_size();
public:
/// Line from document
Line(Text* doc, uint start_char, uint line_number) : m_doc(doc), m_start(start_char), m_number(line_number) {
calc_size();
}
wchar_t operator[](uint pos) const;
wchar_t* begin() const;
wchar_t* end() const;
/// Clears the Line's syntax
void clear_syntax();
/// Erases the given range in the line
void erase(uint start, uint size);
/// Erases the next line
void erase_next();
/// Erases the previous line
void erase_prev();
/// Get the next Line
/// Check if is_last() first !
Line next() const;
/// Get previous Line
/// Check if is_first() first !
Line prev() const;
/// Create a new Line
Line make_next();
/// Returns the character at which the line starts
uint start() const { return m_start; }
/// Return Line number (starts at 1)
uint number() const { return m_number; }
/// Return Line length
uint length() const { return m_size; }
int get_current_indentation() const;
int get_next_indentation() const;
bool is_first() const;
bool is_last() const;
void insert(wchar_t c, uint pos);
void insert(wchar_t* str, uint size, uint pos);
/// Print on screen with syntax highlighting
void print(uint x, uint y, uint bg = 0) const;
/// Print on screen with syntax highlighting, from start and up
void printFrom(uint start, uint x, uint y, uint bg = 0) const;
/// Returns the number of lines the line would take in a specific buffer
uint height(Buffer& buf) const;
/// Returns the matching syntax data
syntax_t* syntax() const;
/// Get a copy of the contained text
std::unique_ptr<wchar_t[]> text_copy() const;
/// Returns max width of the line, counting tabs as 4 characters
uint width() const;
/// Returns the width of the line, up to the given position
uint width(uint pos) const;
};