{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# `ui.splitter`\n", "\n", "## 分隔器\n", "\n", "`ui.splitter` 元素将屏幕空间分割为可调整大小的部分,允许在应用程序中实现灵活和响应式布局。\n", "\n", "基于 Quasar 的 Splitter 组件:[Splitter](https://quasar.dev/vue-components/splitter)\n", "\n", "它提供三个可定制的插槽,`before`、`after` 和 `separator`,可用于在分隔器内嵌入其他元素。\n", "\n", "- `horizontal`:是否水平分割而不是垂直分割\n", "- `limits`:两个数字,表示两个面板的最小和最大分割尺寸\n", "- `value`:第一个面板(或使用 `reverse` 时的第二个)的大小\n", "- `reverse`:是否将模型大小应用于第二个面板而不是第一个\n", "-`on_change`:当用户释放分隔器时调用的回调函数" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "from nicegui import ui\n", "\n", "with ui.splitter() as splitter:\n", " with splitter.before:\n", " ui.label('This is some content on the left hand side.').classes('mr-2')\n", " with splitter.after:\n", " ui.label('This is some content on the right hand side.').classes('ml-2')\n", "\n", "# ui.run()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## 高级用法\n", "\n", "此演示展示了所有插槽和参数,包括一个工具提示、一个自定义分隔符和一个回调函数。" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "from nicegui import ui\n", "\n", "with ui.splitter(horizontal=False, reverse=False, value=60,\n", " on_change=lambda e: ui.notify(e.value)) as splitter:\n", " ui.tooltip('This is the default slot.').classes('bg-green')\n", " with splitter.before:\n", " ui.label('This is the left hand side.').classes('mr-2')\n", " with splitter.after:\n", " ui.label('This is the right hand side.').classes('ml-2')\n", " with splitter.separator:\n", " ui.icon('lightbulb').classes('text-green')\n", "\n", "ui.number('Split value', format='%.1f').bind_value(splitter)\n", "\n", "# ui.run()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## 图片乐趣\n", "\n", "此演示展示了如何使用分隔器并排显示图像。" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [], "source": [ "from nicegui import ui\n", "\n", "with ui.splitter().classes('w-72 h-48') \\\n", " .props('before-class=overflow-hidden after-class=overflow-hidden') as splitter:\n", " with splitter.before:\n", " ui.image('https://cdn.quasar.dev/img/parallax1.jpg').classes('w-72 absolute-top-left')\n", " with splitter.after:\n", " ui.image('https://cdn.quasar.dev/img/parallax1-bw.jpg').classes('w-72 absolute-top-right')\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 }