mirror of
https://github.com/MeexReay/bRAC.git
synced 2025-09-13 23:47:39 +03:00
refactor: add sidebar with hello world
This commit is contained in:
parent
eb1c585ecb
commit
da657875a1
@ -14,9 +14,9 @@ use clap::crate_version;
|
|||||||
|
|
||||||
use libadwaita::gdk::Texture;
|
use libadwaita::gdk::Texture;
|
||||||
use libadwaita::gtk::gdk_pixbuf::InterpType;
|
use libadwaita::gtk::gdk_pixbuf::InterpType;
|
||||||
use libadwaita::gtk::MenuButton;
|
use libadwaita::gtk::Label;
|
||||||
use libadwaita::{
|
use libadwaita::{
|
||||||
self as adw, Avatar, HeaderBar
|
self as adw, Avatar, Breakpoint, BreakpointCondition, NavigationPage, NavigationSplitView
|
||||||
};
|
};
|
||||||
use adw::gdk::Display;
|
use adw::gdk::Display;
|
||||||
use adw::gio::{ActionEntry, ApplicationFlags, Menu};
|
use adw::gio::{ActionEntry, ApplicationFlags, Menu};
|
||||||
@ -163,6 +163,19 @@ fn build_menu(ctx: Arc<Context>, app: &Application) -> Menu {
|
|||||||
menu
|
menu
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn build_sidebar(_ctx: Arc<Context>, _app: &Application) -> NavigationPage {
|
||||||
|
let sidebar = GtkBox::new(Orientation::Vertical, 0);
|
||||||
|
|
||||||
|
sidebar.append(&Label::new(Some("hello worlding")));
|
||||||
|
|
||||||
|
let page = NavigationPage::builder()
|
||||||
|
.child(&sidebar)
|
||||||
|
.title("sidebar")
|
||||||
|
.build();
|
||||||
|
|
||||||
|
page
|
||||||
|
}
|
||||||
|
|
||||||
fn build_ui(ctx: Arc<Context>, app: &Application) -> UiModel {
|
fn build_ui(ctx: Arc<Context>, app: &Application) -> UiModel {
|
||||||
let is_dark_theme = if let Some(settings) = Settings::default() {
|
let is_dark_theme = if let Some(settings) = Settings::default() {
|
||||||
settings.is_gtk_application_prefer_dark_theme()
|
settings.is_gtk_application_prefer_dark_theme()
|
||||||
@ -179,26 +192,27 @@ fn build_ui(ctx: Arc<Context>, app: &Application) -> UiModel {
|
|||||||
|
|
||||||
let main_box = GtkBox::new(Orientation::Vertical, 0);
|
let main_box = GtkBox::new(Orientation::Vertical, 0);
|
||||||
|
|
||||||
let header = HeaderBar::new();
|
let title = format!(
|
||||||
|
|
||||||
header.pack_end(&MenuButton::builder()
|
|
||||||
.icon_name("open-menu-symbolic")
|
|
||||||
.menu_model(&build_menu(ctx.clone(), &app))
|
|
||||||
.build());
|
|
||||||
|
|
||||||
main_box.append(&header);
|
|
||||||
|
|
||||||
let (page_box, chat_box, chat_scrolled) = build_page_box(ctx.clone(), app);
|
|
||||||
|
|
||||||
main_box.append(&page_box);
|
|
||||||
|
|
||||||
let window = ApplicationWindow::builder()
|
|
||||||
.application(app)
|
|
||||||
.title(format!(
|
|
||||||
"bRAC - Connected to {} as {}",
|
"bRAC - Connected to {} as {}",
|
||||||
ctx.config(|o| o.host.clone()),
|
ctx.config(|o| o.host.clone()),
|
||||||
&ctx.name()
|
&ctx.name()
|
||||||
))
|
);
|
||||||
|
|
||||||
|
let (page, chat_box, chat_scrolled) = build_page(ctx.clone(), app, &title);
|
||||||
|
|
||||||
|
let sidebar = build_sidebar(ctx.clone(), &app);
|
||||||
|
|
||||||
|
let split_view = NavigationSplitView::builder()
|
||||||
|
.sidebar(&sidebar)
|
||||||
|
.content(&page)
|
||||||
|
.show_content(true)
|
||||||
|
.build();
|
||||||
|
|
||||||
|
main_box.append(&split_view);
|
||||||
|
|
||||||
|
let window = ApplicationWindow::builder()
|
||||||
|
.application(app)
|
||||||
|
.title(&title)
|
||||||
.default_width(500)
|
.default_width(500)
|
||||||
.default_height(500)
|
.default_height(500)
|
||||||
.resizable(true)
|
.resizable(true)
|
||||||
@ -206,31 +220,17 @@ fn build_ui(ctx: Arc<Context>, app: &Application) -> UiModel {
|
|||||||
.content(&main_box)
|
.content(&main_box)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
// window.connect_default_width_notify(clone!(
|
let breakpoint = Breakpoint::new(
|
||||||
// #[weak] chat_scrolled,
|
BreakpointCondition::new_length(
|
||||||
// move |_| {
|
libadwaita::BreakpointConditionLengthType::MaxWidth,
|
||||||
// timeout_add_local_once(Duration::ZERO, clone!(
|
700.0,
|
||||||
// #[weak] chat_scrolled,
|
libadwaita::LengthUnit::Px
|
||||||
// move || {
|
)
|
||||||
// let value = chat_scrolled.vadjustment().upper() - chat_scrolled.vadjustment().page_size();
|
);
|
||||||
// chat_scrolled.vadjustment().set_value(value);
|
|
||||||
// }
|
|
||||||
// ));
|
|
||||||
// }
|
|
||||||
// ));
|
|
||||||
|
|
||||||
// window.connect_default_height_notify(clone!(
|
breakpoint.add_setter(&split_view, "collapsed", Some(&true.into()));
|
||||||
// #[weak] chat_scrolled,
|
|
||||||
// move |_| {
|
window.add_breakpoint(breakpoint);
|
||||||
// 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);
|
|
||||||
// }
|
|
||||||
// ));
|
|
||||||
// }
|
|
||||||
// ));
|
|
||||||
|
|
||||||
window.present();
|
window.present();
|
||||||
|
|
||||||
|
@ -5,9 +5,9 @@ use std::time::{Duration, SystemTime};
|
|||||||
use chrono::Local;
|
use chrono::Local;
|
||||||
|
|
||||||
use libadwaita::gdk::{BUTTON_PRIMARY, BUTTON_SECONDARY};
|
use libadwaita::gdk::{BUTTON_PRIMARY, BUTTON_SECONDARY};
|
||||||
use libadwaita::gtk::{GestureLongPress, Popover};
|
use libadwaita::gtk::{GestureLongPress, MenuButton, Popover};
|
||||||
use libadwaita::{
|
use libadwaita::{
|
||||||
self as adw, Avatar
|
self as adw, Avatar, HeaderBar, NavigationPage, ToolbarView
|
||||||
};
|
};
|
||||||
use adw::gdk::{Cursor, Display};
|
use adw::gdk::{Cursor, Display};
|
||||||
use adw::gio::MemoryInputStream;
|
use adw::gio::MemoryInputStream;
|
||||||
@ -36,7 +36,7 @@ use crate::chat::{
|
|||||||
};
|
};
|
||||||
|
|
||||||
use super::widgets::CustomLayout;
|
use super::widgets::CustomLayout;
|
||||||
use super::{add_chat_messages, 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(
|
pub fn get_message_box(
|
||||||
ctx: Arc<Context>,
|
ctx: Arc<Context>,
|
||||||
@ -341,10 +341,23 @@ pub fn get_new_message_box(
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// page_box, chat_box, chat_scrolled
|
/// page_box, chat_box, chat_scrolled
|
||||||
pub fn build_page_box(ctx: Arc<Context>, app: &Application) -> (GtkBox, GtkBox, ScrolledWindow) {
|
pub fn build_page(ctx: Arc<Context>, app: &Application, title: &str) -> (NavigationPage, GtkBox, ScrolledWindow) {
|
||||||
let page_box = GtkBox::new(Orientation::Vertical, 5);
|
let page_box = GtkBox::new(Orientation::Vertical, 5);
|
||||||
page_box.set_css_classes(&["page-box"]);
|
page_box.set_css_classes(&["page-box"]);
|
||||||
|
|
||||||
|
let toolbar = ToolbarView::new();
|
||||||
|
|
||||||
|
let header = HeaderBar::new();
|
||||||
|
|
||||||
|
header.pack_end(&MenuButton::builder()
|
||||||
|
.icon_name("open-menu-symbolic")
|
||||||
|
.menu_model(&build_menu(ctx.clone(), &app))
|
||||||
|
.build());
|
||||||
|
|
||||||
|
toolbar.set_content(Some(&header));
|
||||||
|
|
||||||
|
page_box.append(&toolbar);
|
||||||
|
|
||||||
page_box.append(&build_widget_box(ctx.clone(), app));
|
page_box.append(&build_widget_box(ctx.clone(), app));
|
||||||
|
|
||||||
let chat_box = GtkBox::new(Orientation::Vertical, 2);
|
let chat_box = GtkBox::new(Orientation::Vertical, 2);
|
||||||
@ -459,7 +472,9 @@ pub fn build_page_box(ctx: Arc<Context>, app: &Application) -> (GtkBox, GtkBox,
|
|||||||
|
|
||||||
page_box.append(&send_box);
|
page_box.append(&send_box);
|
||||||
|
|
||||||
(page_box, chat_box, chat_scrolled)
|
let page = NavigationPage::new(&page_box, title);
|
||||||
|
|
||||||
|
(page, chat_box, chat_scrolled)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn build_widget_box(ctx: Arc<Context>, _app: &Application) -> Overlay {
|
fn build_widget_box(ctx: Arc<Context>, _app: &Application) -> Overlay {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user