mirror of
https://gitlab.freedesktop.org/dabrain34/GstPipelineStudio.git
synced 2025-02-06 13:52:28 +00:00
properties: follow the same layout as in preferences
Rework the UI to follow the same layout as in preferences dialog
This commit is contained in:
parent
c101ea6a37
commit
b12ea9ebdd
2 changed files with 37 additions and 74 deletions
|
@ -95,36 +95,6 @@
|
||||||
<property name="step-increment">1</property>
|
<property name="step-increment">1</property>
|
||||||
<property name="page-increment">10</property>
|
<property name="page-increment">10</property>
|
||||||
</object>
|
</object>
|
||||||
<object class="GtkDialog" id="dialog-plugin-properties">
|
|
||||||
<property name="transient-for">mainwindow</property>
|
|
||||||
<property name="default-width">320</property>
|
|
||||||
<property name="default-height">260</property>
|
|
||||||
<property name="hide-on-close">True</property>
|
|
||||||
<child>
|
|
||||||
<object class="GtkBox">
|
|
||||||
<property name="orientation">vertical</property>
|
|
||||||
<child>
|
|
||||||
<object class="GtkScrolledWindow">
|
|
||||||
<property name="hexpand">True</property>
|
|
||||||
<property name="vexpand">True</property>
|
|
||||||
<child>
|
|
||||||
<object class="GtkBox" id="box-plugin-properties">
|
|
||||||
<property name="orientation">vertical</property>
|
|
||||||
</object>
|
|
||||||
</child>
|
|
||||||
</object>
|
|
||||||
</child>
|
|
||||||
<child>
|
|
||||||
<object class="GtkButton" id="button-apply-plugin-properties">
|
|
||||||
<property name="halign">end</property>
|
|
||||||
<property name="hexpand">1</property>
|
|
||||||
<property name="receives-default">1</property>
|
|
||||||
<property name="label" translatable="yes">apply</property>
|
|
||||||
</object>
|
|
||||||
</child>
|
|
||||||
</object>
|
|
||||||
</child>
|
|
||||||
</object>
|
|
||||||
<object class="GtkApplicationWindow" id="mainwindow">
|
<object class="GtkApplicationWindow" id="mainwindow">
|
||||||
<property name="title" translatable="yes">GstPipelineStudio</property>
|
<property name="title" translatable="yes">GstPipelineStudio</property>
|
||||||
<property name="default-width">800</property>
|
<property name="default-width">800</property>
|
||||||
|
|
|
@ -27,8 +27,6 @@ use std::cell::RefCell;
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
|
|
||||||
use gtk::{Box, Button, CheckButton, ComboBoxText, Dialog, Entry, Label, Widget};
|
|
||||||
|
|
||||||
fn value_as_str(v: &glib::Value) -> Option<String> {
|
fn value_as_str(v: &glib::Value) -> Option<String> {
|
||||||
match v.type_() {
|
match v.type_() {
|
||||||
glib::Type::I8 => Some(str_some_value!(v, i8).to_string()),
|
glib::Type::I8 => Some(str_some_value!(v, i8).to_string()),
|
||||||
|
@ -52,10 +50,10 @@ pub fn property_to_widget<F: Fn(String, String) + 'static>(
|
||||||
property_name: &str,
|
property_name: &str,
|
||||||
param: &glib::ParamSpec,
|
param: &glib::ParamSpec,
|
||||||
f: F,
|
f: F,
|
||||||
) -> Option<Widget> {
|
) -> Option<gtk::Widget> {
|
||||||
match param.type_() {
|
match param.type_() {
|
||||||
_t if param.type_() == glib::ParamSpecBoolean::static_type() => {
|
_t if param.type_() == glib::ParamSpecBoolean::static_type() => {
|
||||||
let check_button = CheckButton::new();
|
let check_button = gtk::CheckButton::new();
|
||||||
check_button.set_widget_name(property_name);
|
check_button.set_widget_name(property_name);
|
||||||
GPS_TRACE!("add CheckBox property : {}", check_button.widget_name());
|
GPS_TRACE!("add CheckBox property : {}", check_button.widget_name());
|
||||||
if let Some(value) = app.element_property(node_id, property_name) {
|
if let Some(value) = app.element_property(node_id, property_name) {
|
||||||
|
@ -72,7 +70,7 @@ pub fn property_to_widget<F: Fn(String, String) + 'static>(
|
||||||
check_button.connect_toggled(glib::clone!(@weak check_button => move |c| {
|
check_button.connect_toggled(glib::clone!(@weak check_button => move |c| {
|
||||||
f(c.widget_name().to_string(), c.is_active().to_string() );
|
f(c.widget_name().to_string(), c.is_active().to_string() );
|
||||||
}));
|
}));
|
||||||
Some(check_button.upcast::<Widget>())
|
Some(check_button.upcast::<gtk::Widget>())
|
||||||
}
|
}
|
||||||
t if [
|
t if [
|
||||||
glib::ParamSpecInt::static_type(),
|
glib::ParamSpecInt::static_type(),
|
||||||
|
@ -83,7 +81,8 @@ pub fn property_to_widget<F: Fn(String, String) + 'static>(
|
||||||
]
|
]
|
||||||
.contains(&t) =>
|
.contains(&t) =>
|
||||||
{
|
{
|
||||||
let entry = Entry::new();
|
let entry = gtk::Entry::new();
|
||||||
|
entry.set_width_request(350);
|
||||||
entry.set_widget_name(property_name);
|
entry.set_widget_name(property_name);
|
||||||
GPS_TRACE!("Add Edit property : {}", entry.widget_name());
|
GPS_TRACE!("Add Edit property : {}", entry.widget_name());
|
||||||
if let Some(value) = app.element_property(node_id, property_name) {
|
if let Some(value) = app.element_property(node_id, property_name) {
|
||||||
|
@ -101,7 +100,7 @@ pub fn property_to_widget<F: Fn(String, String) + 'static>(
|
||||||
entry.connect_changed(glib::clone!(@weak entry=> move |e| {
|
entry.connect_changed(glib::clone!(@weak entry=> move |e| {
|
||||||
f(e.widget_name().to_string(), e.text().to_string())
|
f(e.widget_name().to_string(), e.text().to_string())
|
||||||
}));
|
}));
|
||||||
Some(entry.upcast::<Widget>())
|
Some(entry.upcast::<gtk::Widget>())
|
||||||
}
|
}
|
||||||
t if [
|
t if [
|
||||||
glib::ParamSpecEnum::static_type(),
|
glib::ParamSpecEnum::static_type(),
|
||||||
|
@ -109,7 +108,8 @@ pub fn property_to_widget<F: Fn(String, String) + 'static>(
|
||||||
]
|
]
|
||||||
.contains(&t) =>
|
.contains(&t) =>
|
||||||
{
|
{
|
||||||
let combo = ComboBoxText::new();
|
let combo = gtk::ComboBoxText::new();
|
||||||
|
|
||||||
combo.set_widget_name(property_name);
|
combo.set_widget_name(property_name);
|
||||||
GPS_TRACE!("add ComboBox property : {}", combo.widget_name());
|
GPS_TRACE!("add ComboBox property : {}", combo.widget_name());
|
||||||
if t.is_a(glib::ParamSpecEnum::static_type()) {
|
if t.is_a(glib::ParamSpecEnum::static_type()) {
|
||||||
|
@ -163,7 +163,7 @@ pub fn property_to_widget<F: Fn(String, String) + 'static>(
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
Some(combo.upcast::<Widget>())
|
Some(combo.upcast::<gtk::Widget>())
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
GPS_INFO!(
|
GPS_INFO!(
|
||||||
|
@ -177,37 +177,24 @@ pub fn property_to_widget<F: Fn(String, String) + 'static>(
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn display_plugin_properties(app: &GPSApp, element_name: &str, node_id: u32) {
|
pub fn display_plugin_properties(app: &GPSApp, element_name: &str, node_id: u32) {
|
||||||
let dialog: Dialog = app
|
let dialog = gtk::Dialog::with_buttons(
|
||||||
.builder
|
Some(&format!("{} properties", element_name)),
|
||||||
.object("dialog-plugin-properties")
|
Some(&app.window),
|
||||||
.expect("Couldn't get dialog-plugin-properties");
|
gtk::DialogFlags::MODAL,
|
||||||
|
&[("Close", gtk::ResponseType::Close)],
|
||||||
|
);
|
||||||
|
|
||||||
dialog.set_title(Some(&format!("{} properties", element_name)));
|
|
||||||
dialog.set_default_size(640, 480);
|
dialog.set_default_size(640, 480);
|
||||||
dialog.set_modal(true);
|
dialog.set_modal(true);
|
||||||
|
|
||||||
let properties_box: Box = app
|
|
||||||
.builder
|
|
||||||
.object("box-plugin-properties")
|
|
||||||
.expect("Couldn't get box-plugin-properties");
|
|
||||||
let update_properties: Rc<RefCell<HashMap<String, String>>> =
|
let update_properties: Rc<RefCell<HashMap<String, String>>> =
|
||||||
Rc::new(RefCell::new(HashMap::new()));
|
Rc::new(RefCell::new(HashMap::new()));
|
||||||
let properties = GPS::ElementInfo::element_properties(element_name).unwrap();
|
let properties = GPS::ElementInfo::element_properties(element_name).unwrap();
|
||||||
while let Some(child) = properties_box.first_child() {
|
|
||||||
properties_box.remove(&child);
|
|
||||||
}
|
|
||||||
|
|
||||||
let grid = gtk::Grid::builder()
|
let grid = gtk::Grid::new();
|
||||||
.margin_start(6)
|
grid.set_column_spacing(4);
|
||||||
.margin_end(6)
|
grid.set_row_spacing(4);
|
||||||
.margin_top(6)
|
grid.set_margin_bottom(12);
|
||||||
.margin_bottom(6)
|
|
||||||
.halign(gtk::Align::Start)
|
|
||||||
.valign(gtk::Align::Center)
|
|
||||||
.row_spacing(6)
|
|
||||||
.column_spacing(100)
|
|
||||||
.width_request(100)
|
|
||||||
.build();
|
|
||||||
|
|
||||||
let mut properties: Vec<(&String, &glib::ParamSpec)> = properties.iter().collect();
|
let mut properties: Vec<(&String, &glib::ParamSpec)> = properties.iter().collect();
|
||||||
properties.sort_by(|a, b| a.0.cmp(b.0));
|
properties.sort_by(|a, b| a.0.cmp(b.0));
|
||||||
|
@ -226,7 +213,7 @@ pub fn display_plugin_properties(app: &GPSApp, element_name: &str, node_id: u32)
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
if let Some(widget) = widget {
|
if let Some(widget) = widget {
|
||||||
let label = Label::new(Some(name));
|
let label = gtk::Label::new(Some(name));
|
||||||
label.set_hexpand(true);
|
label.set_hexpand(true);
|
||||||
label.set_halign(gtk::Align::Start);
|
label.set_halign(gtk::Align::Start);
|
||||||
label.set_margin_start(4);
|
label.set_margin_start(4);
|
||||||
|
@ -235,24 +222,30 @@ pub fn display_plugin_properties(app: &GPSApp, element_name: &str, node_id: u32)
|
||||||
i += 1;
|
i += 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
properties_box.append(&grid);
|
let scrolledwindow = gtk::ScrolledWindow::builder()
|
||||||
|
.hexpand(true)
|
||||||
let properties_apply_btn: Button = app
|
.vexpand(true)
|
||||||
.builder
|
.build();
|
||||||
.object("button-apply-plugin-properties")
|
scrolledwindow.set_child(Some(&grid));
|
||||||
.expect("Couldn't get button-apply-plugin-properties");
|
let content_area = dialog.content_area();
|
||||||
|
content_area.append(&scrolledwindow);
|
||||||
|
content_area.set_vexpand(true);
|
||||||
|
content_area.set_margin_start(10);
|
||||||
|
content_area.set_margin_end(10);
|
||||||
|
content_area.set_margin_top(10);
|
||||||
|
content_area.set_margin_bottom(10);
|
||||||
|
|
||||||
let app_weak = app.downgrade();
|
let app_weak = app.downgrade();
|
||||||
properties_apply_btn.connect_clicked(
|
dialog.connect_response(
|
||||||
glib::clone!(@strong update_properties, @weak dialog => move |_| {
|
glib::clone!(@strong update_properties, @weak dialog => move |_,_| {
|
||||||
let app = upgrade_weak!(app_weak);
|
let app = upgrade_weak!(app_weak);
|
||||||
|
for p in update_properties.borrow().values() {
|
||||||
|
GPS_INFO!("updated properties {}", p);
|
||||||
|
}
|
||||||
app.update_element_properties(node_id, &update_properties.borrow());
|
app.update_element_properties(node_id, &update_properties.borrow());
|
||||||
dialog.close();
|
dialog.close();
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
|
|
||||||
dialog.show();
|
dialog.show();
|
||||||
for p in update_properties.borrow().values() {
|
|
||||||
GPS_INFO!("updated properties {}", p);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue