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::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<Context>, app: &Application) -> 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 {
|
||||
let is_dark_theme = if let Some(settings) = Settings::default() {
|
||||
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 header = HeaderBar::new();
|
||||
let title = format!(
|
||||
"bRAC - Connected to {} as {}",
|
||||
ctx.config(|o| o.host.clone()),
|
||||
&ctx.name()
|
||||
);
|
||||
|
||||
header.pack_end(&MenuButton::builder()
|
||||
.icon_name("open-menu-symbolic")
|
||||
.menu_model(&build_menu(ctx.clone(), &app))
|
||||
.build());
|
||||
let (page, chat_box, chat_scrolled) = build_page(ctx.clone(), app, &title);
|
||||
|
||||
main_box.append(&header);
|
||||
let sidebar = build_sidebar(ctx.clone(), &app);
|
||||
|
||||
let (page_box, chat_box, chat_scrolled) = build_page_box(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<Context>, 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
|
||||
)
|
||||
);
|
||||
|
||||
// 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);
|
||||
// }
|
||||
// ));
|
||||
// }
|
||||
// ));
|
||||
breakpoint.add_setter(&split_view, "collapsed", Some(&true.into()));
|
||||
|
||||
window.add_breakpoint(breakpoint);
|
||||
|
||||
window.present();
|
||||
|
||||
|
@ -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<Context>,
|
||||
@ -341,10 +341,23 @@ pub fn get_new_message_box(
|
||||
}
|
||||
|
||||
/// 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);
|
||||
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));
|
||||
|
||||
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, 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 {
|
||||
|
Loading…
x
Reference in New Issue
Block a user