audiovisual_elements.py 2.0 KB

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