| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960 |
- #pragma once
- #include "lumacs/buffer.hpp"
- #include <memory>
- #include <utility>
- #include <algorithm>
- namespace lumacs {
- struct Viewport {
- int width = 0;
- int height = 0;
- int scroll_offset = 0; // Vertical scroll (line offset)
- int horizontal_offset = 0; // Horizontal scroll (column offset)
- };
- class Window {
- public:
- Window(std::shared_ptr<Buffer> buffer);
- void set_buffer(std::shared_ptr<Buffer> buffer);
-
- // Accessors
- std::shared_ptr<Buffer> buffer_ptr() const { return buffer_; }
- Buffer& buffer() { return *buffer_; }
- const Buffer& buffer() const { return *buffer_; }
- void set_cursor(Position pos);
- Position cursor() const { return cursor_; }
- // Movement
- void move_up();
- void move_down();
- void move_left();
- void move_right();
- void move_to_line_start();
- void move_to_line_end();
- // Viewport
- void set_viewport_size(int width, int height);
- const Viewport& viewport() const { return viewport_; }
-
- void adjust_scroll();
-
- // Explicit scrolling (moves view, and cursor if necessary)
- void scroll_lines(int lines); // + for down, - for up
-
- std::pair<size_t, size_t> visible_line_range() const;
- private:
- void clamp_cursor();
- std::shared_ptr<Buffer> buffer_;
- Position cursor_;
- Viewport viewport_;
-
- static constexpr int SCROLL_MARGIN = 3;
- };
- } // namespace lumacs
|