mirror of
https://github.com/MeexReay/bRAC.git
synced 2025-09-13 23:47:39 +03:00
refactor: improve sidebar
This commit is contained in:
parent
ce4e5e40b3
commit
02c4862178
@ -14,9 +14,9 @@ use clap::crate_version;
|
||||
|
||||
use libadwaita::gdk::Texture;
|
||||
use libadwaita::gtk::gdk_pixbuf::InterpType;
|
||||
use libadwaita::gtk::Label;
|
||||
use libadwaita::gtk::{Button, Label};
|
||||
use libadwaita::{
|
||||
self as adw, Avatar, Breakpoint, BreakpointCondition, NavigationPage, NavigationSplitView
|
||||
self as adw, Avatar, Breakpoint, BreakpointCondition, OverlaySplitView
|
||||
};
|
||||
use adw::gdk::Display;
|
||||
use adw::gio::{ActionEntry, ApplicationFlags, Menu};
|
||||
@ -163,17 +163,10 @@ fn build_menu(ctx: Arc<Context>, app: &Application) -> Menu {
|
||||
menu
|
||||
}
|
||||
|
||||
fn build_sidebar(_ctx: Arc<Context>, _app: &Application) -> NavigationPage {
|
||||
fn build_sidebar(_ctx: Arc<Context>, _app: &Application) -> GtkBox {
|
||||
let sidebar = GtkBox::new(Orientation::Vertical, 0);
|
||||
|
||||
sidebar.append(&Label::new(Some("hello worlding")));
|
||||
|
||||
let page = NavigationPage::builder()
|
||||
.child(&sidebar)
|
||||
.title("sidebar")
|
||||
.build();
|
||||
|
||||
page
|
||||
sidebar
|
||||
}
|
||||
|
||||
fn build_ui(ctx: Arc<Context>, app: &Application) -> UiModel {
|
||||
@ -198,18 +191,31 @@ fn build_ui(ctx: Arc<Context>, app: &Application) -> UiModel {
|
||||
&ctx.name()
|
||||
);
|
||||
|
||||
let (page, chat_box, chat_scrolled) = build_page(ctx.clone(), app, &title);
|
||||
let (header, page, chat_box, chat_scrolled) = build_page(ctx.clone(), app);
|
||||
|
||||
let sidebar = build_sidebar(ctx.clone(), &app);
|
||||
|
||||
let split_view = NavigationSplitView::builder()
|
||||
let split_view = OverlaySplitView::builder()
|
||||
.sidebar(&sidebar)
|
||||
.content(&page)
|
||||
.show_content(true)
|
||||
.enable_hide_gesture(true)
|
||||
.enable_show_gesture(true)
|
||||
.collapsed(true)
|
||||
.build();
|
||||
|
||||
main_box.append(&split_view);
|
||||
|
||||
let toggle_button = Button::from_icon_name("go-previous-symbolic");
|
||||
|
||||
toggle_button.connect_clicked(clone!(
|
||||
#[weak] split_view,
|
||||
move |_| {
|
||||
split_view.set_show_sidebar(!split_view.shows_sidebar());
|
||||
}
|
||||
));
|
||||
|
||||
header.pack_start(&toggle_button);
|
||||
|
||||
let window = ApplicationWindow::builder()
|
||||
.application(app)
|
||||
.title(&title)
|
||||
@ -222,13 +228,14 @@ fn build_ui(ctx: Arc<Context>, app: &Application) -> UiModel {
|
||||
|
||||
let breakpoint = Breakpoint::new(
|
||||
BreakpointCondition::new_length(
|
||||
libadwaita::BreakpointConditionLengthType::MaxWidth,
|
||||
libadwaita::BreakpointConditionLengthType::MinWidth,
|
||||
700.0,
|
||||
libadwaita::LengthUnit::Px
|
||||
)
|
||||
);
|
||||
|
||||
breakpoint.add_setter(&split_view, "collapsed", Some(&true.into()));
|
||||
breakpoint.add_setter(&split_view, "collapsed", Some(&false.into()));
|
||||
breakpoint.add_setter(&toggle_button, "visible", Some(&false.into()));
|
||||
|
||||
window.add_breakpoint(breakpoint);
|
||||
|
||||
|
@ -7,7 +7,7 @@ use chrono::Local;
|
||||
use libadwaita::gdk::{BUTTON_PRIMARY, BUTTON_SECONDARY};
|
||||
use libadwaita::gtk::{GestureLongPress, MenuButton, Popover};
|
||||
use libadwaita::{
|
||||
self as adw, Avatar, HeaderBar, NavigationPage, ToolbarView
|
||||
self as adw, Avatar, HeaderBar, ToolbarView
|
||||
};
|
||||
use adw::gdk::{Cursor, Display};
|
||||
use adw::gio::MemoryInputStream;
|
||||
@ -340,8 +340,8 @@ pub fn get_new_message_box(
|
||||
overlay
|
||||
}
|
||||
|
||||
/// page_box, chat_box, chat_scrolled
|
||||
pub fn build_page(ctx: Arc<Context>, app: &Application, title: &str) -> (NavigationPage, GtkBox, ScrolledWindow) {
|
||||
/// header, page_box, chat_box, chat_scrolled
|
||||
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"]);
|
||||
|
||||
@ -472,9 +472,7 @@ pub fn build_page(ctx: Arc<Context>, app: &Application, title: &str) -> (Navigat
|
||||
|
||||
page_box.append(&send_box);
|
||||
|
||||
let page = NavigationPage::new(&page_box, title);
|
||||
|
||||
(page, chat_box, chat_scrolled)
|
||||
(header, page_box, chat_box, chat_scrolled)
|
||||
}
|
||||
|
||||
fn build_widget_box(ctx: Arc<Context>, _app: &Application) -> Overlay {
|
||||
|
Loading…
x
Reference in New Issue
Block a user