Manual Window Layout

This commit is contained in:
Franz Dietrich 2023-12-13 22:38:07 +01:00
parent b983d78575
commit aaf2f974c7

View File

@ -2,7 +2,7 @@ use std::{cell::RefCell, rc::Rc};
use gtk4::{ use gtk4::{
glib, glib,
prelude::{ApplicationExt, GtkWindowExt, WidgetExt}, prelude::{ApplicationExt, BoxExt, GtkWindowExt, WidgetExt},
Application, ApplicationWindow, Builder, Label, Application, ApplicationWindow, Builder, Label,
}; };
use log::trace; use log::trace;
@ -25,13 +25,36 @@ fn build_ui(
app: &gtk4::Application, app: &gtk4::Application,
from_backend_rx: Rc<RefCell<Option<tokio::sync::mpsc::Receiver<BackToFront>>>>, from_backend_rx: Rc<RefCell<Option<tokio::sync::mpsc::Receiver<BackToFront>>>>,
) { ) {
let glade_src = include_str!("../../../gui/sieverman.ui"); let action_content_status = gtk4::Box::builder()
let builder = Builder::from_string(glade_src); .orientation(gtk4::Orientation::Vertical)
let main_window: ApplicationWindow = builder.object("sieverman").expect("get main-window"); .spacing(5)
main_window.set_height_request(400); .build();
main_window.set_application(Some(app)); let action = gtk4::ActionBar::new();
let status = gtk4::Statusbar::new();
let main_log_server_info = gtk4::Box::builder()
.orientation(gtk4::Orientation::Horizontal)
.hexpand(true)
.vexpand(true)
.halign(gtk4::Align::Fill)
.build();
action_content_status.append(&action);
action_content_status.append(&main_log_server_info);
action_content_status.append(&status);
let log = gtk4::Label::new(Some("Log"));
let server_info = gtk4::Label::new(Some("Server Info"));
main_log_server_info.append(&log);
main_log_server_info.append(&server_info);
let main_window = gtk4::ApplicationWindow::builder()
.application(app)
.title("Sieverman")
.height_request(400)
.width_request(400)
.child(&action_content_status)
.build();
main_window.present(); main_window.present();
let server_info = Rc::new(RefCell::new(server_info));
let future = { let future = {
let mut data_event_receiver = from_backend_rx.take().expect("data_event_reciver"); let mut data_event_receiver = from_backend_rx.take().expect("data_event_reciver");
async move { async move {
@ -40,8 +63,7 @@ fn build_ui(
match event { match event {
BackToFront::ServerConnected(message) => { BackToFront::ServerConnected(message) => {
trace!("Received {}", message); trace!("Received {}", message);
let status_label: Label = builder.object("serverstatus").unwrap(); server_info.borrow_mut().set_text(&message);
status_label.set_text(&message)
} }
} }
} }