Scrolling left right
This commit is contained in:
@@ -148,15 +148,15 @@ void HandleKeybindings(View *_view) {
|
||||
}
|
||||
}
|
||||
|
||||
// @todo: this should happen after we calculate rect for the view
|
||||
// @refactor: this should happen after we calculate rect for the view
|
||||
// Usually in other text editors apart from view there is also a 'window'
|
||||
// abstraction which is exactly the thing which shows the view, will need
|
||||
// which is exactly the thing which shows the view, will need
|
||||
// to think about this later
|
||||
if (!AreEqual(main_cursor_on_begin_frame, view.cursors[0])) {
|
||||
|
||||
Cursor c = view.cursors[0];
|
||||
Int front = GetFront(c);
|
||||
Int line = PosToLine(buf, front);
|
||||
XY xy = PosToXY(buf, front);
|
||||
|
||||
Rect2I GetVisibleCells(const View &view);
|
||||
Rect2I visible = GetVisibleCells(view);
|
||||
@@ -164,14 +164,24 @@ void HandleKeybindings(View *_view) {
|
||||
Vec2 visible_size = ToVec2(visible_cells) * Vec2{view.char_spacing, view.line_spacing};
|
||||
Vec2 rect_size = GetSize(view.rect);
|
||||
|
||||
if (line > visible.max.y - 3) {
|
||||
Int set_view_at_line = line - (visible_cells.y - 1);
|
||||
if (xy.line > visible.max.y - 3) {
|
||||
Int set_view_at_line = xy.line - (visible_cells.y - 1);
|
||||
float cut_off_y = Max(0.f, visible_size.y - rect_size.y);
|
||||
view.scroll.y = ((float)set_view_at_line * view.line_spacing) + cut_off_y;
|
||||
}
|
||||
|
||||
if (line < visible.min.y + 1) {
|
||||
view.scroll.y = line * view.line_spacing;
|
||||
if (xy.line < visible.min.y + 1) {
|
||||
view.scroll.y = xy.line * view.line_spacing;
|
||||
}
|
||||
|
||||
if (xy.col >= visible.max.x - 1) {
|
||||
Int set_view_at_line = xy.col - (visible_cells.x - 1);
|
||||
float cut_off_x = Max(0.f, visible_size.x - rect_size.x);
|
||||
view.scroll.x = ((float)set_view_at_line * view.char_spacing) + cut_off_x;
|
||||
}
|
||||
|
||||
if (xy.col <= visible.min.x) {
|
||||
view.scroll.x = xy.col * view.char_spacing;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user