{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# 操纵杆\n", "\n", "基于[nipple.js](https://yoannmoi.net/nipplejs/)创建一个操纵杆。" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "- `on_start`: 当用户触摸操纵杆时的回调\n", "- `on_move`: 当用户移动操纵杆时的回调\n", "- `on_end`: 用户释放操纵杆时的回调\n", "- `throttle`: 移动事件的 Throttle `interval` (以秒为单位)(默认值: `0.05`)\n", "- `options`: 像 `color` 这样的参数应该传递给底层的 [`nipple.js` 库](https://github.com/yoannmoinet/nipplejs#options)" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "from nicegui import ui\n", "\n", "ui.joystick(color='blue', size=50,\n", " on_move=lambda e: coordinates.set_text(f\"{e.x:.3f}, {e.y:.3f}\"),\n", " on_end=lambda _: coordinates.set_text('0, 0'))\n", "coordinates = ui.label('0, 0')\n", "\n", "# ui.run()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "py311", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.11.7" } }, "nbformat": 4, "nbformat_minor": 2 }