Moved away from EmbeddedWidgetConnector
Fixed lifetime management of mainwindow connector
This commit is contained in:
parent
a1695a3997
commit
0840e2c9c6
36
Linux/Cargo.lock
generated
36
Linux/Cargo.lock
generated
@ -13,9 +13,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "anstream"
|
name = "anstream"
|
||||||
version = "0.6.14"
|
version = "0.6.15"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "418c75fa768af9c03be99d17643f93f79bbba589895012a80e3452a19ddda15b"
|
checksum = "64e15c1ab1f89faffbf04a634d5e1962e9074f2741eef6d97f3c4e322426d526"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anstyle",
|
"anstyle",
|
||||||
"anstyle-parse",
|
"anstyle-parse",
|
||||||
@ -28,33 +28,33 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "anstyle"
|
name = "anstyle"
|
||||||
version = "1.0.7"
|
version = "1.0.8"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "038dfcf04a5feb68e9c60b21c9625a54c2c0616e79b72b0fd87075a056ae1d1b"
|
checksum = "1bec1de6f59aedf83baf9ff929c98f2ad654b97c9510f4e70cf6f661d49fd5b1"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "anstyle-parse"
|
name = "anstyle-parse"
|
||||||
version = "0.2.4"
|
version = "0.2.5"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "c03a11a9034d92058ceb6ee011ce58af4a9bf61491aa7e1e59ecd24bd40d22d4"
|
checksum = "eb47de1e80c2b463c735db5b217a0ddc39d612e7ac9e2e96a5aed1f57616c1cb"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"utf8parse",
|
"utf8parse",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "anstyle-query"
|
name = "anstyle-query"
|
||||||
version = "1.1.0"
|
version = "1.1.1"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "ad186efb764318d35165f1758e7dcef3b10628e26d41a44bc5550652e6804391"
|
checksum = "6d36fc52c7f6c869915e99412912f22093507da8d9e942ceaf66fe4b7c14422a"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"windows-sys",
|
"windows-sys",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "anstyle-wincon"
|
name = "anstyle-wincon"
|
||||||
version = "3.0.3"
|
version = "3.0.4"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "61a38449feb7068f52bb06c12759005cf459ee52bb4adc1d5a7c4322d716fb19"
|
checksum = "5bf74e1b6e971609db8ca7a9ce79fd5768ab6ae46441c572e46cf596f59e57f8"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anstyle",
|
"anstyle",
|
||||||
"windows-sys",
|
"windows-sys",
|
||||||
@ -147,9 +147,9 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "colorchoice"
|
name = "colorchoice"
|
||||||
version = "1.0.1"
|
version = "1.0.2"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "0b6a852b24ab71dffc585bcb46eaf7959d175cb865a7152e35b348d1b2960422"
|
checksum = "d3fd119d74b830634cea2a0f58bbd0d54540518a14397557951e79340abc28c0"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "core-foundation-sys"
|
name = "core-foundation-sys"
|
||||||
@ -205,9 +205,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "env_filter"
|
name = "env_filter"
|
||||||
version = "0.1.0"
|
version = "0.1.2"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "a009aa4810eb158359dda09d0c87378e4bbb89b5a801f016885a4707ba24f7ea"
|
checksum = "4f2c92ceda6ceec50f43169f9ee8424fe2db276791afde7b2cd8bc084cb376ab"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"log",
|
"log",
|
||||||
"regex",
|
"regex",
|
||||||
@ -215,9 +215,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "env_logger"
|
name = "env_logger"
|
||||||
version = "0.11.3"
|
version = "0.11.5"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "38b35839ba51819680ba087cd351788c9a3c476841207e0b8cee0b04722343b9"
|
checksum = "e13fa619b91fb2381732789fc5de83b45675e882f66623b7d8cb4f643017018d"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anstream",
|
"anstream",
|
||||||
"anstyle",
|
"anstyle",
|
||||||
@ -666,9 +666,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "is_terminal_polyfill"
|
name = "is_terminal_polyfill"
|
||||||
version = "1.70.0"
|
version = "1.70.1"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "f8478577c03552c21db0e2724ffb8986a5ce7af88107e6be5d2ee6e158c12800"
|
checksum = "7943c866cc5cd64cbc25b2e01621d07fa8eb2a1a23160ee81ce38704e97b8ecf"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "itoa"
|
name = "itoa"
|
||||||
|
@ -5,7 +5,7 @@ edition = "2021"
|
|||||||
build = "build.rs"
|
build = "build.rs"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
env_logger = "0.11.3"
|
env_logger = "0.11.5"
|
||||||
gtk = { version = "0.9.0", package = "gtk4", features = ["v4_14"] }
|
gtk = { version = "0.9.0", package = "gtk4", features = ["v4_14"] }
|
||||||
log = "0.4.21"
|
log = "0.4.21"
|
||||||
rust-i18n = "3.0.1"
|
rust-i18n = "3.0.1"
|
||||||
|
@ -1,3 +1,6 @@
|
|||||||
|
use std::cell::RefCell;
|
||||||
|
use std::rc::Rc;
|
||||||
|
|
||||||
use massiveknob_backend::orchestrator::DeviceReference;
|
use massiveknob_backend::orchestrator::DeviceReference;
|
||||||
|
|
||||||
use crate::ui::uicomponent::UiComponent;
|
use crate::ui::uicomponent::UiComponent;
|
||||||
@ -46,7 +49,7 @@ impl UiComponent for EmulatorSettingsUi
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn init(_root: &Self::Root, _state: &std::rc::Rc<std::cell::RefCell<Self::State>>)
|
fn init(_root: &Self::Root, _widgets: &Rc<Self::Widgets>, _state: &Rc<RefCell<Self::State>>)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -54,48 +57,10 @@ impl UiComponent for EmulatorSettingsUi
|
|||||||
|
|
||||||
impl UiComponentState<EmulatorSettingsUi> for EmulatorSettingsUi
|
impl UiComponentState<EmulatorSettingsUi> for EmulatorSettingsUi
|
||||||
{
|
{
|
||||||
fn new(_init: EmulatorSettingsUiInit, _widgets: EmulatorSettingsUiWidgets) -> Self
|
fn new(_init: EmulatorSettingsUiInit) -> Self
|
||||||
{
|
{
|
||||||
Self
|
Self
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
#[relm4::component(pub)]
|
|
||||||
impl SimpleComponent for EmulatorWindow
|
|
||||||
{
|
|
||||||
type Init = ();
|
|
||||||
type Input = EmulatorWindowMessage;
|
|
||||||
type Output = ();
|
|
||||||
|
|
||||||
view!
|
|
||||||
{
|
|
||||||
gtk::Window
|
|
||||||
{
|
|
||||||
set_title: Some(&t!("emulatorwindow.title")),
|
|
||||||
set_default_size: (300, 500)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
fn init(_data: Self::Init, root: Self::Root, _sender: ComponentSender<Self>, ) -> ComponentParts<Self>
|
|
||||||
{
|
|
||||||
let model = EmulatorWindow {};
|
|
||||||
let widgets = view_output!();
|
|
||||||
|
|
||||||
root.set_visible(true);
|
|
||||||
ComponentParts { model, widgets }
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
fn update(&mut self, msg: Self::Input, _sender: ComponentSender<Self>)
|
|
||||||
{
|
|
||||||
match msg
|
|
||||||
{
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
*/
|
|
@ -23,8 +23,8 @@ impl DeviceSettingsUiBuilder
|
|||||||
{
|
{
|
||||||
match device.as_ref()
|
match device.as_ref()
|
||||||
{
|
{
|
||||||
Device::Emulator(_) => Box::new(EmulatorSettingsUi::builder().build(EmulatorSettingsUiInit { device })),
|
Device::Emulator(_) => Box::new(EmulatorSettingsUi::builder().build("EmulatorSettingsUi", EmulatorSettingsUiInit { device })),
|
||||||
Device::SerialMin(_) => Box::new(SerialMinSettingsUi::builder().build(SerialMinSettingsUiInit { device }))
|
Device::SerialMin(_) => Box::new(SerialMinSettingsUi::builder().build("SerialMinSettingsUi", SerialMinSettingsUiInit { device }))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -153,7 +153,7 @@ impl SerialMinSettingsUi
|
|||||||
fn set_port(&self, widgets: &Rc<SerialMinSettingsUiWidgets>, index: u32)
|
fn set_port(&self, widgets: &Rc<SerialMinSettingsUiWidgets>, index: u32)
|
||||||
{
|
{
|
||||||
let Ok(index_usize) = usize::try_from(index) else { return };
|
let Ok(index_usize) = usize::try_from(index) else { return };
|
||||||
let custom_port_visible = index_usize == self.ports.len() - 1;
|
let custom_port_visible = index_usize == self.ports.len();
|
||||||
|
|
||||||
widgets.custom_port_input.set_visible(custom_port_visible);
|
widgets.custom_port_input.set_visible(custom_port_visible);
|
||||||
}
|
}
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
use std::cell::RefCell;
|
||||||
|
use std::rc::Rc;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use std::sync::Mutex;
|
use std::sync::Mutex;
|
||||||
|
|
||||||
@ -8,6 +10,7 @@ use mainwindow::MainWindow;
|
|||||||
use mainwindow::MainWindowInit;
|
use mainwindow::MainWindowInit;
|
||||||
use massiveknob_backend::orchestrator::Orchestrator;
|
use massiveknob_backend::orchestrator::Orchestrator;
|
||||||
use ui::uicomponent::UiComponent;
|
use ui::uicomponent::UiComponent;
|
||||||
|
use ui::uicomponent::UiComponentConnector;
|
||||||
|
|
||||||
|
|
||||||
const APP_ID: &str = "com.github.mvrens.massiveknob";
|
const APP_ID: &str = "com.github.mvrens.massiveknob";
|
||||||
@ -24,6 +27,7 @@ pub mod devices;
|
|||||||
|
|
||||||
pub mod mainwindow;
|
pub mod mainwindow;
|
||||||
|
|
||||||
|
|
||||||
fn main() -> glib::ExitCode
|
fn main() -> glib::ExitCode
|
||||||
{
|
{
|
||||||
env_logger::Builder::from_env(Env::default().default_filter_or("info"))
|
env_logger::Builder::from_env(Env::default().default_filter_or("info"))
|
||||||
@ -31,23 +35,31 @@ fn main() -> glib::ExitCode
|
|||||||
.init();
|
.init();
|
||||||
|
|
||||||
|
|
||||||
|
let mainwindow: Rc<RefCell<Option<UiComponentConnector<MainWindow>>>> = Rc::new(RefCell::new(None));
|
||||||
|
|
||||||
|
|
||||||
let app = gtk::Application::builder()
|
let app = gtk::Application::builder()
|
||||||
.application_id(APP_ID)
|
.application_id(APP_ID)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
app.connect_activate(activate);
|
{
|
||||||
app.run()
|
let mainwindow = mainwindow.clone();
|
||||||
}
|
app.connect_activate(move |app|
|
||||||
|
|
||||||
|
|
||||||
fn activate(app: >k::Application)
|
|
||||||
{
|
{
|
||||||
let orchestrator = Arc::new(Mutex::new(Orchestrator::new()));
|
let orchestrator = Arc::new(Mutex::new(Orchestrator::new()));
|
||||||
let mainwindow = MainWindow::builder().build(MainWindowInit
|
let newmainwindow = MainWindow::builder().build("MainWindow", MainWindowInit
|
||||||
{
|
{
|
||||||
app: app.clone(),
|
app: app.clone(),
|
||||||
orchestrator: orchestrator.clone()
|
orchestrator: orchestrator.clone()
|
||||||
});
|
});
|
||||||
|
|
||||||
mainwindow.root.present();
|
newmainwindow.root.present();
|
||||||
|
mainwindow.borrow_mut().replace(newmainwindow);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
let result = app.run();
|
||||||
|
|
||||||
|
log::debug!("So long and thanks for all the fish!");
|
||||||
|
result
|
||||||
}
|
}
|
@ -118,7 +118,7 @@ impl UiComponent for MainWindow
|
|||||||
}
|
}
|
||||||
|
|
||||||
let mut state = state.borrow_mut();
|
let mut state = state.borrow_mut();
|
||||||
state.update_active_device(&widgets, false);
|
state.update_active_device(widgets, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,8 +1 @@
|
|||||||
pub mod uicomponent;
|
pub mod uicomponent;
|
||||||
|
|
||||||
|
|
||||||
#[deprecated]
|
|
||||||
pub trait EmbeddedWidgetConnector
|
|
||||||
{
|
|
||||||
fn root(&self) -> gtk::Widget;
|
|
||||||
}
|
|
@ -35,9 +35,12 @@ pub trait UiComponentState<C: UiComponent>
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#[must_use]
|
||||||
pub struct UiComponentConnector<C: UiComponent>
|
pub struct UiComponentConnector<C: UiComponent>
|
||||||
{
|
{
|
||||||
|
pub name: String,
|
||||||
pub root: C::Root,
|
pub root: C::Root,
|
||||||
|
pub widgets: Rc<C::Widgets>,
|
||||||
pub state: Rc<RefCell<C::State>>
|
pub state: Rc<RefCell<C::State>>
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -68,7 +71,7 @@ impl<C: UiComponent> Default for UiComponentBuilder<C>
|
|||||||
|
|
||||||
impl<C: UiComponent> UiComponentBuilder<C>
|
impl<C: UiComponent> UiComponentBuilder<C>
|
||||||
{
|
{
|
||||||
pub fn build(&self, init: C::Init) -> UiComponentConnector<C>
|
pub fn build(&self, name: &str, init: C::Init) -> UiComponentConnector<C>
|
||||||
{
|
{
|
||||||
let root = C::build_root(&init);
|
let root = C::build_root(&init);
|
||||||
let widgets = Rc::new(C::build_widgets(&root, &init));
|
let widgets = Rc::new(C::build_widgets(&root, &init));
|
||||||
@ -79,7 +82,9 @@ impl<C: UiComponent> UiComponentBuilder<C>
|
|||||||
|
|
||||||
UiComponentConnector::<C>
|
UiComponentConnector::<C>
|
||||||
{
|
{
|
||||||
|
name: String::from(name),
|
||||||
root,
|
root,
|
||||||
|
widgets,
|
||||||
state
|
state
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -90,7 +95,7 @@ impl<C: UiComponent> From<UiComponentConnector<C>> for gtk::Widget
|
|||||||
{
|
{
|
||||||
fn from(val: UiComponentConnector<C>) -> Self
|
fn from(val: UiComponentConnector<C>) -> Self
|
||||||
{
|
{
|
||||||
val.root.into()
|
val.root.clone().into()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -102,3 +107,13 @@ impl<C: UiComponent> UiComponentConnectorWidget for UiComponentConnector<C>
|
|||||||
self.root.clone().into()
|
self.root.clone().into()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
impl<C: UiComponent> Drop for UiComponentConnector<C>
|
||||||
|
{
|
||||||
|
fn drop(&mut self)
|
||||||
|
{
|
||||||
|
self.root.unrealize();
|
||||||
|
log::debug!("Dropped UiComponentConnector for {}", self.name.as_str());
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user