audiovisual_elements.py 1.9 KB

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