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
9 changes: 5 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ debug: folk
if [ "$$(uname)" = "Darwin" ]; then \
lldb -o "process handle -p true -s false SIGUSR1" -- ./folk; \
else \
DEBUGINFOD_URLS="" gdb -ex "handle SIGUSR1 nostop" -ex "handle SIGPIPE nostop" ./folk; \
gdb -ex "handle SIGUSR1 nostop" -ex "handle SIGPIPE nostop" ./folk; \
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Why was this removed? The debuginfod suppression is there because it would hang in gdb on accessing it for me (can add a comment about that)

fi

clean:
Expand Down Expand Up @@ -115,19 +115,20 @@ kill-folk:
fi

FOLK_REMOTE_NODE ?= folk-live
FOLK_SYNC_IGNORES ?= $(shell git rev-parse --git-path ignores.tmp 2>/dev/null || printf '%s\n' .git/ignores.tmp)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

what does this fix?


sync:
ssh $(FOLK_REMOTE_NODE) -t \
'cd ~/folk && git init > /dev/null && git ls-files --exclude-standard -oi --directory' \
> .git/ignores.tmp || true
git ls-files --exclude-standard -oi --directory >> .git/ignores.tmp
> '$(FOLK_SYNC_IGNORES)' || true
git ls-files --exclude-standard -oi --directory >> '$(FOLK_SYNC_IGNORES)'
rsync --timeout=15 -e "ssh -o StrictHostKeyChecking=no" \
--archive --delete --itemize-changes \
--exclude='/.git' \
--exclude-from='$(FOLK_SYNC_IGNORES)' \
--exclude='vendor/tracy/public/TracyClient.o' \
--include='vendor/tracy/public/***' \
--exclude='vendor/tracy/*' \
--exclude-from='.git/ignores.tmp' \
./ $(FOLK_REMOTE_NODE):~/folk/

remote-setup:
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -517,7 +517,7 @@ Use it in an animation:

```
When the clock time is /t/ {
Wish $this draws a circle with offset [list [expr {sin($t) * 50}] 0]
Wish $this draws a circle with offset [list [expr {sin($t) * 5.0}]cm 0cm] radius 1.2cm
}
```

Expand Down
2 changes: 1 addition & 1 deletion builtin-programs/connections.folk
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Connection wish fulfillment
# for wishes of the form:
# "Wish $tag is connected to $tag2" or "Wish $tag is dynamically connected to $tag2"

return; # TODO: FIXME
When /anyone/ wishes /source/ is connected to /sink/ {
Wish $source is connected to $sink from centroid to centroid
}
Expand Down
62 changes: 39 additions & 23 deletions builtin-programs/decorations/label.folk
Original file line number Diff line number Diff line change
@@ -1,34 +1,50 @@
fn drawLabelMaxLineLength {text} {
set maxLength 0
foreach line [split $text "\n"] {
set lineLength [string length $line]
if {$lineLength > $maxLength} {
set maxLength $lineLength
}
}
return $maxLength
}

fn drawLabelDefaultScale {text} {
set maxLength [drawLabelMaxLineLength $text]
if {$maxLength == 0} { return 0.02 }
::math::min 0.02 [/ 0.45 $maxLength]
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

would be better style to use explicit return

}

fn drawLabelDefaultOptions {text width height} {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

In general, I don't really like all these utility functions, but I could be convinced otherwise. @ppkn @smj-edison what do you think?

Lots of repetition since you need to restate and pass in all the parameters, and it doesn't fit the style we use in existing drawing programs. I think a straight-line When body is easier to read than having like 4 functions in each file.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I'm not opposed to utility functions, as long as they're used multiple times and don't cause indirection fatigue. I think in this case it might be clearer inline, since they're not used that often.

set scale [drawLabelDefaultScale $text]
set position [list [expr {$width / 2.0}] [expr {$height / 2.0}]]
dict create \
position $position \
scale $scale \
anchor center \
font "PTSans-Regular"
}

