app: rework the UI dimension

Add GtkPaned between the logs and the graph
Load/save app dimensions.
This commit is contained in:
Stéphane Cerveau 2022-01-05 18:19:52 +01:00
parent 38dac1e56f
commit 57838ef141
3 changed files with 101 additions and 46 deletions

View file

@ -21,8 +21,8 @@ use gtk::gdk::Rectangle;
use gtk::prelude::*; use gtk::prelude::*;
use gtk::{ use gtk::{
gdk::BUTTON_SECONDARY, AboutDialog, Application, ApplicationWindow, Builder, Button, gdk::BUTTON_SECONDARY, AboutDialog, Application, ApplicationWindow, Builder, Button,
CellRendererText, FileChooserAction, FileChooserDialog, ListStore, PopoverMenu, ResponseType, CellRendererText, FileChooserAction, FileChooserDialog, ListStore, Paned, PopoverMenu,
Statusbar, TreeView, TreeViewColumn, Viewport, ResponseType, Statusbar, TreeView, TreeViewColumn, Viewport,
}; };
use gtk::{gio, glib, graphene}; use gtk::{gio, glib, graphene};
use once_cell::unsync::OnceCell; use once_cell::unsync::OnceCell;
@ -81,7 +81,19 @@ impl GPSApp {
let window: ApplicationWindow = builder.object("mainwindow").expect("Couldn't get window"); let window: ApplicationWindow = builder.object("mainwindow").expect("Couldn't get window");
window.set_application(Some(application)); window.set_application(Some(application));
window.set_title(Some("GstPipelineStudio")); window.set_title(Some("GstPipelineStudio"));
window.set_size_request(800, 600); let settings = Settings::load_settings();
window.set_size_request(settings.app_width, settings.app_height);
let paned: Paned = builder
.object("graph_logs-paned")
.expect("Couldn't get window");
paned.set_position(settings.app_graph_logs_paned_pos);
let paned: Paned = builder
.object("graph_favorites-paned")
.expect("Couldn't get window");
paned.set_position(settings.app_graph_favorites_paned_pos);
if settings.app_maximized {
window.maximize();
}
let pipeline = Pipeline::new().expect("Unable to initialize the pipeline"); let pipeline = Pipeline::new().expect("Unable to initialize the pipeline");
let app = GPSApp(Rc::new(GPSAppInner { let app = GPSApp(Rc::new(GPSAppInner {
window, window,
@ -120,6 +132,25 @@ impl GPSApp {
.borrow_mut() .borrow_mut()
.take() .take()
.expect("Shutdown called multiple times"); .expect("Shutdown called multiple times");
let window: ApplicationWindow = app
.builder
.object("mainwindow")
.expect("Couldn't get window");
let mut settings = Settings::load_settings();
settings.app_maximized = window.is_maximized();
settings.app_width = window.width();
settings.app_height = window.height();
let paned: Paned = app
.builder
.object("graph_logs-paned")
.expect("Couldn't get window");
settings.app_graph_logs_paned_pos = paned.position();
let paned: Paned = app
.builder
.object("graph_favorites-paned")
.expect("Couldn't get window");
settings.app_graph_favorites_paned_pos = paned.position();
Settings::save_settings(&settings);
app.drop(); app.drop();
}); });
} }
@ -134,10 +165,13 @@ impl GPSApp {
ok_button = "Save"; ok_button = "Save";
action = FileChooserAction::Save; action = FileChooserAction::Save;
} }
let window: ApplicationWindow = app
.builder
.object("mainwindow")
.expect("Couldn't get window");
let file_chooser: FileChooserDialog = FileChooserDialog::new( let file_chooser: FileChooserDialog = FileChooserDialog::new(
Some(message), Some(message),
Some(&app.window), Some(&window),
action, action,
&[ &[
(ok_button, ResponseType::Ok), (ok_button, ResponseType::Ok),
@ -191,6 +225,7 @@ impl GPSApp {
dialog.set_resizable(false); dialog.set_resizable(false);
dialog.show(); dialog.show();
} }
fn reset_logger_list(&self, logger_list: &TreeView) { fn reset_logger_list(&self, logger_list: &TreeView) {
let model = ListStore::new(&[String::static_type()]); let model = ListStore::new(&[String::static_type()]);
logger_list.set_model(Some(&model)); logger_list.set_model(Some(&model));
@ -298,7 +333,11 @@ impl GPSApp {
app.reset_favorite_list(&favorite_list); app.reset_favorite_list(&favorite_list);
pop_menu.unparent(); pop_menu.unparent();
})); }));
if let Some(application) = app.window.application() { let window: ApplicationWindow = app
.builder
.object("mainwindow")
.expect("Couldn't get window");
if let Some(application) = window.application() {
application.add_action(&action); application.add_action(&action);
} }

View file

@ -231,47 +231,52 @@
</object> </object>
</child> </child>
<child> <child>
<object class="GtkPaned"> <object class="GtkPaned" id="graph_logs-paned">
<property name="position">600</property> <property name="orientation">vertical</property>
<property name="position-set">True</property> <property name="position">400</property>
<property name="hexpand">True</property> <child>
<property name="vexpand">True</property> <object class="GtkPaned" id="graph_favorites-paned">
<child> <property name="position">600</property>
<object class="GtkScrolledWindow" id="drawing_area-window"> <property name="position-set">True</property>
<property name="hexpand">True</property> <property name="hexpand">True</property>
<property name="vexpand">True</property> <property name="vexpand">True</property>
<property name="child"> <child>
<object class="GtkViewport" id="drawing_area"> <object class="GtkScrolledWindow" id="drawing_area-window">
<property name="hexpand">True</property>
<property name="vexpand">True</property>
<property name="child">
<object class="GtkViewport" id="drawing_area">
<child>
<placeholder/>
</child>
</object>
</property>
</object>
</child>
<child>
<object class="GtkScrolledWindow">
<property name="hexpand">True</property>
<property name="vexpand">True</property>
<property name="child">
<object class="GtkTreeView" id="favorites_list">
<child> <child>
<placeholder/> <object class="GtkPopoverMenu" id="fav_pop_menu">
<property name="menu-model">fav_menu</property>
</object>
</child> </child>
</object> </object>
</property> </property>
</object> </object>
</child> </child>
<child> </object>
<object class="GtkScrolledWindow"> </child>
<property name="hexpand">True</property> <child>
<property name="vexpand">True</property> <object class="GtkScrolledWindow">
<property name="child"> <property name="child">
<object class="GtkTreeView" id="favorites_list"> <object class="GtkTreeView" id="logger_list"/>
<child> </property>
<object class="GtkPopoverMenu" id="fav_pop_menu"> </object>
<property name="menu-model">fav_menu</property> </child>
</object>
</child>
</object>
</property>
</object>
</child>
</object>
</child>
<child>
<object class="GtkScrolledWindow">
<property name="valign">end</property>
<property name="child">
<object class="GtkTreeView" id="logger_list"/>
</property>
</object> </object>
</child> </child>
<child> <child>

View file

@ -9,6 +9,11 @@ use crate::logger;
#[derive(Debug, Serialize, Deserialize, Default)] #[derive(Debug, Serialize, Deserialize, Default)]
pub struct Settings { pub struct Settings {
pub favorites: Vec<String>, pub favorites: Vec<String>,
pub app_maximized: bool,
pub app_width: i32,
pub app_height: i32,
pub app_graph_logs_paned_pos: i32,
pub app_graph_favorites_paned_pos: i32,
} }
impl Settings { impl Settings {
@ -81,7 +86,13 @@ impl Settings {
} }
} }
} else { } else {
Settings::default() Settings {
app_width: 800,
app_height: 600,
app_graph_logs_paned_pos: 400,
app_graph_favorites_paned_pos: 600,
..Default::default()
}
} }
} }
} }