section_audiovisual_elements.py 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. from nicegui import ui
  2. from . import (audio_documentation, avatar_documentation, doc, icon_documentation, image_documentation,
  3. interactive_image_documentation, video_documentation)
  4. doc.title('*Audiovisual* Elements')
  5. doc.intro(image_documentation)
  6. @doc.demo('Captions and Overlays', '''
  7. By nesting elements inside a `ui.image` you can create augmentations.
  8. Use [Quasar classes](https://quasar.dev/vue-components/img) for positioning and styling captions.
  9. To overlay an SVG, make the `viewBox` exactly the size of the image and provide `100%` width/height to match the actual rendered size.
  10. ''')
  11. def captions_and_overlays_demo():
  12. with ui.image('https://picsum.photos/id/29/640/360'):
  13. ui.label('Nice!').classes('absolute-bottom text-subtitle2 text-center')
  14. with ui.image('https://cdn.stocksnap.io/img-thumbs/960w/airplane-sky_DYPWDEEILG.jpg'):
  15. ui.html('''
  16. <svg viewBox="0 0 960 638" width="100%" height="100%" xmlns="http://www.w3.org/2000/svg">
  17. <circle cx="445" cy="300" r="100" fill="none" stroke="red" stroke-width="20" />
  18. </svg>
  19. ''').classes('bg-transparent')
  20. doc.intro(interactive_image_documentation)
  21. doc.intro(audio_documentation)
  22. doc.intro(video_documentation)
  23. doc.intro(icon_documentation)
  24. doc.intro(avatar_documentation)
  25. @doc.demo('SVG', '''
  26. You can add Scalable Vector Graphics using the `ui.html` element.
  27. ''')
  28. def svg_demo():
  29. content = '''
  30. <svg viewBox="0 0 200 200" width="100" height="100" xmlns="http://www.w3.org/2000/svg">
  31. <circle cx="100" cy="100" r="78" fill="#ffde34" stroke="black" stroke-width="3" />
  32. <circle cx="80" cy="85" r="8" />
  33. <circle cx="120" cy="85" r="8" />
  34. <path d="m60,120 C75,150 125,150 140,120" style="fill:none; stroke:black; stroke-width:8; stroke-linecap:round" />
  35. </svg>'''
  36. ui.html(content)