1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2025-01-24 07:56:52 +00:00

add convert.to.pixels.locally function that uses conver.to.pixels global function and refactor some global functions

This commit is contained in:
BurningTreeC 2024-10-27 16:41:37 +01:00
parent 30b4a4f58b
commit 801396b09a
2 changed files with 42 additions and 39 deletions

View File

@ -20,26 +20,29 @@ code-body: yes
\function convert.to.pt(value) [convert.to.in<value>multiply[72]]
\function convert.to.em(value) [[storyTiddler]is[variable]then<value>divide{$:/themes/tiddlywiki/vanilla/metrics/bodyfontsize}] [[storyTiddler]!is[variable]then<value>divide{$:/themes/tiddlywiki/vanilla/metrics/fontsize}]
\function convert.to.pixels(value,metric)
[<metric>match[cm]then<value>multiply[37.8]]
[<metric>match[mm]then<value>multiply[37.8]divide[10]]
[<metric>match[Q]then<value>multiply[37.8]divide[40]]
[<metric>match[in]then<value>multiply[96]]
[<metric>match[pc]then<value>multiply[96]divide[6]]
[<metric>match[pt]then<value>multiply[96]divide[72]]
[<metric>match[em]then[storyTiddler]is[variable]then<value>multiply{$:/themes/tiddlywiki/vanilla/metrics/bodyfontsize}]
[<metric>match[em]then[storyTiddler]!is[variable]then<value>multiply{$:/themes/tiddlywiki/vanilla/metrics/fontsize}]
\function convert.to.pixels(value)
[is.pixel.value<value>]
:else[is.cm.value<value>multiply[37.8]]
:else[is.mm.value<value>multiply[37.8]divide[10]]
:else[is.Q.value<value>multiply[37.8]divide[40]]
:else[is.in.value<value>multiply[96]]
:else[is.pc.value<value>multiply[96]divide[6]]
:else[is.pt.value<value>multiply[96]divide[72]]
:else[is.em.value<value>then[storyTiddler]is[variable]then<value>multiply{$:/themes/tiddlywiki/vanilla/metrics/bodyfontsize}]
:else[is.em.value<value>then[storyTiddler]!is[variable]then<value>multiply{$:/themes/tiddlywiki/vanilla/metrics/fontsize}]
\end
\function convert.to.pixels.metric(value,metric) [<value>addsuffix<metric>] :map[convert.to.pixels<currentTiddler>]
\function subtract.one.from.sidebarbreakpoint(value)
[is.pixel.value<value>subtract[1]addsuffix[px]]
:else[is.cm.value<value>convert.to.pixels<value>,[cm]subtract[1]divide[37.8]addsuffix[cm]]
:else[is.mm.value<value>convert.to.pixels<value>,[mm]subtract[1]divide[37.8]multiply[10]addsuffix[mm]]
:else[is.Q.value<value>convert.to.pixels<value>,[Q]subtract[1]divide[37.8]multiply[40]addsuffix[Q]]
:else[is.in.value<value>convert.to.pixels<value>,[in]subtract[1]divide[96]addsuffix[in]]
:else[is.pc.value<value>convert.to.pixels<value>,[pc]subtract[1]divide[96]multiply[6]addsuffix[pc]]
:else[is.pt.value<value>convert.to.pixels<value>,[pt]subtract[1]divide[96]multiply[72]addsuffix[pt]]
:else[is.em.value<value>convert.to.pixels<value>,[em]subtract[1]divide{$:/themes/tiddlywiki/vanilla/metrics/fontsize}addsuffix[em]]
:else[is.cm.value<value>convert.to.pixels.metric<value>,[cm]subtract[1]divide[37.8]addsuffix[cm]]
:else[is.mm.value<value>convert.to.pixels.metric<value>,[mm]subtract[1]divide[37.8]multiply[10]addsuffix[mm]]
:else[is.Q.value<value>convert.to.pixels.metric<value>,[Q]subtract[1]divide[37.8]multiply[40]addsuffix[Q]]
:else[is.in.value<value>convert.to.pixels.metric<value>,[in]subtract[1]divide[96]addsuffix[in]]
:else[is.pc.value<value>convert.to.pixels.metric<value>,[pc]subtract[1]divide[96]multiply[6]addsuffix[pc]]
:else[is.pt.value<value>convert.to.pixels.metric<value>,[pt]subtract[1]divide[96]multiply[72]addsuffix[pt]]
:else[is.em.value<value>convert.to.pixels.metric<value>,[em]subtract[1]divide{$:/themes/tiddlywiki/vanilla/metrics/fontsize}addsuffix[em]]
\end
\function sidebarbreakpoint() [{$:/themes/tiddlywiki/vanilla/metrics/sidebarbreakpoint}]
@ -48,13 +51,13 @@ code-body: yes
\function add.one.to.breakpoint(value)
[is.pixel.value<value>add[1]addsuffix[px]]
:else[is.cm.value<value>convert.to.pixels<value>,[cm]add[1]divide[37.8]addsuffix[cm]]
:else[is.mm.value<value>convert.to.pixels<value>,[mm]add[1]divide[37.8]multiply[10]addsuffix[mm]]
:else[is.Q.value<value>convert.to.pixels<value>,[Q]add[1]divide[37.8]multiply[40]addsuffix[Q]]
:else[is.in.value<value>convert.to.pixels<value>,[in]add[1]divide[96]addsuffix[in]]
:else[is.pc.value<value>convert.to.pixels<value>,[pc]add[1]divide[96]multiply[6]addsuffix[pc]]
:else[is.pt.value<value>convert.to.pixels<value>,[pt]add[1]divide[96]multiply[72]addsuffix[pt]]
:else[is.em.value<value>convert.to.pixels<value>,[em]add[1]divide{$:/themes/tiddlywiki/vanilla/metrics/fontsize}addsuffix[em]]
:else[is.cm.value<value>convert.to.pixels.metric<value>,[cm]add[1]divide[37.8]addsuffix[cm]]
:else[is.mm.value<value>convert.to.pixels.metric<value>,[mm]add[1]divide[37.8]multiply[10]addsuffix[mm]]
:else[is.Q.value<value>convert.to.pixels.metric<value>,[Q]add[1]divide[37.8]multiply[40]addsuffix[Q]]
:else[is.in.value<value>convert.to.pixels.metric<value>,[in]add[1]divide[96]addsuffix[in]]
:else[is.pc.value<value>convert.to.pixels.metric<value>,[pc]add[1]divide[96]multiply[6]addsuffix[pc]]
:else[is.pt.value<value>convert.to.pixels.metric<value>,[pt]add[1]divide[96]multiply[72]addsuffix[pt]]
:else[is.em.value<value>convert.to.pixels.metric<value>,[em]add[1]divide{$:/themes/tiddlywiki/vanilla/metrics/fontsize}addsuffix[em]]
\end
\function breakpoint-plus-one() [add.one.to.breakpoint{$:/config/plugins/menubar/breakpoint}] :else[{$:/config/plugins/menubar/breakpoint}]

View File

@ -11,7 +11,7 @@ title: $:/core/procedures/sidebar-resizer
\function convert.to.pt.value() [convert.to.pt<value>]
\function convert.to.em.value() [convert.to.em<value>]
\function convert.to.pixels(value) [is.pixel.value<value>] [is.percentage.value<value>multiply<widgetNodeWidth>divide[100]] [is.cm.value<value>multiply[37.8]] [is.mm.value<value>multiply[37.8]divide[10]] [is.Q.value<value>multiply[37.8]divide[40]] [is.in.value<value>multiply[96]] [is.pc.value<value>multiply[96]divide[6]] [is.pt.value<value>multiply[96]divide[72]] [is.em.value<value>multiply{$:/themes/tiddlywiki/vanilla/metrics/fontsize}]
\function convert.to.pixels.locally(value) [is.percentage.value<value>multiply<widgetNodeWidth>divide[100]] :else[convert.to.pixels<value>]
\function convert.to.result(value,suffix) [<suffix>match[px]then<value>] [<suffix>match[%]then<convert.to.percentage.value>] [<suffix>match[cm]then<convert.to.cm.value>] [<suffix>match[mm]then<convert.to.mm.value>] [<suffix>match[Q]then<convert.to.Q.value>] [<suffix>match[in]then<convert.to.in.value>] [<suffix>match[pc]then<convert.to.pc.value>] [<suffix>match[pt]then<convert.to.pt.value>] [<suffix>match[em]then<convert.to.em.value>]
@ -67,18 +67,18 @@ title: $:/core/procedures/sidebar-resizer
\procedure set-storywidth-storyright-actions()
<$let
storyRightStart={{{ [convert.to.pixels{$:/state/sidebar/resizing!!start-story-right}] }}}
storyWidthStart={{{ [convert.to.pixels{$:/state/sidebar/resizing!!start-story-width}] }}}
storyRightStart={{{ [convert.to.pixels.locally{$:/state/sidebar/resizing!!start-story-right}] }}}
storyWidthStart={{{ [convert.to.pixels.locally{$:/state/sidebar/resizing!!start-story-width}] }}}
storyMinWidthValue={{{ [<storyMinWidthTiddler>!is[blank]get[text]] :else[<get.theme.metric storyminwidth>] }}}
storyMinWidth={{{ [convert.to.pixels<storyMinWidthValue>] }}}
storyMinWidth={{{ [convert.to.pixels.locally<storyMinWidthValue>] }}}
sidebarMinWidthValue={{{ [<sidebarMinWidthTiddler>!is[blank]get[text]] :else[<get.theme.metric sidebarminwidth>] }}}
sidebarMinWidth={{{ [convert.to.pixels<sidebarMinWidthValue>] }}}
sidebarMinWidth={{{ [convert.to.pixels.locally<sidebarMinWidthValue>] }}}
storyPaddingLeftValue={{{ [<storyPaddingLeftTiddler>!is[blank]get[text]] :else[get.theme.metric[metrics/storypaddingleft]] }}}
storyPaddingLeft={{{ [convert.to.pixels<storyPaddingLeftValue>] }}}
storyPaddingLeft={{{ [convert.to.pixels.locally<storyPaddingLeftValue>] }}}
storyPaddingRightValue={{{ [<storyPaddingRightTiddler>!is[blank]get[text]] :else[get.theme.metric[metrics/storypaddingright]] }}}
storyPaddingRight={{{ [convert.to.pixels<storyPaddingRightValue>] }}}
storyPaddingRight={{{ [convert.to.pixels.locally<storyPaddingRightValue>] }}}
storyLeftValue={{{ [<storyLeftTiddler>!is[blank]get[text]] :else[<get.theme.metric storyleft>] }}}
storyLeft={{{ [convert.to.pixels<storyLeftValue>] }}}
storyLeft={{{ [convert.to.pixels.locally<storyLeftValue>] }}}
clampedDiff={{{ [<storyWidthStart>add<storyLeft>add<sidebarMinWidth>subtract<widgetNodeWidth>compare:number:gt[0]] ~0 }}}
storyWidthStart={{{ [<storyWidthStart>subtract<clampedDiff>] }}}
storyRightStart={{{ [<storyRightStart>subtract<clampedDiff>] }}}
@ -90,7 +90,7 @@ title: $:/core/procedures/sidebar-resizer
storyMaxWidth={{{ [<storyRiverLimit>subtract<storyLeft>] }}}
tiddlerWidthMetric={{$:/state/sidebar/resizing!!tiddler-width-metric}}
tiddlerWidthStart={{$:/state/sidebar/resizing!!start-tiddler-width}}
tiddlerWidthStartPixels={{{ [<tiddlerWidthMetric>match[%]then<tiddlerWidthStart>multiply<innerStoryWidthStart>divide[100]] :else[convert.to.pixels<tiddlerWidthStart>] }}}
tiddlerWidthStartPixels={{{ [<tiddlerWidthMetric>match[%]then<tiddlerWidthStart>multiply<innerStoryWidthStart>divide[100]] :else[convert.to.pixels.locally<tiddlerWidthStart>] }}}
tiddlerWidthClampedDiff={{{ [<tiddlerWidthStartPixels>add<storyPaddingLeft>add<storyPaddingRight>add<storyLeft>add<sidebarMinWidth>subtract<widgetNodeWidth>compare:number:gt[0]] ~0 }}}
tiddlerWidth={{{ [<tiddlerWidthStartPixels>add<dragDiff>subtract<tiddlerWidthClampedDiff>] }}}
tiddlerWidthDiff={{{ [<storyWidth>subtract<tiddlerWidth>] }}}
@ -138,11 +138,11 @@ title: $:/core/procedures/sidebar-resizer
<$let
sidebarMinWidthValue={{{ [<sidebarMinWidthTiddler>!is[blank]get[text]] :else[<get.theme.metric sidebarminwidth>] }}}
sidebarWidthMetric={{$:/state/sidebar/resizing!!sidebar-width-metric}}
sidebarMinWidth={{{ [convert.to.pixels<sidebarMinWidthValue>] }}}
sidebarMinWidth={{{ [convert.to.pixels.locally<sidebarMinWidthValue>] }}}
storyLeftValue={{{ [<storyLeftTiddler>!is[blank]get[text]] :else[<get.theme.metric storyleft>] }}}
storyLeft={{{ [convert.to.pixels<storyLeftValue>] }}}
storyLeft={{{ [convert.to.pixels.locally<storyLeftValue>] }}}
storyMinWidthValue={{{ [<storyMinWidthTiddler>!is[blank]get[text]] :else[<get.theme.metric storyminwidth>] }}}
storyMinWidth={{{ [convert.to.pixels<storyMinWidthValue>] }}}
storyMinWidth={{{ [convert.to.pixels.locally<storyMinWidthValue>] }}}
sidebarMaxWidth={{{ [<widgetNodeWidth>subtract<storyLeft>subtract<storyMinWidth>] }}}
clampedDiff={{{ [<storyLeft>add<storyMinWidth>add<startSidebarWidth>subtract<widgetNodeWidth>compare:number:gt[0]] ~0 }}}
sidebarWidth={{{ [<sidebarWidth>subtract<clampedDiff>] }}}>
@ -161,10 +161,10 @@ title: $:/core/procedures/sidebar-resizer
\procedure set-centralised-actions()
<$let
storyMinWidthValue={{{ [<storyMinWidthTiddler>!is[blank]get[text]] :else[{$:/themes/tiddlywiki/centralised/metrics/storyminwidth}] }}}
storyMinWidth={{{ [convert.to.pixels<storyMinWidthValue>] }}}
storyWidthStart={{{ [convert.to.pixels{$:/state/sidebar/resizing!!start-story-width}] }}}
storyMinWidth={{{ [convert.to.pixels.locally<storyMinWidthValue>] }}}
storyWidthStart={{{ [convert.to.pixels.locally{$:/state/sidebar/resizing!!start-story-width}] }}}
sidebarMinWidthValue={{{ [<sidebarMinWidthTiddler>!is[blank]get[text]] :else[{$:/themes/tiddlywiki/centralised/metrics/sidebarminwidth}] }}}
sidebarMinWidth={{{ [convert.to.pixels<sidebarMinWidthValue>] }}}
sidebarMinWidth={{{ [convert.to.pixels.locally<sidebarMinWidthValue>] }}}
storyMaxWidth={{{ [<widgetNodeWidth>subtract<sidebarMinWidth>subtract<sidebarMinWidth>] }}}
dragDiffMultiplied={{{ [<dragDiff>multiply[2]] }}}
storyWidthClamped={{{ [<storyWidthStart>add<sidebarMinWidth>add<sidebarMinWidth>subtract<widgetNodeWidth>compare:number:gt[0]] ~0 }}}
@ -189,7 +189,7 @@ title: $:/core/procedures/sidebar-resizer
\procedure sidebar-resizer-pointermove-actions()
<%if [[$:/state/sidebar/resizing]!is[missing]] %>
<$let widgetNodeWidth={{$:/state/sidebar/resizing!!widget-node-width}} dragDiff=<<get.drag.diff>> startStoryRight={{{ [convert.to.pixels{$:/state/sidebar/resizing!!start-story-right}] }}} storyRiverWidth={{{ [<startStoryRight>add<dragDiff>] }}} startSidebarWidth={{{ [convert.to.pixels{$:/state/sidebar/resizing!!start-sidebar-width}] }}} sidebarWidth={{{ [<startSidebarWidth>subtract<dragDiff>] }}}>
<$let widgetNodeWidth={{$:/state/sidebar/resizing!!widget-node-width}} dragDiff=<<get.drag.diff>> startStoryRight={{{ [convert.to.pixels.locally{$:/state/sidebar/resizing!!start-story-right}] }}} storyRiverWidth={{{ [<startStoryRight>add<dragDiff>] }}} startSidebarWidth={{{ [convert.to.pixels.locally{$:/state/sidebar/resizing!!start-sidebar-width}] }}} sidebarWidth={{{ [<startSidebarWidth>subtract<dragDiff>] }}}>
<%if [<tv-set-storywidth-storyright>match[yes]] %>
<<set_theme_throttling storyright>>
<<set_theme_throttling tiddlerwidth>>