我想在Compose.jl上覆盖形状上的文字。例如,假设我想在这个形状的中心叠加一个标签:
<Page
x:Class="App1.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:App1"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">
<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<WebView Source="http://appstest.local/Survey" x:Name="WebView" Visibility="Visible" HorizontalAlignment="Left" Height="720" VerticalAlignment="Top" Width="1280"/>
</Grid>
</Page>
如何将文字叠加到这些对象上?
由于
答案 0 :(得分:2)
以下是一些代码片段,它覆盖了某些形状的文字:
try:
from threading import _Timer
except ImportError:
from threading import Timer as _Timer # Python 3.3+
def named_timer(name, interval, function, *args, **kwargs):
"""Factory function to create named Timer objects.
Timers call a function after a specified number of seconds:
t = Timer('Name', 30.0, function)
t.start()
t.cancel() # stop the timer's action if it's still waiting
"""
timer = _Timer(interval, function, *args, **kwargs)
timer.name = name
return timer
if __name__ == '__main__':
def func():
print('func() called')
timer = named_timer('Fidgit', 15, func)
print('timer.name: {!r}'.format(timer.name)) # -> timer.name: 'Fidgit'
timer.run() # causes "func() called" to be printed 15 seconds later
代码产生以下输出:
compose(
context(), fill("black"),
(context(0.2, 0.5), text(0.2, 0.1,"eeee", Compose.hcenter, Compose.vcenter)),
(context(0.2, 0.5, 0.4, 0.2), rectangle(), fill("green")),
(context(0.0, 0.6), text(0.25, 0.1, "aaaaaaaaaaabbbbbbbbbbbbcccccccc", Compose.hcenter, Compose.vcenter)),
(context(0.0, 0.6, 0.5, 0.2), rectangle(), fill("red"))
)
的两个第一个参数是文本相对于当前上下文的位置。
text()
和Compose.hcenter
是可选的,它们设置文本的水平和垂直对齐方式。用于对齐的选项是:
Compose.vcenter
vleft
vcenter
vright
htop
hcenter
不幸的是我没有找到要链接到的hbottom
函数的文档,只有它的定义,可以在github上找到here。