Metadata-Version: 2.1
Name: discord-ext-ui
Version: 1.0.1
Summary: An Declarative UI Kit for discord.py
Home-page: https://github.com/sizumita/discord-ext-ui
Author: sizumita
License: MIT
Platform: UNKNOWN
Classifier: Development Status :: 5 - Production/Stable
Classifier: License :: OSI Approved :: MIT License
Classifier: Intended Audience :: Developers
Classifier: Natural Language :: Japanese
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Classifier: Topic :: Internet
Classifier: Topic :: Software Development :: Libraries
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Classifier: Topic :: Utilities
Requires-Python: >=3.8.2
Description-Content-Type: text/x-rst
License-File: LICENSE

=====================
discord-ext-ui
=====================

This package is extension of discord.ui.

You can build ui like SwiftUI.

Features
========

View System
-----------

You can build UI by View class.

View.body function returns what you want to show.

Combine System
--------------

You can use Combine like Swift's Combine.


Example
=======

.. code-block:: python

    from discord.ext.ui import Component, Button, View, ObservedObject, Published, Message
    from discord.ext import commands
    import discord
    import os

    client = commands.Bot("!")


    class SampleViewModel(ObservedObject):
        def __init__(self):
            super().__init__()
            self.num = Published(0)

        def countup(self):
            self.num += 1

        def countdown(self):
            self.num -= 1


    class SampleView(View):
        def __init__(self):
            super().__init__()
            self.viewModel = SampleViewModel()

        async def add_reaction(self):
            await self.discord_message.add_reaction("\U0001f44d")

        async def body(self):
            return Message(
                content=f"test! {self.viewModel.num}",
                component=Component(items=[
                    [
                        Button("+1")
                            .on_click(lambda x: self.viewModel.countup())
                            .style(discord.ButtonStyle.blurple),

                        Button("-1")
                            .on_click(lambda x: self.viewModel.countdown())
                            .style(discord.ButtonStyle.blurple)
                    ]
                ])
            )


    @client.event
    async def on_message(message):
        if message.content != "!test":
            return
        await SampleView().start(client, message.channel)


