Skip to content

Real-Time Mouse-Based Window Resizing - #130

Merged
markusressel merged 2 commits into
mainfrom
feature/window-resizing
Jun 21, 2026
Merged

Real-Time Mouse-Based Window Resizing#130
markusressel merged 2 commits into
mainfrom
feature/window-resizing

Conversation

@markusressel

Copy link
Copy Markdown
Owner

This Pull Request introduces real-time mouse resizing of the main three panels (File Browser, Dataset Info, and Snapshot Browser) in the terminal user interface (TUI). It enables smooth, visual border drag interactions while preventing deadlocks and terminal redraw flooding.


Key Features

1. Root-Level Mouse Drag Tracking

  • Reconfigured mouse capturing to bind to the top-level layout container (mainPageLayout) instead of individual window layouts.
  • Ensures mouse movement events are continually captured and processed even when the user moves the mouse cursor outside the boundary or panel dimensions quickly.

2. High-Performance Drag Mechanics (Lag & Flooding Prevention)

  • 30ms Redraw Throttling: Implemented a rate-limiter that restricts intermediate panel size updates and screen redraws to a maximum frequency of roughly 33 FPS.
  • Trailing Event Timer: Uses time.AfterFunc alongside application.QueueUpdateDraw to queue a final resize update 30ms after the last motion event. This ensures the panel lands precisely at the final cursor drop location without dropping the last frame.
  • Redraw CPU/Network Reduction: Consumes rate-limited move events by returning action, nil (suppressing immediate frame redraws) rather than triggering full terminal rerenders on every mouse pixel moved.

3. Precise Visual Border Highlighting

  • Custom layout highlights are painted dynamically via the tview.Application.SetAfterDrawFunc hook.
  • When hovering or dragging, the foreground color of only the adjacent boundary cells (columns for the vertical boundary, rows for the horizontal boundary) is overridden to theme.Primary (accent orange).
  • Restores panel borders to the default gray (theme.Colors.Layout.Border) when the mouse leaves.
  • Preserves all underlying double/single box-drawing characters, corner intersections, and header text since it only styles the foreground color.

4. Layout Sizing Consistency

  • Translates absolute drag coordinates into relative character proportions and applies them to child views using tview.Flex.ResizeItem.
  • Panels remain completely responsive to terminal window resizing.

Code Structure Changes

  • main_page.go:
    • Added drag & hover state fields to MainPage.
    • Added applyResize helper to update layout item sizing proportions.
    • Implemented top-level SetMouseCapture and application-wide SetAfterDrawFunc callbacks in createLayout.
  • data_loader.go:
    • Added SetBorderColor wrapper for LoadingContainer.
  • file_browser.go, dataset_info.go, and snapshot_browser.go:
    • Added SetBorderColor(tcell.Color) helper methods to individual panel components.

Validation & Deadlock Compliance

  • Checked that all layout and style properties are mutated synchronously inside input event handlers, allowing tview to handle redraw evaluations at the end of the event loop.
  • Ensured background routines (like the trailing timer) dispatch updates strictly via QueueUpdateDraw, preventing main-thread event loop deadlocks.
  • Verified that all unit tests (go test ./...) pass successfully.

      • Added  SetBorderColor(tcell.Color)  to  FileBrowserComponent  in file_browser.go.
      • Added  SetBorderColor(tcell.Color)  to  DatasetInfoComponent  in dataset_info.go.
      • Added  SetBorderColor(tcell.Color)  to  SnapshotBrowserComponent  in snapshot_browser.go.
      • Added  SetBorderColor(tcell.Color)  wrapper inside  LoadingContainer  in data_loader.go.
  2. Implemented coordinate tracking and resize interaction in main_page.go:
      • Configured  SetMouseCapture  on the parent  windowLayout .
      • Used absolute screen coordinates from  event.Position()  and checked them against the widget rectangles returned by  GetRect() .
      • Enabled interactive boundary hover detection: highlighting the border of adjacent windows with  theme.Primary  (accent orange) when
      the mouse is positioned on the boundaries.
      • Handled  MouseLeftDown  click drags to dynamically scale flex row/column proportions using  tview.Flex.ResizeItem , clamping panels
      to safe minimum boundaries (minimum 10 columns for browser width, 4 rows for dataset info height, 5 rows for snapshot browser height).
      • Released state tracking on  MouseLeftUp  or when buttons are released.
  • Moved the mouse capture handler from  windowLayout  up to the top-level  mainPageLayout . Because this spans the entire screen, fast
  mouse movements will never escape the captured region.
  • Added a 30ms rate-limiter (approx 33 FPS) that suppresses redundant intermediate layout calculations and screen redraws.
  • Integrated a trailing timer ( dragTimer  via  time.AfterFunc  calling  QueueUpdateDraw ) which guarantees that the final drag position
  is always visually captured and exact even if it fell within a rate-limited window.
  • Normal mouse events return  action, nil  (consumed but no redraw) during rate-limiting periods, drastically reducing CPU/network
  terminal redraw load.

  ### 2. Precise Boundary Highlighting (Adjacent Border Lines Only)

  • Reverted full panel border color changes to prevent the outer/non-adjacent sides of the windows from turning orange.
  • Utilized  tview 's  SetAfterDrawFunc  hook to draw highlights. In this hook, we query the character cells directly from  screen.
  GetContent(x, y)  at the active boundary column/row and dynamically override their foreground color style to  theme.Primary  (accent
  orange) while leaving the characters, corners, junction lines, and background styles completely intact.
@markusressel markusressel added the enhancement New feature or request label Jun 21, 2026
@markusressel
markusressel merged commit f9ee6df into main Jun 21, 2026
8 checks passed
@markusressel
markusressel deleted the feature/window-resizing branch June 21, 2026 23:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant