building out UI a ton more and also working on serialization and deserial for the desktop app

This commit is contained in:
2026-03-08 14:09:43 +11:00
parent 0a560dca17
commit 12a8bd4c19
7 changed files with 158 additions and 24 deletions

View File

@@ -1,5 +1,5 @@
from textual.containers import VerticalScroll, Vertical, HorizontalGroup
from textual.widgets import Static, Button, Rule
from textual.widgets import Static, Button, Rule, ContentSwitcher
from api.channel import Channel
@@ -37,16 +37,19 @@ class ChannelsList(Vertical):
}
"""
def on_button_pressed(self, event: ChannelView.Pressed):
self.screen.query_one(ContentSwitcher).current = "chat-window"
def compose(self):
with VerticalScroll():
yield Static("channels", classes="banner")
yield ChannelView(Channel("test channel", "AQ=="))
yield ChannelView(Channel("test channel", "AQ=="))
yield ChannelView(Channel("test channel", "AQ=="))
yield ChannelView(Channel("test channel", "AQ=="))
yield ChannelView(Channel("test channel", "AQ=="))
yield ChannelView(Channel("test channel", "AQ=="))
yield ChannelView(Channel("test channel", "AQ=="))
yield ChannelView(Channel("test channel 1", "AQ=="))
yield ChannelView(Channel("test channel 2", "AQ=="))
yield ChannelView(Channel("test channel 3", "AQ=="))
yield ChannelView(Channel("test channel 4", "AQ=="))
yield ChannelView(Channel("test channel 5", "AQ=="))
yield ChannelView(Channel("test channel 6", "AQ=="))
yield ChannelView(Channel("test channel 7", "AQ=="))
yield Rule()

View File

@@ -1,16 +1,82 @@
from textual.containers import Vertical, VerticalScroll, HorizontalGroup
from textual.containers import Vertical, VerticalScroll, VerticalGroup, HorizontalGroup
from textual.widgets import Input, Button, Static
from api.message import Message
from api.node import MeshNode
class Message(Static):
def __init__(self, message):
class MessageView(VerticalGroup):
DEFAULT_CSS = """
MessageView {
margin-bottom: 1;
#message-text {
background: $surface;
padding: 1;
width: auto;
max-width: 25;
}
#triangle {
color: $surface;
width: auto;
}
&.right {
align-horizontal: right;
}
}
"""
def __init__(self, message: Message):
super().__init__()
self.message = message
if self.message.sender != self.app.mesh_node:
self.notify("right side")
self.add_class("right")
def compose(self):
user_name = self.message.sender.name
if self.message.sender == self.app.mesh_node:
user_name += " (You)"
yield Static(f"[b u cyan]{user_name}[/]\n{self.message.content}", id="message-text")
yield Static("", id="triangle")
class ChatWindow(Vertical):
def compose(self):
with VerticalScroll():
pass
DEFAULT_CSS = """
ChatWindow {
#message-history {
padding: 1;
}
with HorizontalGroup():
yield Input(placeholder="Send a message")
yield Button("", flat=True)
#message-box {
margin-right: 2;
align: left middle;
#message-input {
margin: 1;
width: 90%;
}
#send-btn {
max-width: 10%;
margin: 1 0;
}
}
}
"""
def compose(self):
with VerticalScroll(id="message-history"):
fake = MeshNode(None, self.app)
fake.name = "billy"
yield MessageView(Message("hi!!!", fake))
yield MessageView(Message("hi!!!", fake))
yield MessageView(Message("hi!!!", self.app.mesh_node))
with HorizontalGroup(id="message-box"):
yield Input(placeholder="Send a message", id="message-input")
yield Button("", flat=True, id="send-btn")