mirror of
https://github.com/MeexReay/bRAC.git
synced 2025-09-13 23:47:39 +03:00
refactor: rustfmt
This commit is contained in:
parent
431736e967
commit
5e4957a1e4
@ -4,39 +4,33 @@ use std::time::{Duration, SystemTime};
|
||||
|
||||
use chrono::Local;
|
||||
|
||||
use libadwaita::gdk::{BUTTON_PRIMARY, BUTTON_SECONDARY};
|
||||
use libadwaita::gtk::{GestureLongPress, MenuButton, Popover};
|
||||
use libadwaita::{
|
||||
self as adw, Avatar, HeaderBar, ToolbarView
|
||||
};
|
||||
use adw::gdk::{Cursor, Display};
|
||||
use adw::gio::MemoryInputStream;
|
||||
use adw::glib::clone;
|
||||
use adw::glib::{
|
||||
self, source::timeout_add_local_once,
|
||||
timeout_add_local,
|
||||
ControlFlow,
|
||||
};
|
||||
use adw::glib::{self, source::timeout_add_local_once, timeout_add_local, ControlFlow};
|
||||
use adw::prelude::*;
|
||||
use adw::Application;
|
||||
use libadwaita::gdk::{BUTTON_PRIMARY, BUTTON_SECONDARY};
|
||||
use libadwaita::gtk::{GestureLongPress, MenuButton, Popover};
|
||||
use libadwaita::{self as adw, Avatar, HeaderBar, ToolbarView};
|
||||
|
||||
use adw::gtk;
|
||||
use gtk::gdk_pixbuf::PixbufAnimation;
|
||||
use gtk::pango::WrapMode;
|
||||
use gtk::{
|
||||
Align, Box as GtkBox, Button, Calendar, Entry, Fixed, GestureClick, Justification, Label, ListBox,
|
||||
Orientation, Overlay, Picture, ScrolledWindow,
|
||||
Align, Box as GtkBox, Button, Calendar, Entry, Fixed, GestureClick, Justification, Label,
|
||||
ListBox, Orientation, Overlay, Picture, ScrolledWindow,
|
||||
};
|
||||
|
||||
|
||||
use crate::chat::{
|
||||
config::get_config_path,
|
||||
ctx::Context,
|
||||
on_send_message, parse_message, SERVER_LIST,
|
||||
config::get_config_path, ctx::Context, on_send_message, parse_message, SERVER_LIST,
|
||||
};
|
||||
|
||||
use super::widgets::CustomLayout;
|
||||
use super::{add_chat_messages, build_menu, get_avatar_id, get_message_sign, load_pixbuf, send_notification, try_save_config, update_window_title, UiModel};
|
||||
use super::{
|
||||
add_chat_messages, build_menu, get_avatar_id, get_message_sign, load_pixbuf, send_notification,
|
||||
try_save_config, update_window_title, UiModel,
|
||||
};
|
||||
|
||||
pub fn get_message_box(
|
||||
ctx: Arc<Context>,
|
||||
@ -141,14 +135,17 @@ fn open_avatar_popup(avatar: String, avatar_picture: &Avatar) {
|
||||
|
||||
let button = Button::with_label("Copy Link");
|
||||
button.connect_clicked(clone!(
|
||||
#[weak] clipboard,
|
||||
#[weak] popover,
|
||||
#[strong] avatar,
|
||||
#[weak]
|
||||
clipboard,
|
||||
#[weak]
|
||||
popover,
|
||||
#[strong]
|
||||
avatar,
|
||||
move |_| {
|
||||
clipboard.set_text(avatar.as_str());
|
||||
popover.popdown();
|
||||
})
|
||||
);
|
||||
}
|
||||
));
|
||||
|
||||
let vbox = GtkBox::builder()
|
||||
.orientation(Orientation::Vertical)
|
||||
@ -166,7 +163,7 @@ pub fn get_new_message_box(
|
||||
ui: &UiModel,
|
||||
message: String,
|
||||
notify: bool,
|
||||
formatting_enabled: bool
|
||||
formatting_enabled: bool,
|
||||
) -> Overlay {
|
||||
// TODO: softcode these colors
|
||||
|
||||
@ -193,7 +190,7 @@ pub fn get_new_message_box(
|
||||
.map(|o| o.1.to_string())
|
||||
.unwrap_or("#DDDDDD".to_string()),
|
||||
avatar.clone(),
|
||||
avatar.map(|o| get_avatar_id(&o)).unwrap_or_default()
|
||||
avatar.map(|o| get_avatar_id(&o)).unwrap_or_default(),
|
||||
)
|
||||
} else {
|
||||
(
|
||||
@ -203,7 +200,7 @@ pub fn get_new_message_box(
|
||||
"System".to_string(),
|
||||
"#DDDDDD".to_string(),
|
||||
None,
|
||||
0
|
||||
0,
|
||||
)
|
||||
};
|
||||
|
||||
@ -246,13 +243,13 @@ pub fn get_new_message_box(
|
||||
avatar_picture.set_halign(Align::Start);
|
||||
|
||||
if let Some(avatar) = avatar {
|
||||
let long_gesture = GestureLongPress::builder()
|
||||
.button(BUTTON_PRIMARY)
|
||||
.build();
|
||||
let long_gesture = GestureLongPress::builder().button(BUTTON_PRIMARY).build();
|
||||
|
||||
long_gesture.connect_pressed(clone!(
|
||||
#[weak] avatar_picture,
|
||||
#[strong] avatar,
|
||||
#[weak]
|
||||
avatar_picture,
|
||||
#[strong]
|
||||
avatar,
|
||||
move |_, x, y| {
|
||||
if x < 32.0 && y > 4.0 && y < 32.0 {
|
||||
open_avatar_popup(avatar.clone(), &avatar_picture);
|
||||
@ -262,13 +259,13 @@ pub fn get_new_message_box(
|
||||
|
||||
overlay.add_controller(long_gesture);
|
||||
|
||||
let short_gesture = GestureClick::builder()
|
||||
.button(BUTTON_SECONDARY)
|
||||
.build();
|
||||
let short_gesture = GestureClick::builder().button(BUTTON_SECONDARY).build();
|
||||
|
||||
short_gesture.connect_released(clone!(
|
||||
#[weak] avatar_picture,
|
||||
#[strong] avatar,
|
||||
#[weak]
|
||||
avatar_picture,
|
||||
#[strong]
|
||||
avatar,
|
||||
move |_, _, x, y| {
|
||||
if x < 32.0 && y > 4.0 && y < 32.0 {
|
||||
open_avatar_popup(avatar.clone(), &avatar_picture);
|
||||
@ -313,18 +310,20 @@ pub fn get_new_message_box(
|
||||
.build());
|
||||
}
|
||||
|
||||
vbox.append(&Label::builder()
|
||||
.label(format!(
|
||||
"<span color=\"{text_color}\">{}</span>",
|
||||
glib::markup_escape_text(&content)
|
||||
))
|
||||
.halign(Align::Start)
|
||||
.hexpand(true)
|
||||
.selectable(true)
|
||||
.wrap(true)
|
||||
.wrap_mode(WrapMode::WordChar)
|
||||
.use_markup(true)
|
||||
.build());
|
||||
vbox.append(
|
||||
&Label::builder()
|
||||
.label(format!(
|
||||
"<span color=\"{text_color}\">{}</span>",
|
||||
glib::markup_escape_text(&content)
|
||||
))
|
||||
.halign(Align::Start)
|
||||
.hexpand(true)
|
||||
.selectable(true)
|
||||
.wrap(true)
|
||||
.wrap_mode(WrapMode::WordChar)
|
||||
.use_markup(true)
|
||||
.build(),
|
||||
);
|
||||
|
||||
vbox.set_margin_start(37);
|
||||
vbox.set_hexpand(true);
|
||||
@ -341,7 +340,10 @@ pub fn get_new_message_box(
|
||||
}
|
||||
|
||||
/// header, page_box, chat_box, chat_scrolled
|
||||
pub fn build_page(ctx: Arc<Context>, app: &Application) -> (HeaderBar, GtkBox, GtkBox, ScrolledWindow) {
|
||||
pub fn build_page(
|
||||
ctx: Arc<Context>,
|
||||
app: &Application,
|
||||
) -> (HeaderBar, GtkBox, GtkBox, ScrolledWindow) {
|
||||
let page_box = GtkBox::new(Orientation::Vertical, 5);
|
||||
page_box.set_css_classes(&["page-box"]);
|
||||
|
||||
@ -349,10 +351,12 @@ pub fn build_page(ctx: Arc<Context>, app: &Application) -> (HeaderBar, GtkBox, G
|
||||
|
||||
let header = HeaderBar::new();
|
||||
|
||||
header.pack_end(&MenuButton::builder()
|
||||
.icon_name("open-menu-symbolic")
|
||||
.menu_model(&build_menu(ctx.clone(), &app))
|
||||
.build());
|
||||
header.pack_end(
|
||||
&MenuButton::builder()
|
||||
.icon_name("open-menu-symbolic")
|
||||
.menu_model(&build_menu(ctx.clone(), &app))
|
||||
.build(),
|
||||
);
|
||||
|
||||
toolbar.set_content(Some(&header));
|
||||
|
||||
@ -379,7 +383,8 @@ pub fn build_page(ctx: Arc<Context>, app: &Application) -> (HeaderBar, GtkBox, G
|
||||
let chat_scrolled = chat_scrolled.downgrade();
|
||||
move |_| {
|
||||
if let Some(chat_scrolled) = chat_scrolled.upgrade() {
|
||||
let value = chat_scrolled.vadjustment().upper() - chat_scrolled.vadjustment().page_size();
|
||||
let value =
|
||||
chat_scrolled.vadjustment().upper() - chat_scrolled.vadjustment().page_size();
|
||||
chat_scrolled.vadjustment().set_value(value);
|
||||
}
|
||||
return None;
|
||||
@ -388,13 +393,18 @@ pub fn build_page(ctx: Arc<Context>, app: &Application) -> (HeaderBar, GtkBox, G
|
||||
|
||||
page_box.set_layout_manager(Some(layout));
|
||||
|
||||
timeout_add_local_once(Duration::ZERO, clone!(
|
||||
#[weak] chat_scrolled,
|
||||
move || {
|
||||
let value = chat_scrolled.vadjustment().upper() - chat_scrolled.vadjustment().page_size();
|
||||
chat_scrolled.vadjustment().set_value(value);
|
||||
}
|
||||
));
|
||||
timeout_add_local_once(
|
||||
Duration::ZERO,
|
||||
clone!(
|
||||
#[weak]
|
||||
chat_scrolled,
|
||||
move || {
|
||||
let value =
|
||||
chat_scrolled.vadjustment().upper() - chat_scrolled.vadjustment().page_size();
|
||||
chat_scrolled.vadjustment().set_value(value);
|
||||
}
|
||||
),
|
||||
);
|
||||
|
||||
page_box.append(&chat_scrolled);
|
||||
|
||||
@ -419,8 +429,10 @@ pub fn build_page(ctx: Arc<Context>, app: &Application) -> (HeaderBar, GtkBox, G
|
||||
.build();
|
||||
|
||||
send_btn.connect_clicked(clone!(
|
||||
#[weak] text_entry,
|
||||
#[weak] ctx,
|
||||
#[weak]
|
||||
text_entry,
|
||||
#[weak]
|
||||
ctx,
|
||||
move |_| {
|
||||
let text = text_entry.text().clone();
|
||||
|
||||
@ -444,8 +456,10 @@ pub fn build_page(ctx: Arc<Context>, app: &Application) -> (HeaderBar, GtkBox, G
|
||||
));
|
||||
|
||||
text_entry.connect_activate(clone!(
|
||||
#[weak] text_entry,
|
||||
#[weak] ctx,
|
||||
#[weak]
|
||||
text_entry,
|
||||
#[weak]
|
||||
ctx,
|
||||
move |_| {
|
||||
let text = text_entry.text().clone();
|
||||
|
||||
@ -505,7 +519,8 @@ fn build_widget_box(ctx: Arc<Context>, _app: &Application) -> Overlay {
|
||||
let click = GestureClick::new();
|
||||
|
||||
click.connect_pressed(clone!(
|
||||
#[weak] ctx,
|
||||
#[weak]
|
||||
ctx,
|
||||
move |_, _, _, _| {
|
||||
let mut config = ctx.config.read().unwrap().clone();
|
||||
config.host = url.clone();
|
||||
@ -601,4 +616,3 @@ fn build_widget_box(ctx: Arc<Context>, _app: &Application) -> Overlay {
|
||||
|
||||
widget_box_overlay
|
||||
}
|
||||
|
||||
|
@ -1,11 +1,11 @@
|
||||
use libadwaita::{glib, gtk};
|
||||
|
||||
use glib::object::ObjectExt;
|
||||
use gtk::{subclass::prelude::*, prelude::LayoutManagerExt, BoxLayout};
|
||||
use gtk::{prelude::LayoutManagerExt, subclass::prelude::*, BoxLayout};
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct CustomLayout {
|
||||
box_layout: BoxLayout
|
||||
box_layout: BoxLayout,
|
||||
}
|
||||
|
||||
impl Default for CustomLayout {
|
||||
@ -14,7 +14,7 @@ impl Default for CustomLayout {
|
||||
box_layout: BoxLayout::builder()
|
||||
.orientation(gtk::Orientation::Vertical)
|
||||
.spacing(5)
|
||||
.build()
|
||||
.build(),
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -32,9 +32,7 @@ impl ObjectImpl for CustomLayout {
|
||||
|
||||
static SIGNALS: OnceLock<Vec<glib::subclass::Signal>> = OnceLock::new();
|
||||
|
||||
SIGNALS.get_or_init(|| {
|
||||
vec![glib::subclass::Signal::builder("size-changed").build()]
|
||||
})
|
||||
SIGNALS.get_or_init(|| vec![glib::subclass::Signal::builder("size-changed").build()])
|
||||
}
|
||||
}
|
||||
impl LayoutManagerImpl for CustomLayout {
|
||||
@ -43,11 +41,11 @@ impl LayoutManagerImpl for CustomLayout {
|
||||
self.box_layout.allocate(widget, width, height, baseline)
|
||||
}
|
||||
fn measure(
|
||||
&self,
|
||||
widget: >k::Widget,
|
||||
orientation: gtk::Orientation,
|
||||
for_size: i32,
|
||||
) -> (i32, i32, i32, i32) {
|
||||
&self,
|
||||
widget: >k::Widget,
|
||||
orientation: gtk::Orientation,
|
||||
for_size: i32,
|
||||
) -> (i32, i32, i32, i32) {
|
||||
self.box_layout.measure(widget, orientation, for_size)
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
mod imp;
|
||||
|
||||
use libadwaita::gtk::glib;
|
||||
use libadwaita::gtk;
|
||||
use libadwaita::gtk::glib;
|
||||
|
||||
glib::wrapper! {
|
||||
pub struct CustomLayout(ObjectSubclass<imp::CustomLayout>)
|
||||
|
Loading…
x
Reference in New Issue
Block a user