Created
December 13, 2020 18:04
-
-
Save jkrumbiegel/fb0871fd7116d0a13992b184032995ea to your computer and use it in GitHub Desktop.
focus different laxis with keyboard press
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using GLMakie | |
set_window_config!(float = true) | |
# | |
scene, layout = layoutscene(resolution = (1000, 1000)) | |
offscreen_gl = GridLayout(bbox = BBox(-500, -400, -500, -400)) | |
axs = layout[] = [LAxis(scene, title = string(i)) for i in CartesianIndices((2, 2))] | |
for ax in axs | |
lines!(ax, randn(10), color = rand(RGBf0), linewidth = rand(1:10)) | |
end | |
display(scene) | |
## | |
function focus(i) | |
for (j, ax) in enumerate(axs) | |
if j != i | |
offscreen_gl[1, 1] = ax | |
else | |
layout[1, 1] = ax | |
end | |
end | |
trim!(layout) | |
end | |
function focus_all() | |
for (j, ax) in enumerate(axs) | |
layout[fldmod1(j, 2)...] = ax | |
end | |
end | |
on(scene.events.keyboardbuttons) do buttons | |
if ispressed(scene, Keyboard._1) | |
focus(1) | |
end | |
if ispressed(scene, Keyboard._2) | |
focus(2) | |
end | |
if ispressed(scene, Keyboard._3) | |
focus(3) | |
end | |
if ispressed(scene, Keyboard._4) | |
focus(4) | |
end | |
if ispressed(scene, Keyboard._0) | |
focus_all() | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment