Created
August 14, 2019 23:28
-
-
Save tshirtman/2592d61a553ef5bae4cd85795882b3aa to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from kivy.lang import Builder | |
from kivy.properties import NumericProperty, ListProperty | |
from kivy.uix.label import Label | |
__all__ = ['RoundLabel'] | |
KV = ''' | |
#:import chain itertools.chain | |
#:import sin math.sin | |
#:import cos math.cos | |
<-RoundLabel>: | |
font_size: 16 | |
a: self.texture_size[0] / float(self.radius) | |
min_angle: self.angle - self.a / 2. | |
canvas: | |
Color: | |
rgba: self.color | |
Mesh: | |
mode: 'triangle_strip' | |
texture: self.texture | |
vertices: | |
list(chain(*[ | |
( | |
self.origin[0] + cos(self.min_angle + a * self.a) * self.radius, | |
self.origin[1] + sin(self.min_angle + a * self.a) * self.radius, 1 - float(a), 1, | |
self.origin[0] + cos(self.min_angle + a * self.a) * (self.radius + self.texture_size[1]), | |
self.origin[1] + sin(self.min_angle + a * self.a) * (self.radius + self.texture_size[1]), 1 - float(a), 0 | |
) | |
for a in (x / float(self.precision) for x in range(self.precision, 0, -1)) | |
]) if self.min_angle and self.radius and self.precision else []) | |
indices: range(2 * self.precision) | |
''' # noqa | |
class RoundLabel(Label): | |
radius = NumericProperty(50) | |
angle = NumericProperty(0) | |
origin = ListProperty([0, 0]) | |
precision = NumericProperty(10) | |
Builder.load_string(KV) | |
KV_DEMO = r''' | |
#:import pi math.pi | |
BoxLayout: | |
BoxLayout: | |
orientation: 'vertical' | |
RoundLabel: | |
text: ti.text | |
precision: precision.value | |
radius: radius.value | |
angle: angle.value | |
font_size: font_size.value | |
origin: self.center | |
TextInput: | |
id: ti | |
multiline: False | |
size_hint_y: None | |
height: self.minimum_height | |
text: 'default text' | |
BoxLayout: | |
orientation: 'vertical' | |
Label: | |
text: 'precision:\n {}'.format(precision.value) | |
Slider: | |
id: precision | |
min: 1 | |
max: 360 | |
step: 1 | |
value: 180 | |
Label: | |
text: 'radius:\n {}'.format(radius.value) | |
Slider: | |
id: radius | |
min: 20 | |
max: 500 | |
step: 1 | |
value: 100 | |
Label: | |
text: 'angle:\n {}'.format(angle.value) | |
Slider: | |
id: angle | |
min: 0 | |
max: 2 * pi | |
step: 0.01 | |
value: 0 | |
Label: | |
text: 'font size:\n {}'.format(font_size.value) | |
Slider: | |
id: font_size | |
min: 10 | |
max: 100 | |
step: 1 | |
value: 20 | |
''' | |
if __name__ == '__main__': | |
from kivy.base import runTouchApp | |
from kivy.lang import Builder | |
runTouchApp(Builder.load_string(KV_DEMO)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment