Render the chat element #34
|
@ -0,0 +1,50 @@
|
||||||
|
use glib::Object;
|
||||||
|
use gtk::{prelude::*, subclass::prelude::*};
|
||||||
|
use kifu_core::ui::ChatElement;
|
||||||
|
|
||||||
|
#[derive(Default)]
|
||||||
|
pub struct ChatPrivate {
|
||||||
|
chat_history: gtk::Box,
|
||||||
|
entry: gtk::Entry,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[glib::object_subclass]
|
||||||
|
impl ObjectSubclass for ChatPrivate {
|
||||||
|
const NAME: &'static str = "Chat";
|
||||||
|
type Type = Chat;
|
||||||
|
type ParentType = gtk::Box;
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ObjectImpl for ChatPrivate {
|
||||||
|
fn constructed(&self) {
|
||||||
|
self.chat_history
|
||||||
|
.set_orientation(gtk::Orientation::Vertical);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
impl WidgetImpl for ChatPrivate {}
|
||||||
|
impl BoxImpl for ChatPrivate {}
|
||||||
|
|
||||||
|
glib::wrapper! {
|
||||||
|
pub struct Chat(ObjectSubclass<ChatPrivate>) @extends gtk::Box, gtk::Widget, @implements gtk::Orientable;
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Chat {
|
||||||
|
pub fn new(element: ChatElement) -> Chat {
|
||||||
|
let s: Self = Object::builder().build();
|
||||||
|
s.set_orientation(gtk::Orientation::Vertical);
|
||||||
|
|
||||||
|
s.append(&s.imp().chat_history);
|
||||||
|
s.append(&s.imp().entry);
|
||||||
|
|
||||||
|
element.messages.into_iter().for_each(|msg| {
|
||||||
|
s.imp().chat_history.append(
|
||||||
|
>k::Label::builder()
|
||||||
|
.label(&msg)
|
||||||
|
.halign(gtk::Align::Start)
|
||||||
|
.build(),
|
||||||
|
)
|
||||||
|
});
|
||||||
|
|
||||||
|
s
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,88 +1,5 @@
|
||||||
use crate::ui;
|
mod player_card;
|
||||||
use glib::Object;
|
pub use player_card::PlayerCard;
|
||||||
use gtk::{prelude::*, subclass::prelude::*};
|
|
||||||
use kifu_core::{ui::ChatElement, ui::PlayerCardElement, Color};
|
|
||||||
use std::{cell::RefCell, rc::Rc};
|
|
||||||
|
|
||||||
#[derive(Default)]
|
mod chat;
|
||||||
pub struct PlayerCardPrivate {
|
pub use chat::Chat;
|
||||||
player_name: gtk::Label,
|
|
||||||
clock: gtk::Label,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[glib::object_subclass]
|
|
||||||
impl ObjectSubclass for PlayerCardPrivate {
|
|
||||||
const NAME: &'static str = "PlayerCard";
|
|
||||||
type Type = PlayerCard;
|
|
||||||
type ParentType = gtk::Box;
|
|
||||||
}
|
|
||||||
|
|
||||||
impl ObjectImpl for PlayerCardPrivate {}
|
|
||||||
impl WidgetImpl for PlayerCardPrivate {}
|
|
||||||
impl BoxImpl for PlayerCardPrivate {}
|
|
||||||
|
|
||||||
glib::wrapper! {
|
|
||||||
pub struct PlayerCard(ObjectSubclass<PlayerCardPrivate>) @extends gtk::Box, gtk::Widget, @implements gtk::Orientable;
|
|
||||||
}
|
|
||||||
|
|
||||||
impl PlayerCard {
|
|
||||||
pub fn new(element: PlayerCardElement) -> PlayerCard {
|
|
||||||
let s: Self = Object::builder().build();
|
|
||||||
s.set_orientation(gtk::Orientation::Vertical);
|
|
||||||
s.imp()
|
|
||||||
.player_name
|
|
||||||
.set_text(&format!("{} ({})", element.name, element.rank));
|
|
||||||
s.imp().clock.set_text(&element.clock);
|
|
||||||
|
|
||||||
s.append(&s.imp().player_name);
|
|
||||||
s.append(&s.imp().clock);
|
|
||||||
s
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Default)]
|
|
||||||
pub struct ChatPrivate {
|
|
||||||
chat_history: gtk::Box,
|
|
||||||
entry: gtk::Entry,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[glib::object_subclass]
|
|
||||||
impl ObjectSubclass for ChatPrivate {
|
|
||||||
const NAME: &'static str = "Chat";
|
|
||||||
type Type = Chat;
|
|
||||||
type ParentType = gtk::Box;
|
|
||||||
}
|
|
||||||
|
|
||||||
impl ObjectImpl for ChatPrivate {
|
|
||||||
fn constructed(&self) {
|
|
||||||
self.chat_history
|
|
||||||
.set_orientation(gtk::Orientation::Vertical);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
impl WidgetImpl for ChatPrivate {}
|
|
||||||
impl BoxImpl for ChatPrivate {}
|
|
||||||
|
|
||||||
glib::wrapper! {
|
|
||||||
pub struct Chat(ObjectSubclass<ChatPrivate>) @extends gtk::Box, gtk::Widget, @implements gtk::Orientable;
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Chat {
|
|
||||||
pub fn new(element: ChatElement) -> Chat {
|
|
||||||
let s: Self = Object::builder().build();
|
|
||||||
s.set_orientation(gtk::Orientation::Vertical);
|
|
||||||
|
|
||||||
s.append(&s.imp().chat_history);
|
|
||||||
s.append(&s.imp().entry);
|
|
||||||
|
|
||||||
element.messages.into_iter().for_each(|msg| {
|
|
||||||
s.imp().chat_history.append(
|
|
||||||
>k::Label::builder()
|
|
||||||
.label(&msg)
|
|
||||||
.halign(gtk::Align::Start)
|
|
||||||
.build(),
|
|
||||||
)
|
|
||||||
});
|
|
||||||
|
|
||||||
s
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -0,0 +1,39 @@
|
||||||
|
use glib::Object;
|
||||||
|
use gtk::{prelude::*, subclass::prelude::*};
|
||||||
|
use kifu_core::{ui::PlayerCardElement, Color};
|
||||||
|
|
||||||
|
#[derive(Default)]
|
||||||
|
pub struct PlayerCardPrivate {
|
||||||
|
player_name: gtk::Label,
|
||||||
|
clock: gtk::Label,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[glib::object_subclass]
|
||||||
|
impl ObjectSubclass for PlayerCardPrivate {
|
||||||
|
const NAME: &'static str = "PlayerCard";
|
||||||
|
type Type = PlayerCard;
|
||||||
|
type ParentType = gtk::Box;
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ObjectImpl for PlayerCardPrivate {}
|
||||||
|
impl WidgetImpl for PlayerCardPrivate {}
|
||||||
|
impl BoxImpl for PlayerCardPrivate {}
|
||||||
|
|
||||||
|
glib::wrapper! {
|
||||||
|
pub struct PlayerCard(ObjectSubclass<PlayerCardPrivate>) @extends gtk::Box, gtk::Widget, @implements gtk::Orientable;
|
||||||
|
}
|
||||||
|
|
||||||
|
impl PlayerCard {
|
||||||
|
pub fn new(element: PlayerCardElement) -> PlayerCard {
|
||||||
|
let s: Self = Object::builder().build();
|
||||||
|
s.set_orientation(gtk::Orientation::Vertical);
|
||||||
|
s.imp()
|
||||||
|
.player_name
|
||||||
|
.set_text(&format!("{} ({})", element.name, element.rank));
|
||||||
|
s.imp().clock.set_text(&element.clock);
|
||||||
|
|
||||||
|
s.append(&s.imp().player_name);
|
||||||
|
s.append(&s.imp().clock);
|
||||||
|
s
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue