mirror of
https://gitlab.freedesktop.org/dabrain34/GstPipelineStudio.git
synced 2024-11-25 10:30:59 +00:00
move glib value_as_str to common module
This commit is contained in:
parent
c0220c4bdb
commit
01df04be60
2 changed files with 20 additions and 18 deletions
|
@ -7,6 +7,7 @@
|
||||||
// SPDX-License-Identifier: GPL-3.0-only
|
// SPDX-License-Identifier: GPL-3.0-only
|
||||||
|
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
|
use gtk::glib;
|
||||||
|
|
||||||
pub fn init() -> Result<()> {
|
pub fn init() -> Result<()> {
|
||||||
unsafe {
|
unsafe {
|
||||||
|
@ -16,3 +17,19 @@ pub fn init() -> Result<()> {
|
||||||
gtk::init()?;
|
gtk::init()?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn value_as_str(v: &glib::Value) -> Option<String> {
|
||||||
|
match v.type_() {
|
||||||
|
glib::Type::I8 => Some(str_some_value!(v, i8).to_string()),
|
||||||
|
glib::Type::U8 => Some(str_some_value!(v, u8).to_string()),
|
||||||
|
glib::Type::BOOL => Some(str_some_value!(v, bool).to_string()),
|
||||||
|
glib::Type::I32 => Some(str_some_value!(v, i32).to_string()),
|
||||||
|
glib::Type::U32 => Some(str_some_value!(v, u32).to_string()),
|
||||||
|
glib::Type::I64 => Some(str_some_value!(v, i64).to_string()),
|
||||||
|
glib::Type::U64 => Some(str_some_value!(v, u64).to_string()),
|
||||||
|
glib::Type::F32 => Some(str_some_value!(v, f32).to_string()),
|
||||||
|
glib::Type::F64 => Some(str_some_value!(v, f64).to_string()),
|
||||||
|
glib::Type::STRING => str_opt_value!(v, String),
|
||||||
|
_ => None,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
// SPDX-License-Identifier: GPL-3.0-only
|
// SPDX-License-Identifier: GPL-3.0-only
|
||||||
|
|
||||||
use crate::app::GPSApp;
|
use crate::app::GPSApp;
|
||||||
|
use crate::common;
|
||||||
use crate::gps as GPS;
|
use crate::gps as GPS;
|
||||||
use crate::logger;
|
use crate::logger;
|
||||||
use crate::ui as GPSUI;
|
use crate::ui as GPSUI;
|
||||||
|
@ -18,22 +19,6 @@ use std::cell::RefCell;
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
|
|
||||||
fn value_as_str(v: &glib::Value) -> Option<String> {
|
|
||||||
match v.type_() {
|
|
||||||
glib::Type::I8 => Some(str_some_value!(v, i8).to_string()),
|
|
||||||
glib::Type::U8 => Some(str_some_value!(v, u8).to_string()),
|
|
||||||
glib::Type::BOOL => Some(str_some_value!(v, bool).to_string()),
|
|
||||||
glib::Type::I32 => Some(str_some_value!(v, i32).to_string()),
|
|
||||||
glib::Type::U32 => Some(str_some_value!(v, u32).to_string()),
|
|
||||||
glib::Type::I64 => Some(str_some_value!(v, i64).to_string()),
|
|
||||||
glib::Type::U64 => Some(str_some_value!(v, u64).to_string()),
|
|
||||||
glib::Type::F32 => Some(str_some_value!(v, f32).to_string()),
|
|
||||||
glib::Type::F64 => Some(str_some_value!(v, f64).to_string()),
|
|
||||||
glib::Type::STRING => str_opt_value!(v, String),
|
|
||||||
_ => None,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn property_to_widget<F: Fn(String, String) + 'static>(
|
pub fn property_to_widget<F: Fn(String, String) + 'static>(
|
||||||
app: &GPSApp,
|
app: &GPSApp,
|
||||||
node_id: u32,
|
node_id: u32,
|
||||||
|
@ -57,7 +42,7 @@ pub fn property_to_widget<F: Fn(String, String) + 'static>(
|
||||||
{
|
{
|
||||||
check_button.set_active(value.parse::<bool>().unwrap_or(false));
|
check_button.set_active(value.parse::<bool>().unwrap_or(false));
|
||||||
}
|
}
|
||||||
} else if let Some(value) = value_as_str(param.default_value()) {
|
} else if let Some(value) = common::value_as_str(param.default_value()) {
|
||||||
check_button.set_active(value.parse::<bool>().unwrap_or(false));
|
check_button.set_active(value.parse::<bool>().unwrap_or(false));
|
||||||
}
|
}
|
||||||
check_button.connect_toggled(glib::clone!(@weak check_button => move |c| {
|
check_button.connect_toggled(glib::clone!(@weak check_button => move |c| {
|
||||||
|
@ -88,7 +73,7 @@ pub fn property_to_widget<F: Fn(String, String) + 'static>(
|
||||||
{
|
{
|
||||||
entry.set_text(&value);
|
entry.set_text(&value);
|
||||||
}
|
}
|
||||||
} else if let Some(value) = value_as_str(param.default_value()) {
|
} else if let Some(value) = common::value_as_str(param.default_value()) {
|
||||||
entry.set_text(&value);
|
entry.set_text(&value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue