Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions docs/src/projects.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ from the catalog are saved with their constructors and can be edited on their pa
together, a group moved as a whole as one), new objects appear, changed ones are built again and
removed ones go. The window is never replaced.
- **Versions.** `Ctrl+S` writes what is still pending and saves a version of the project (a git
commit, without a git install). A card asks for its message, filled with what changed since the
last version.
commit, without a git install). A card in the middle of the view asks for its message, filled
with what changed since the last version.
- **Taking the files.** `Ctrl+R` makes the window as in the files: everything that differs is
taken from them, changes in the window that were not saved are lost.
- **Groups** made in the window are `@group` lines of the project.
Expand Down
13 changes: 13 additions & 0 deletions src/LiveCard.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1014,6 +1014,19 @@ function _spot_position(spot::Tuple{Bool, Bool, Vec2f}, size::Vec2f, view::Rect2
return Point2f(clamp(x, lo[1], max(lo[1], hi[1] - size[1])), clamp(y, min(hi[2], lo[2] + size[2]), hi[2]))
end

"""Top left corner [figure px] of a card of the `size` in the middle of the 3D view `view`."""
_center_position(size::Vec2f, view::Rect2f) =
Point2f(minimum(view)[1] + (Makie.widths(view)[1] - size[1]) / 2, minimum(view)[2] + (Makie.widths(view)[2] + size[2]) / 2)

"""
_centered(obj) -> Bool

Whether the card of `obj` belongs to the window rather than to a place in the scene: it stands in
the middle of the 3D view without a line, like a dialog (unless the mouse moved it), e.g. the card
of a new version of a project, see `_VersionCard`. `false` for everything else.
"""
_centered(@nospecialize(obj)) = false

# Rectangle [figure px] of a part of a card, which hangs down from the point of its suggested bounding box
function _part_rect(x::GridLayout)
p, s = minimum(x.layoutobservables.suggestedbbox[]), _card_size(x)
Expand Down
11 changes: 8 additions & 3 deletions src/LiveCards.jl
Original file line number Diff line number Diff line change
Expand Up @@ -506,17 +506,22 @@ function _update_card!(gui::LiveView, c::_ComponentCard, @nospecialize(obj), obs
_fit_properties!(c)
_fit_view!(c, view)
size = _card_size(c)
p = isnothing(c.spot) ? _avoid(_card_position(sel, size, view), size, view, obstacles) :
# A card of the window rather than of a place in the scene stands in the middle of the view,
# without a line, unless the mouse moved it, see `_centered`
centered = isnothing(c.spot) && _centered(obj)
p = centered ? _center_position(size, view) :
isnothing(c.spot) ? _avoid(_card_position(sel, size, view), size, view, obstacles) :
_spot_position(c.spot, size, view)
if isnothing(c.spot) && c.pinned && !c.collapsed && _covers(p, size, obstacles)
if !centered && isnothing(c.spot) && c.pinned && !c.collapsed && _covers(p, size, obstacles)
c.auto_collapsed = true
size = _card_size(c)
p = _avoid(_card_position(sel, size, view), size, view, obstacles)
end
_arrange_card!(c, p)
rect = _card_rect(p, size)
push!(obstacles, rect)
_update!(c.link, [_link_anchor(scene, corners, obj), Point2f(minimum(rect) .+ size ./ 2)])
_update!(c.link, _centered(obj) ? Point2f[] :
[_link_anchor(scene, corners, obj), Point2f(minimum(rect) .+ size ./ 2)])
_update!(c.scene.visible, true)
_show_view!(gui, c, obj)
return nothing
Expand Down
2 changes: 2 additions & 0 deletions src/LiveProject.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1207,6 +1207,8 @@ struct _VersionCard <: _InfoItem
end

_points(x::_VersionCard) = [x.point]
# A dialog of the window, not of a place in the scene, see `_centered`
_centered(::_VersionCard) = true
_title(::_VersionCard) = "Save a version"
_tree_kind(::_VersionCard) = :save
_keep_plots!(::LiveView, ::_VersionCard) = nothing
Expand Down
3 changes: 3 additions & 0 deletions test/TestLiveProject.jl
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,9 @@ const GUI = BeamletOpticsGUI
GUI._save_key!(gui)
c = GUI._version_card(gui)
@test !isnothing(c)
# in the middle of the view like a dialog, without a line to a point of the scene
@test GUI._centered(c.obj) && isempty(c.link[])
@test GUI._center_position(Vec2f(100, 50), Rect2f(10, 20, 400, 300)) == Point2f(160, 195)
box = GUI._version_box(gui)
@test box.displayed_string[] == "moved $lens" == version_summary(dir)
@test box.focused[] && gui.controls.ignore_keys()
Expand Down
Loading