You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: CHANGELOG.md
+1Lines changed: 1 addition & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -10,6 +10,7 @@ This file contains the changelog for the PlutoExtras package. It follows the [Ke
10
10
11
11
### Added
12
12
- Added possibility of providing any valid object with a `MIME"text/html"` representation as description of the `@NTBond` macro.
13
+
- Added the possibility of simplifying application of `PlutoUI.Experimental.transformed_value` to the fields of an `@NTBond` using the `@tv` decorator (see the example notebook for details).
13
14
14
15
### Changed
15
16
- Changed the hiding behavior of the `Popout` container so that it stays displayed if the mouse is hovering over its contents even if not popped out
# This will take an expression and check if it contains single underscores identifiers. If it does, it assumes it has to translate this into an anonymous function with a single argument that will go in place of the underscore
# This function will try parsing the fieldbond expression to eventually deal with `@tv`
36
+
process_fieldbond_expression(x) = x
37
+
functionprocess_fieldbond_expression(ex::Expr)
38
+
Meta.isexpr(ex, :macrocall) ||return ex
39
+
args =filter(x ->!(x isa LineNumberNode), ex.args)
40
+
macro_name = args[1]
41
+
macro_name ==Symbol("@tv") ||return ex
42
+
length(args) ==3||throw(ArgumentError("The @tv decorator has to be called with two arguments after it.\nThe first must be the transforming function and the second the widget"))
end_.a + _.b # This function is replaced within the macro to be `nt -> nt.a + nt.b`, which could have also been provided as anonymous function directly
155
155
156
156
# ╔═╡ 1d5573ee-872e-4dfb-a785-1ac9e836ad98
157
157
transformed_value_example
158
158
159
+
# ╔═╡ 5bb22f07-fbea-44ab-9783-9ca16e0da11e
160
+
md"""
161
+
### Transform only a few fields
162
+
"""
163
+
164
+
# ╔═╡ 134d6033-2f08-4f49-9829-6a023b368a70
165
+
md"""
166
+
A similar approach can also be achieved on a field by field basis by using the `@tv` decorator (which is not a macro per-se but is directly processed during the macro expansion of `@NTBond`).
167
+
168
+
`@tv` is a shorthand for transformed_value and it expects two arguments after it, the first being the function to process the value returned by the widget, and the second being the widget itself.
169
+
170
+
This can be used to be a bit less verbose when one is interested in only transforming one of many fields as below:
a = ("Angle [°]", @tv deg2rad Slider(0:90; default =60, show_value=true)) # This transforms the angle into radians
176
+
b =Slider(1:10)
177
+
c =Slider(1:10)
178
+
end
179
+
180
+
# ╔═╡ e102613f-244c-4b49-9837-535bf047a14a
181
+
transform_single_field
182
+
159
183
# ╔═╡ 8eb18c7f-bb4d-4cdc-9e30-d561f9099800
160
184
md"""
161
185
## Markdown math in description
@@ -166,11 +190,14 @@ md"""
166
190
The description of an `@NTBond` can now be provided as anything that has a valid `MIME"text/html"` representation. This includes markdown with math inside!
167
191
"""
168
192
193
+
# ╔═╡ bb04ac12-20a0-467a-af1a-c298301e4838
194
+
markdown_function = nt ->atan(nt.x, nt.y) +3
195
+
169
196
# ╔═╡ 36faf18c-11c3-4012-a996-55c7cdae71a8
170
197
math_ntbond =@bind atanval @NTBondmd"This is math!: ``\;atan(x,y) + 3``"begin
171
-
x = (md"``x``", Slider(1:10))
172
-
y = (md"``y``", Slider(1:10))
173
-
endnt ->atan(nt.x, nt.y) +3
198
+
x = (md"``x``", Slider(1:10; show_value=true))
199
+
y = (md"``y``", Slider(1:10; show_value=true))
200
+
endmarkdown_function # We can also directly use functions in the caller scope to transform the value
0 commit comments