Scroll clamping
This commit is contained in:
@@ -12,6 +12,7 @@ struct LayoutRow {
|
||||
struct Layout {
|
||||
Array<LayoutRow> rows;
|
||||
Vec2 buffer_world_pixel_size;
|
||||
LayoutColumn *max_column;
|
||||
};
|
||||
|
||||
struct HistoryEntry {
|
||||
@@ -82,6 +83,10 @@ Layout CalculateLayout(Arena *arena, Buffer &buffer, Font font, float font_size,
|
||||
row->columns.add({cell_rect, iter.pos, (int)iter.item});
|
||||
row->rect.max = cell_rect.max;
|
||||
|
||||
if (layout.max_column == NULL || row->rect.max.x > layout.max_column->rect.max.x) {
|
||||
layout.max_column = row->columns.last();
|
||||
}
|
||||
|
||||
text_offset_x += x_to_offset_by;
|
||||
}
|
||||
|
||||
@@ -111,6 +116,10 @@ Layout CalculateLayout(Arena *arena, Buffer &buffer, Font font, float font_size,
|
||||
Rect2 cell_rect = {glyph_position, Vector2Add(glyph_position, cell_size)};
|
||||
row->columns.add({cell_rect, buffer.len, '\0'});
|
||||
row->rect = {glyph_position, cell_rect.max};
|
||||
|
||||
if (layout.max_column == NULL || row->rect.max.x > layout.max_column->rect.max.x) {
|
||||
layout.max_column = row->columns.last();
|
||||
}
|
||||
}
|
||||
|
||||
layout.buffer_world_pixel_size.y = text_offset_y;
|
||||
|
||||
@@ -123,8 +123,6 @@ int main() {
|
||||
|
||||
float mouse_wheel = GetMouseWheelMove() * 48;
|
||||
focused_window->scroll.y -= mouse_wheel;
|
||||
focused_window->scroll.y = ClampBottom(focused_window->scroll.y, 0.f);
|
||||
focused_window->scroll.x = ClampBottom(focused_window->scroll.x, 0.f);
|
||||
|
||||
MergeCursors(focused_window);
|
||||
if (IsKeyDown(KEY_LEFT_CONTROL) && IsKeyPressed(KEY_A)) {
|
||||
@@ -430,8 +428,8 @@ int main() {
|
||||
DrawRectangleRec(ToRectangle(window.rect), WHITE);
|
||||
|
||||
Vec2 size = GetSize(window.rect);
|
||||
Vec2 min = window.scroll / window.layout.buffer_world_pixel_size;
|
||||
Vec2 max = (window.scroll + size) / window.layout.buffer_world_pixel_size;
|
||||
Vec2 min = window.scroll / (window.layout.buffer_world_pixel_size + size);
|
||||
Vec2 max = (window.scroll + size) / (window.layout.buffer_world_pixel_size + size);
|
||||
|
||||
DrawRectangleRec(ToRectangle(vertical_bar_rect), GRAY);
|
||||
{
|
||||
@@ -456,7 +454,6 @@ int main() {
|
||||
}
|
||||
float value = GetMouseDelta().y / vert_size;
|
||||
window.scroll.y += value * window.layout.buffer_world_pixel_size.y;
|
||||
window.scroll.y = ClampBottom(window.scroll.y, 0.f);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -483,11 +480,15 @@ int main() {
|
||||
}
|
||||
float value = GetMouseDelta().x / hori_size;
|
||||
window.scroll.x += value * window.layout.buffer_world_pixel_size.x;
|
||||
window.scroll.x = ClampBottom(window.scroll.x, 0.f);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
window.scroll.y = Clamp(window.scroll.y, 0.f, window.layout.rows.last()->rect.min.y);
|
||||
window.scroll.x = Clamp(window.scroll.x, 0.f, window.layout.max_column->rect.min.x);
|
||||
}
|
||||
|
||||
// Mouse selection
|
||||
if (!window.mouse_selecting_hori_bar && !window.mouse_selecting_vert_bar) {
|
||||
bool mouse_in_window = CheckCollisionPointRec(mouse, ToRectangle(window.rect)) ||
|
||||
|
||||
Reference in New Issue
Block a user