Skip to content

Commit

Permalink
Add a tooltip to all figures with a controls cheatsheet
Browse files Browse the repository at this point in the history
  • Loading branch information
JamesWrigley committed Aug 2, 2024
1 parent b70a3eb commit 476e283
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 5 deletions.
6 changes: 6 additions & 0 deletions docs/src/_changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ CurrentModule = CImGui
This documents notable changes in CImGui.jl. The format is based on [Keep a
Changelog](https://keepachangelog.com).

## [v2.2.0] - 2024-08-02

### Added
- Support for more GLMakie controls, and a tooltip for each figure by default
([#134]).

## [v2.1.0] - 2024-07-29

### Added
Expand Down
30 changes: 29 additions & 1 deletion ext/MakieIntegration.jl
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,29 @@ function apply_config!(screen::GLMakie.Screen, config::GLMakie.ScreenConfig)
screen.config = config
end

function ig.MakieFigure(title_id::String, f::GLMakie.Figure; auto_resize_x=true, auto_resize_y=false)
function draw_figure_tooltip(cursor_pos, image_size)
help_str = "(?)"
text_size = ig.CalcTextSize(help_str)
text_pos = (cursor_pos.x + image_size[1] - text_size.x, cursor_pos.y)
ig.AddText(ig.GetWindowDrawList(), text_pos, ig.IM_COL32_BLACK, help_str)
hovering = ig.IsMouseHoveringRect(text_pos, (text_pos[1] + text_size.x, text_pos[2] + text_size.y))

if hovering && ig.BeginTooltip()
ig.PushTextWrapPos(ig.GetFontSize() * 35.0)
ig.TextUnformatted("""
Controls:
- Scroll to zoom
- Click and drag to rectangle select a region to zoom to
- Right click and drag to pan
- Shift + {x/y} and scroll to zoom along the X/Y axes
- Ctrl + left click to reset the limits
""")
ig.PopTextWrapPos()
ig.EndTooltip()
end
end

function ig.MakieFigure(title_id::String, f::GLMakie.Figure; auto_resize_x=true, auto_resize_y=false, tooltip=true)
ig.PushID(title_id)
id = ig.GetID(title_id)

Expand Down Expand Up @@ -152,6 +174,12 @@ function ig.MakieFigure(title_id::String, f::GLMakie.Figure; auto_resize_x=true,
cursor_pos,
(cursor_pos.x + image_size[1], cursor_pos.y + image_size[2]),
(0, 1), (1, 0))

# Draw tooltip
if tooltip
draw_figure_tooltip(cursor_pos, image_size)
end

ig.InvisibleButton("figure_image", size(color_buffer))

# Update the scene events
Expand Down
10 changes: 6 additions & 4 deletions src/CImGui.jl
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,15 @@ const IMGUI_VERSION = unsafe_string(GetVersion())
# This is implemented by the MakieIntegration extension but we document it here
# so that we don't have to install GLMakie to build the docs.
"""
MakieFigure(id::String, f::GLMakie.Figure; auto_resize_x=true, auto_resize_y=false)
MakieFigure(id::String, f::GLMakie.Figure; auto_resize_x=true, auto_resize_y=false, tooltip=true)
Display a Makie figure in ImGui. See `examples/makie_demo.jl` for an example of
how to use it. This supports all the interaction features in GLMakie:
- Scrolling to zoom
- Rectangle select to zoom
- RMB to pan
- Scroll to zoom
- Click and drag to rectangle select a region to zoom to
- Right click and drag to pan
- Shift + {x/y} and scroll to zoom along the X/Y axes
- Ctrl + left click to reset the limits
Note that scrolling to zoom will also cause the ImGui window to scroll, which
can be annoying. This may be fixed in the future by using some other key
Expand Down

0 comments on commit 476e283

Please sign in to comment.