Skip to content

Commit

Permalink
Add mouse coordinates display in live viewer
Browse files Browse the repository at this point in the history
  • Loading branch information
codejaeger committed Apr 16, 2021
1 parent 4241ea1 commit 7120fa5
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions src/javis_viewer.jl
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,9 @@ function _javis_viewer(
# Create a textbox
tbox = GtkReactive.textbox(Int; signal = signal(slide))

# Create a Gtk label to print the mouse coordinates upon hover
mouse_coordinates = GtkLabel("")

# Button for going forward through animation
forward = GtkButton("==>")

Expand All @@ -147,15 +150,24 @@ function _javis_viewer(
# Gtk Canvas object upon which to draw image; sized via frame size
canvas = Gtk.Canvas(frame_dims[1], frame_dims[2])

# Add callback to update mouse corrdinates over canvas
canvas.mouse.motion = @guarded (widget, event) -> begin
GAccessor.text(
mouse_coordinates,
"$(Int(round(event.x-frame_dims[1]/2))), $(Int(round(event.y-frame_dims[2]/2)))",
)
end

# Grid to allocate widgets
grid = Gtk.Grid()

# Allocate the widgets in a 3x3 grid
# Allocate the widgets in a 4x3 grid
grid[1:3, 1] = canvas
grid[1:3, 2] = slide
grid[1, 3] = backward
grid[2, 3] = tbox
grid[3, 3] = forward
grid[2, 2] = mouse_coordinates
grid[1:3, 3] = slide
grid[1, 4] = backward
grid[2, 4] = tbox
grid[3, 4] = forward

# Center all widgets vertically in grid
set_gtk_property!(grid, :valign, 3)
Expand Down

0 comments on commit 7120fa5

Please sign in to comment.