diff --git a/src/chat/gui/mod.rs b/src/chat/gui/mod.rs index 4cefa94..46ce6ce 100644 --- a/src/chat/gui/mod.rs +++ b/src/chat/gui/mod.rs @@ -14,9 +14,9 @@ use clap::crate_version; use libadwaita::gdk::Texture; use libadwaita::gtk::gdk_pixbuf::InterpType; -use libadwaita::gtk::MenuButton; +use libadwaita::gtk::Label; use libadwaita::{ - self as adw, Avatar, HeaderBar + self as adw, Avatar, Breakpoint, BreakpointCondition, NavigationPage, NavigationSplitView }; use adw::gdk::Display; use adw::gio::{ActionEntry, ApplicationFlags, Menu}; @@ -163,6 +163,19 @@ fn build_menu(ctx: Arc, app: &Application) -> Menu { menu } +fn build_sidebar(_ctx: Arc, _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, app: &Application) -> UiModel { let is_dark_theme = if let Some(settings) = Settings::default() { settings.is_gtk_application_prefer_dark_theme() @@ -178,27 +191,28 @@ fn build_ui(ctx: Arc, app: &Application) -> UiModel { let is_dark_theme = true; let main_box = GtkBox::new(Orientation::Vertical, 0); - - let header = HeaderBar::new(); - header.pack_end(&MenuButton::builder() - .icon_name("open-menu-symbolic") - .menu_model(&build_menu(ctx.clone(), &app)) - .build()); - - main_box.append(&header); + let title = format!( + "bRAC - Connected to {} as {}", + ctx.config(|o| o.host.clone()), + &ctx.name() + ); - let (page_box, chat_box, chat_scrolled) = build_page_box(ctx.clone(), app); + 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(&page_box); + main_box.append(&split_view); let window = ApplicationWindow::builder() .application(app) - .title(format!( - "bRAC - Connected to {} as {}", - ctx.config(|o| o.host.clone()), - &ctx.name() - )) + .title(&title) .default_width(500) .default_height(500) .resizable(true) @@ -206,31 +220,17 @@ fn build_ui(ctx: Arc, app: &Application) -> UiModel { .content(&main_box) .build(); - // window.connect_default_width_notify(clone!( - // #[weak] chat_scrolled, - // move |_| { - // 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); - // } - // )); - // } - // )); + let breakpoint = Breakpoint::new( + BreakpointCondition::new_length( + libadwaita::BreakpointConditionLengthType::MaxWidth, + 700.0, + libadwaita::LengthUnit::Px + ) + ); + + breakpoint.add_setter(&split_view, "collapsed", Some(&true.into())); - // window.connect_default_height_notify(clone!( - // #[weak] chat_scrolled, - // move |_| { - // 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.add_breakpoint(breakpoint); window.present(); diff --git a/src/chat/gui/page.rs b/src/chat/gui/page.rs index 269e627..3986699 100644 --- a/src/chat/gui/page.rs +++ b/src/chat/gui/page.rs @@ -5,9 +5,9 @@ use std::time::{Duration, SystemTime}; use chrono::Local; use libadwaita::gdk::{BUTTON_PRIMARY, BUTTON_SECONDARY}; -use libadwaita::gtk::{GestureLongPress, Popover}; +use libadwaita::gtk::{GestureLongPress, MenuButton, Popover}; use libadwaita::{ - self as adw, Avatar + self as adw, Avatar, HeaderBar, NavigationPage, ToolbarView }; use adw::gdk::{Cursor, Display}; use adw::gio::MemoryInputStream; @@ -36,7 +36,7 @@ use crate::chat::{ }; 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( ctx: Arc, @@ -341,9 +341,22 @@ pub fn get_new_message_box( } /// page_box, chat_box, chat_scrolled -pub fn build_page_box(ctx: Arc, app: &Application) -> (GtkBox, GtkBox, ScrolledWindow) { +pub fn build_page(ctx: Arc, app: &Application, title: &str) -> (NavigationPage, GtkBox, ScrolledWindow) { let page_box = GtkBox::new(Orientation::Vertical, 5); 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)); @@ -458,8 +471,10 @@ pub fn build_page_box(ctx: Arc, app: &Application) -> (GtkBox, GtkBox, send_box.append(&send_btn); page_box.append(&send_box); + + let page = NavigationPage::new(&page_box, title); - (page_box, chat_box, chat_scrolled) + (page, chat_box, chat_scrolled) } fn build_widget_box(ctx: Arc, _app: &Application) -> Overlay {