1
0
mirror of synced 2024-12-22 09:03:08 +01:00

Moved away from EmbeddedWidgetConnector

Fixed lifetime management of mainwindow connector
This commit is contained in:
Mark van Renswoude 2024-08-27 10:03:57 +02:00
parent a1695a3997
commit 0840e2c9c6
9 changed files with 72 additions and 87 deletions

36
Linux/Cargo.lock generated
View File

@ -13,9 +13,9 @@ dependencies = [
[[package]]
name = "anstream"
version = "0.6.14"
version = "0.6.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "418c75fa768af9c03be99d17643f93f79bbba589895012a80e3452a19ddda15b"
checksum = "64e15c1ab1f89faffbf04a634d5e1962e9074f2741eef6d97f3c4e322426d526"
dependencies = [
"anstyle",
"anstyle-parse",
@ -28,33 +28,33 @@ dependencies = [
[[package]]
name = "anstyle"
version = "1.0.7"
version = "1.0.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "038dfcf04a5feb68e9c60b21c9625a54c2c0616e79b72b0fd87075a056ae1d1b"
checksum = "1bec1de6f59aedf83baf9ff929c98f2ad654b97c9510f4e70cf6f661d49fd5b1"
[[package]]
name = "anstyle-parse"
version = "0.2.4"
version = "0.2.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c03a11a9034d92058ceb6ee011ce58af4a9bf61491aa7e1e59ecd24bd40d22d4"
checksum = "eb47de1e80c2b463c735db5b217a0ddc39d612e7ac9e2e96a5aed1f57616c1cb"
dependencies = [
"utf8parse",
]
[[package]]
name = "anstyle-query"
version = "1.1.0"
version = "1.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ad186efb764318d35165f1758e7dcef3b10628e26d41a44bc5550652e6804391"
checksum = "6d36fc52c7f6c869915e99412912f22093507da8d9e942ceaf66fe4b7c14422a"
dependencies = [
"windows-sys",
]
[[package]]
name = "anstyle-wincon"
version = "3.0.3"
version = "3.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "61a38449feb7068f52bb06c12759005cf459ee52bb4adc1d5a7c4322d716fb19"
checksum = "5bf74e1b6e971609db8ca7a9ce79fd5768ab6ae46441c572e46cf596f59e57f8"
dependencies = [
"anstyle",
"windows-sys",
@ -147,9 +147,9 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
[[package]]
name = "colorchoice"
version = "1.0.1"
version = "1.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0b6a852b24ab71dffc585bcb46eaf7959d175cb865a7152e35b348d1b2960422"
checksum = "d3fd119d74b830634cea2a0f58bbd0d54540518a14397557951e79340abc28c0"
[[package]]
name = "core-foundation-sys"
@ -205,9 +205,9 @@ dependencies = [
[[package]]
name = "env_filter"
version = "0.1.0"
version = "0.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a009aa4810eb158359dda09d0c87378e4bbb89b5a801f016885a4707ba24f7ea"
checksum = "4f2c92ceda6ceec50f43169f9ee8424fe2db276791afde7b2cd8bc084cb376ab"
dependencies = [
"log",
"regex",
@ -215,9 +215,9 @@ dependencies = [
[[package]]
name = "env_logger"
version = "0.11.3"
version = "0.11.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "38b35839ba51819680ba087cd351788c9a3c476841207e0b8cee0b04722343b9"
checksum = "e13fa619b91fb2381732789fc5de83b45675e882f66623b7d8cb4f643017018d"
dependencies = [
"anstream",
"anstyle",
@ -666,9 +666,9 @@ dependencies = [
[[package]]
name = "is_terminal_polyfill"
version = "1.70.0"
version = "1.70.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f8478577c03552c21db0e2724ffb8986a5ce7af88107e6be5d2ee6e158c12800"
checksum = "7943c866cc5cd64cbc25b2e01621d07fa8eb2a1a23160ee81ce38704e97b8ecf"
[[package]]
name = "itoa"

View File

@ -5,7 +5,7 @@ edition = "2021"
build = "build.rs"
[dependencies]
env_logger = "0.11.3"
env_logger = "0.11.5"
gtk = { version = "0.9.0", package = "gtk4", features = ["v4_14"] }
log = "0.4.21"
rust-i18n = "3.0.1"

View File

@ -1,3 +1,6 @@
use std::cell::RefCell;
use std::rc::Rc;
use massiveknob_backend::orchestrator::DeviceReference;
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
{
fn new(_init: EmulatorSettingsUiInit, _widgets: EmulatorSettingsUiWidgets) -> Self
fn new(_init: EmulatorSettingsUiInit) -> 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
{
}
}
}
*/
}

View File

@ -23,8 +23,8 @@ impl DeviceSettingsUiBuilder
{
match device.as_ref()
{
Device::Emulator(_) => Box::new(EmulatorSettingsUi::builder().build(EmulatorSettingsUiInit { device })),
Device::SerialMin(_) => Box::new(SerialMinSettingsUi::builder().build(SerialMinSettingsUiInit { device }))
Device::Emulator(_) => Box::new(EmulatorSettingsUi::builder().build("EmulatorSettingsUi", EmulatorSettingsUiInit { device })),
Device::SerialMin(_) => Box::new(SerialMinSettingsUi::builder().build("SerialMinSettingsUi", SerialMinSettingsUiInit { device }))
}
}
}

View File

@ -153,7 +153,7 @@ impl SerialMinSettingsUi
fn set_port(&self, widgets: &Rc<SerialMinSettingsUiWidgets>, index: u32)
{
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);
}

View File

@ -1,3 +1,5 @@
use std::cell::RefCell;
use std::rc::Rc;
use std::sync::Arc;
use std::sync::Mutex;
@ -8,6 +10,7 @@ use mainwindow::MainWindow;
use mainwindow::MainWindowInit;
use massiveknob_backend::orchestrator::Orchestrator;
use ui::uicomponent::UiComponent;
use ui::uicomponent::UiComponentConnector;
const APP_ID: &str = "com.github.mvrens.massiveknob";
@ -24,6 +27,7 @@ pub mod devices;
pub mod mainwindow;
fn main() -> glib::ExitCode
{
env_logger::Builder::from_env(Env::default().default_filter_or("info"))
@ -31,23 +35,31 @@ fn main() -> glib::ExitCode
.init();
let mainwindow: Rc<RefCell<Option<UiComponentConnector<MainWindow>>>> = Rc::new(RefCell::new(None));
let app = gtk::Application::builder()
.application_id(APP_ID)
.build();
app.connect_activate(activate);
app.run()
}
fn activate(app: &gtk::Application)
{
let orchestrator = Arc::new(Mutex::new(Orchestrator::new()));
let mainwindow = MainWindow::builder().build(MainWindowInit
{
app: app.clone(),
orchestrator: orchestrator.clone()
});
let mainwindow = mainwindow.clone();
app.connect_activate(move |app|
{
let orchestrator = Arc::new(Mutex::new(Orchestrator::new()));
let newmainwindow = MainWindow::builder().build("MainWindow", MainWindowInit
{
app: app.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
}

View File

@ -118,7 +118,7 @@ impl UiComponent for MainWindow
}
let mut state = state.borrow_mut();
state.update_active_device(&widgets, false);
state.update_active_device(widgets, false);
}
}

View File

@ -1,8 +1 @@
pub mod uicomponent;
#[deprecated]
pub trait EmbeddedWidgetConnector
{
fn root(&self) -> gtk::Widget;
}
pub mod uicomponent;

View File

@ -35,9 +35,12 @@ pub trait UiComponentState<C: UiComponent>
}
#[must_use]
pub struct UiComponentConnector<C: UiComponent>
{
pub name: String,
pub root: C::Root,
pub widgets: Rc<C::Widgets>,
pub state: Rc<RefCell<C::State>>
}
@ -68,7 +71,7 @@ impl<C: UiComponent> Default for 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 widgets = Rc::new(C::build_widgets(&root, &init));
@ -79,7 +82,9 @@ impl<C: UiComponent> UiComponentBuilder<C>
UiComponentConnector::<C>
{
name: String::from(name),
root,
widgets,
state
}
}
@ -90,7 +95,7 @@ impl<C: UiComponent> From<UiComponentConnector<C>> for gtk::Widget
{
fn from(val: UiComponentConnector<C>) -> Self
{
val.root.into()
val.root.clone().into()
}
}
@ -101,4 +106,14 @@ impl<C: UiComponent> UiComponentConnectorWidget for UiComponentConnector<C>
{
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());
}
}