Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FIX: issue #4733 ([VID] Late switching of layout direction) #4734

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
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
33 changes: 22 additions & 11 deletions modules/view/VID.red
Original file line number Diff line number Diff line change
Expand Up @@ -520,7 +520,7 @@ system/view/VID: context [
/local axis anti ;-- defined in a SET block
][
background!: make typeset! [image! file! url! tuple! word! issue!]
list: make block! 4 ;-- panel's pane block
limit: list: make block! 4 ;-- panel's pane block
reactors: make block! 10 ;-- reactors of this particular layout
local-styles: any [css make block! 2] ;-- panel-local styles definitions
pane-size: 0x0 ;-- panel's content dynamic size
Expand All @@ -529,7 +529,7 @@ system/view/VID: context [
begin: tail list
size: none ;-- user-set panel's size
max-sz: 0 ;-- maximum width/height of current column/row
current: 0 ;-- layout's cursor position
last-size: none ;-- last laid out face's size
global?: yes ;-- TRUE: panel options expected
below?: no

Expand All @@ -549,6 +549,7 @@ system/view/VID: context [
]
align-faces begin direction align max-sz
begin: tail list
unless empty? limit [begin: back begin] ;-- allow to realign the last face (e.g. below -> across -> across bottom)

words: pick [[left center right][top middle bottom]] below?
align: any [ ;-- set new alignment
Expand All @@ -560,14 +561,17 @@ system/view/VID: context [
]

reset: [
if last-size [cursor/:anti: cursor/:anti - last-size/:anti]
bound: max bound cursor
if zero? max-sz [ ;-- if empty row/col, make some room
max-sz: spacing/:anti
cursor/:anti: cursor/:anti + max-sz
]
limit: tail list ;-- exclude placed items from further alignment
do re-align
cursor: as-pair origin/:axis spacing/:anti + max bound/:anti cursor/:anti + max-sz
if direction = 'below [cursor: reverse cursor]
last-size: none
max-sz: 0
]

Expand Down Expand Up @@ -617,19 +621,24 @@ system/view/VID: context [
below
across [
below?: value = 'below
saved: attempt [select last list 'offset]
do re-align
all [
direction <> value ;-- if direction changed
anti2: pick [y x] value = 'across
cursor/:anti2 <> origin/:anti2 ;-- and if not close to opposite edge
cursor/:anti2: cursor/:anti2 + spacing/:anti2 ;-- ensure proper spacing when changing direction
max-sz: 0
if begin/1 [ ;-- last face is still subject to alignment?
cursor: cursor - saved + begin/1/offset ;-- re-align may have moved the last face
max-sz: begin/1/size/(pick [x y] below?)
if divides [throw-error spec] ;-- forbid change of direction in grid mode
]
direction: value
bound: max bound cursor
max-sz: 0
]
space [spacing: fetch-argument pair! spec]
origin [origin: cursor: pad + top-left: fetch-argument pair! spec]
origin [
origin: cursor: pad + top-left: fetch-argument pair! spec
do re-align
limit: tail list
last-size: none
]
at [at-offset: fetch-expr 'spec spec: back spec]
pad [cursor: cursor + fetch-argument pair! spec]
do [do-safe bind fetch-argument block! spec panel]
Expand Down Expand Up @@ -711,13 +720,14 @@ system/view/VID: context [
][
do reset
][ ;-- flow layout
if all [max-sz > 0 cursor/:axis <> origin/:axis][
if last-size [
cursor/:axis: cursor/:axis + spacing/:axis
cursor/:anti: cursor/:anti - last-size/:anti
]
]
max-sz: max max-sz face/size/:anti
face/offset: cursor
cursor/:axis: cursor/:axis + face/size/:axis
cursor: cursor + last-size: face/size

if all [divide? index > 0][
index: index + 1
Expand Down Expand Up @@ -745,6 +755,7 @@ system/view/VID: context [
]
spec: next spec
]
if last-size [cursor/:anti: cursor/:anti - last-size/:anti]
do re-align
process-reactors reactors ;-- Needs to be after [set name face]

Expand Down
3 changes: 1 addition & 2 deletions tests/clip-test.red
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,6 @@ board: layout [
below
label: text "" 200x30 font [size: 14]
canvas: base 200x200 255.0.0.128
below
across
btn-prev: button "previous" [
unless btn-next/enabled? [ btn-next/enabled?: true ]
either index > 2 [
Expand All @@ -72,6 +70,7 @@ board: layout [
show canvas
][ btn-prev/enabled?: false ]
]
across
btn-next: button "next" [
unless btn-prev/enabled? [ btn-prev/enabled?: true ]
either index < length? drawings [
Expand Down
3 changes: 1 addition & 2 deletions tests/complexpen-test.red
Original file line number Diff line number Diff line change
Expand Up @@ -681,8 +681,6 @@ board: layout [
below
label: text "" 400 font [size: 16]
canvas: base 700x400
below
across
btn-prev: button "previous" [
unless btn-next/enabled? [ btn-next/enabled?: true ]
either index > 2 [
Expand All @@ -692,6 +690,7 @@ board: layout [
show canvas
][ btn-prev/enabled?: false ]
]
across
btn-next: button "next" [
unless btn-prev/enabled? [ btn-prev/enabled?: true ]
either index < length? drawings [
Expand Down
3 changes: 1 addition & 2 deletions tests/matrix-test.red
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,6 @@ board: layout [
below
label: text "" 200x30 font [size: 14]
canvas: base 600x400
below
across
btn-prev: button "previous" [
unless btn-next/enabled? [ btn-next/enabled?: true ]
either index > 2 [
Expand All @@ -98,6 +96,7 @@ board: layout [
show canvas
][ btn-prev/enabled?: false ]
]
across
btn-next: button "next" [
unless btn-prev/enabled? [ btn-prev/enabled?: true ]
either index < length? drawings [
Expand Down
3 changes: 1 addition & 2 deletions tests/select-text.red
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ view [
f/parent/selected: f
f/selected: 1x5
]
across
text "Field:" 30 text "" left react [face/data: f/selected] return
text "Field:" 30 across text "" left react [face/data: f/selected] return
text "Area:" 30 text "" left react [face/data: a/selected]
]
]
3 changes: 1 addition & 2 deletions tests/shape-test.red
Original file line number Diff line number Diff line change
Expand Up @@ -231,8 +231,6 @@ board: layout [
below
label: text "" 200 font [size: 16]
canvas: base 700x400
below
across
btn-prev: button "previous" [
unless btn-next/enabled? [ btn-next/enabled?: true ]
either index > 2 [
Expand All @@ -242,6 +240,7 @@ board: layout [
show canvas
][ btn-prev/enabled?: false ]
]
across
btn-next: button "next" [
unless btn-prev/enabled? [ btn-prev/enabled?: true ]
either index < length? drawings [
Expand Down
3 changes: 2 additions & 1 deletion tests/vid.red
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,14 @@ view [
"tab2" [at 80x10 text "two"]
]

below
slider 5%
below
pad 10x0 bar: progress 50% 130
base 255.0.0.138 50x50 draw [fill-pen blue circle 25x25 15]
across
return middle

pad 0x20
check "option 1" font-size 14
check "option 2" font-color orange
radio "option 3" font-name "Times New Roman"
Expand Down
13 changes: 6 additions & 7 deletions tests/vid2.red
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,12 @@ view [

below left
button "ok" base green text "4"
button "ok"
across base yellow 350x250 text "5"

across
button "ok" base yellow 350x250 text "5"
button "ok"
below center base green text "6" return

below center
button "ok" base green text "6" return

below right
button "ok" base green text "7" return
button "ok"
below right base green text "7" return
]
1 change: 1 addition & 0 deletions tests/vid5.red
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Red [
system/view/VID/debug?: yes
view [
at 1x110 base 1100x1 black
origin 10x10
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is at modifying the flow cursor now? That should not happen. at is meant to specify an absolute position that does not interfere with the automatic layout system.

Copy link
Collaborator Author

@hiiamboris hiiamboris Dec 1, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not. But debug facilities (in re-align) are rather dumb. They see at.. base.. across top base.. as a single row (the begin word points at first base). Exclusion of at items is done in another place (align-faces), which re-align doesn't know of. Previously, when across was starting a row, begin pointed at the second base and debug lines were drawn properly.

This line origin 10x10 only fixes the debug lines in this particular case, and has no effect on layout itself. To properly draw debug lines we need to remove at-positioned faces right in the layout function. I considered it not worth the effort to do so.

across top base 1x60 button 50x50 button "OK" text "text" cyan field drop-down drop-list check yellow radio yellow progress slider return
across middle base 1x60 button 50x50 button "OK" text "text" cyan field drop-down drop-list check yellow radio yellow progress slider return
across bottom base 1x60 button 50x50 button "OK" text "text" cyan field drop-down drop-list check yellow radio yellow progress slider
Expand Down
1 change: 1 addition & 0 deletions tests/vid6.red
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Red [
system/view/VID/debug?: yes
view [
at 320x1 base 1x400 black
origin 10x10
below left base 200x1 button 50x50 button "OK" text "text" cyan field drop-down check yellow radio yellow drop-list progress slider return
below center base 200x1 button 50x50 button "OK" text "text" cyan field drop-down check yellow radio yellow drop-list progress slider return
below right base 200x1 button 50x50 button "OK" text "text" cyan field drop-down check yellow radio yellow drop-list progress slider
Expand Down