When /thing/ has resolved geometry /geom/ {
When the collected results for [list /someone/ wishes $thing is labelled /text/ with /...options/] are /results/ {
set text [join [lmap result $results {dict get $result text}] "\n"]
if {$text eq ""} { return }

# Split text into lines and find the longest line.
set lines [split $text "\n"]
set maxLength 0
foreach line $lines {
set lineLength [string length $line]
if {$lineLength > $maxLength} {
set maxLength $lineLength
}
set width [dict get $geom width]
set height [dict get $geom height]
set options [drawLabelDefaultOptions $text $width $height]
if {[dict exists $geom top] &&
[dict exists $geom tagSize] &&
[dict exists $geom bottom]} {
dict set options position \
[list [expr {$width / 2.0}] \
[expr {[dict get $geom top] + [dict get $geom tagSize] + [dict get $geom bottom] / 2.0}]]
}

# Set default scale based on longest line length.
# Scale inversely with length to keep text readable.
set defaultScale [::math::min 0.02 [/ 0.45 $maxLength]]

set x [/ $geom(width) 2.0]
try {
set y $($geom(top) + $geom(tagSize) + $geom(bottom)/2.0)
} on error e {
set y [/ $geom(height) 2.0]
foreach result $results {
set options [dict merge $options [dict get $result options]]
}
set options [dict create x $x y $y scale $defaultScale]
# FIXME: support per-label options; right now, this just
# applies an arbitrary label's options to all of them
# together.
set options [dict merge $options [dict get $result options]]
dict set options text $text

Wish to draw text onto $thing with {*}$options
}
}
Expand Down
72 changes: 62 additions & 10 deletions builtin-programs/decorations/outline.folk
Original file line number Diff line number Diff line change
@@ -1,13 +1,65 @@
When /someone/ wishes /thing/ is outlined /color/ &\
/thing/ has resolved geometry /geom/ {
dict with geom {
set points [list [list 0 0] \
[list $width 0] \
[list $width $height] \
[list 0 $height] \
[list 0 0]]
}
fn drawOutlinePoints {width height} {
return [list [list 0 0] \
[list $width 0] \
[list $width $height] \
[list 0 $height] \
[list 0 0]]
}

fn drawOutlineOptions {color options} {
if {![info exists options]} { set options [dict create] }
dict set options color $color
return $options
}

fn drawOutlineOptionTail {key value rest} {
if {![info exists rest]} { set rest [list] }
return [list $key $value {*}$rest]
}

fn drawOutlineOnto {thing geom options} {
if {![info exists options]} { set options [dict create] }
set color [dict getdef $options color white]
set outlineWidth [drawPhysicalLength \
[dict getdef $options width [dict getdef $options thickness 1cm]]]
set layer [dict getdef $options layer 2]

Wish to draw a line onto $thing with \
points $points width 0.01 color $color
points [drawOutlinePoints [dict get $geom width] [dict get $geom height]] \
width $outlineWidth color $color layer $layer
}

When /thing/ has resolved geometry /geom/ &\
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This stuff is really ugly:

Image

I would rather standardize on one variant (even if we have to break compatibility) and/or add some syntax sugar (maybe so one handler can deal with both with and non-with variants?) than have all of this stuff all over the codebase -- it's very low-information-density and hard to read.

/someone/ wishes /thing/ is outlined /color/ {
drawOutlineOnto $thing $geom [drawOutlineOptions $color [dict create]]
}

When /thing/ has resolved geometry /geom/ &\
/someone/ wishes /thing/ is outlined /color/ with /optionKey/ /optionValue/ /...optionRest/ {
if {![info exists optionKey] || ![info exists optionValue]} { return }
if {![info exists optionRest]} { set optionRest [list] }
set options [drawOutlineOptionTail $optionKey $optionValue $optionRest]
drawOutlineOnto $thing $geom [drawOutlineOptions $color $options]
}

When /thing/ has resolved geometry /geom/ &\
/someone/ wishes /thing/ is outlined /color/ with /optionKey/ /optionValue/ {
if {![info exists optionKey] || ![info exists optionValue]} { return }
set options [list $optionKey $optionValue]
drawOutlineOnto $thing $geom [drawOutlineOptions $color $options]
}

When /thing/ has resolved geometry /geom/ &\
/someone/ wishes /thing/ is outlined with /optionKey/ /optionValue/ /...optionRest/ {
if {![info exists optionKey] || ![info exists optionValue]} { return }
if {![info exists optionRest]} { set optionRest [list] }
set options [drawOutlineOptionTail $optionKey $optionValue $optionRest]
drawOutlineOnto $thing $geom $options
}

When /thing/ has resolved geometry /geom/ &\
/someone/ wishes /thing/ is outlined with /optionKey/ /optionValue/ {
if {![info exists optionKey] || ![info exists optionValue]} { return }
set options [list $optionKey $optionValue]
drawOutlineOnto $thing $geom $options
}
18 changes: 17 additions & 1 deletion builtin-programs/demos.folk
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ Claim 45004 has demo code {
}
Claim 45005 has demo code {
When the clock time is /t/ {
Wish $this draws a circle offset [list expr {sin($t) * 50} 0]
Wish $this draws a circle with offset [list [expr {sin($t) * 5.0}cm] 0cm] radius 1.2cm
}
}
Claim 45006 has demo code {
Expand All @@ -43,3 +43,19 @@ Claim 45008 has demo code {
Wish $this displays camera slice $slice
}
}

When /someone/ wishes /program/ runs demo code from /filename/ {
Hold! -key "active-demo-$program" Claim $program running demo code from $filename
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

shouldn't need to use Hold! ; also not a proper English sentence

On unmatch {
if {[llength [Query! /someone/ wishes $program runs demo code from /any/]] == 0} {
Hold! -key "active-demo-$program"
}
}
}

When /program/ running demo code from /filename/ {
When $filename has demo code /code/ {
set this $program
eval $code
}
}
39 changes: 0 additions & 39 deletions builtin-programs/display/arc.folk

This file was deleted.

Loading