added dynamic server list

pull/3/head
Lorenzo Torres 2022-03-24 11:23:34 +01:00
parent e094bbf00c
commit fd2fcc3330
6 changed files with 121 additions and 28 deletions

View File

@ -4,5 +4,6 @@
<!-- see https://gtk-rs.org/gtk4-rs/git/docs/gtk4/struct.Application.html#automatic-resources -->
<file compressed="true" preprocess="xml-stripblanks" alias="gtk/help-overlay.ui">ui/shortcuts.ui</file>
<file compressed="true" preprocess="xml-stripblanks">ui/window.ui</file>
<file compressed="true" preprocess="xml-stripblanks">ui/server_entry.ui</file>
</gresource>
</gresources>

View File

@ -0,0 +1,35 @@
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<template class="ServerEntry" parent="GtkListBoxRow">
<child>
<object class="GtkBox">
<property name="margin-start">10</property>
<property name="margin-end">0</property>
<property name="margin-top">12</property>
<property name="margin-bottom">12</property>
<property name="spacing">12</property>
<child>
<object class="AdwAvatar">
<property name="halign">start</property>
<property name="text">among us</property>
<property name="size">24</property>
<property name="show-initials">true</property>
</object>
</child>
<child>
<object class="GtkLabel">
<property name="hexpand">False</property>
<property name="label" translatable="yes">Among Us</property>
<property name="ellipsize">end</property>
</object>
</child>
<child>
<object class="GtkImage">
<property name="halign">end</property>
<property name="icon_name">go-next-symbolic</property>
</object>
</child>
</object>
</child>
</template>
</interface>

View File

@ -37,6 +37,13 @@
<object class="GtkBox" id="title_box">
<property name="orientation">horizontal</property>
<property name="spacing">6</property>
<child>
<object class="AdwAvatar">
<property name="text">among us</property>
<property name="size">24</property>
<property name="show-initials">true</property>
</object>
</child>
<child>
<object class="AdwWindowTitle" id="sidebar_title_widget">
<property name="title" translatable="yes">Mutiny</property>
@ -54,36 +61,14 @@
</child>
<child>
<object class="GtkListBox">
<object class="GtkScrolledWindow">
<property name="width-request">300</property>
<property name="hscrollbar-policy">never</property>
<property name="vexpand">true</property>
<child>
<object class="GtkListBoxRow">
<object class="GtkListBox" id="server_list">
<child>
<object class="GtkBox">
<property name="margin-start">24</property>
<property name="margin-end">24</property>
<property name="margin-top">12</property>
<property name="margin-bottom">12</property>
<property name="spacing">12</property>
<child>
<object class="AdwAvatar">
<property name="text">among us</property>
<property name="size">24</property>
<property name="show-initials">true</property>
</object>
</child>
<child>
<object class="GtkLabel">
<property name="hexpand">True</property>
<property name="label" translatable="yes">Among Us</property>
<property name="xalign">0</property>
</object>
</child>
<child>
<object class="GtkImage">
<property name="icon_name">go-next-symbolic</property>
</object>
</child>
</object>
<object class="ServerEntry"></object>
</child>
</object>
</child>

View File

@ -2,6 +2,7 @@ mod application;
#[rustfmt::skip]
mod config;
mod window;
mod server_entry;
use gettextrs::{gettext, LocaleCategory};
use gtk::{gio, glib};

59
src/server_entry.rs Normal file
View File

@ -0,0 +1,59 @@
use adw::subclass::prelude::*;
use gtk::prelude::*;
use gtk::subclass::prelude::*;
use gtk::glib;
mod imp {
use super::*;
use gtk::CompositeTemplate;
#[derive(Debug, CompositeTemplate)]
#[template(resource="/chat/revolt/Mutiny/ui/server_entry.ui")]
pub struct ServerEntry {
}
impl Default for ServerEntry {
fn default() -> Self {
Self { }
}
}
#[glib::object_subclass]
impl ObjectSubclass for ServerEntry {
const NAME: &'static str = "ServerEntry";
type Type = super::ServerEntry;
type ParentType = gtk::ListBoxRow;
fn class_init(klass: &mut Self::Class) {
klass.bind_template();
}
fn instance_init(obj: &glib::subclass::InitializingObject<Self>) {
obj.init_template();
}
}
impl ObjectImpl for ServerEntry {
fn constructed(&self, obj: &Self::Type) {
self.parent_constructed(obj);
}
}
impl WidgetImpl for ServerEntry {}
impl ListBoxRowImpl for ServerEntry {}
}
glib::wrapper! {
pub struct ServerEntry(ObjectSubclass<imp::ServerEntry>)
@extends gtk::Widget, gtk::ListBoxRow,
@implements gtk::Accessible, gtk::Buildable, gtk::ConstraintTarget;
}
impl ServerEntry {
pub fn new() -> Self {
glib::Object::new(&[]).expect("Failed to create ServerEntry")
}
}

View File

@ -7,6 +7,8 @@ use crate::application::MutinyApp;
use crate::config::{APP_ID, PROFILE};
mod imp {
use crate::server_entry::ServerEntry;
use super::*;
use gtk::CompositeTemplate;
@ -16,6 +18,8 @@ mod imp {
pub struct MutinyAppWindow {
// #[template_child]
// pub headerbar: TemplateChild<adw::HeaderBar>,
#[template_child]
pub server_list: TemplateChild<gtk::ListBox>,
pub settings: gio::Settings,
}
@ -23,6 +27,7 @@ mod imp {
fn default() -> Self {
Self {
// headerbar: TemplateChild::default(),
server_list: TemplateChild::default(),
settings: gio::Settings::new(APP_ID),
}
}
@ -35,6 +40,8 @@ mod imp {
type ParentType = adw::ApplicationWindow;
fn class_init(klass: &mut Self::Class) {
ServerEntry::ensure_type();
Self::bind_template(klass);
}
@ -55,6 +62,11 @@ mod imp {
// Load latest window state
obj.load_window_size();
for _ in 0..100 {
self.server_list.append(&ServerEntry::new());
}
}
}