Infinitely scrolling grid

This commit is contained in:
Synthasmagoria 2026-08-27 19:55:19 +02:00
commit ebd0ef76d3
3 changed files with 35 additions and 8 deletions

View file

@ -229,6 +229,7 @@ Program :: struct {
grid: Grid,
grid_zoom_x_only: bool,
grid_zoom_y_only: bool,
grid_zoom_speed: f32,
font_style: FontStyle,
state: ProgramState,
message_type: ProgramMessageType,
@ -301,6 +302,7 @@ program_init :: proc(allocator := context.allocator) {
world_position = 0.0,
world_size = program_screen_size()
}
program.grid_zoom_speed = 1.0
program.mouse_draggable_radius = 6.0
ui.init(&program.ui_context, 4000, ui_measure_text, &program.font_style, allocator)
@ -429,7 +431,6 @@ program_update :: proc() {
top_bar_container_br := rect_get_br(rect2(top_bar_container.area))
matrix_container_br := rect_get_br(rect2(matrix_container.area))
program.grid.world_size = program_screen_size()
grid_text_clip := rect_from_area(v2{matrix_container_br.x, top_bar_container_br.y}, program_screen_size())
draw_grid(program.grid, rect_grow(grid_text_clip, -4.0), rect_grow(grid_text_clip, -32.0))
@ -710,7 +711,7 @@ program_handle_mouse :: proc(mouse_state: MouseState, top_bar_container, matrix_
}
program.grid.zoom_previous = program.grid.zoom
grid_zoom_dimension_lock := v2{1.0 - f32(int(program.grid_zoom_y_only)), 1.0 - f32(int(program.grid_zoom_x_only))}
program.grid.zoom += grid_zoom_dimension_lock * mouse_wheel.y * 0.01
program.grid.zoom += grid_zoom_dimension_lock * mouse_wheel.y * 0.2 * program.grid_zoom_speed
case .DraggingDraggable:
if !rl.IsMouseButtonDown(.LEFT) {
mouse_state = .Hover