mirror of
https://github.com/13hannes11/toolbx-tuner.git
synced 2024-09-03 23:21:00 +02:00
convert to hashmap isntead of list
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
use crate::gtk::Align;
|
use crate::gtk::Align;
|
||||||
use relm4::factory::FactoryVecDeque;
|
use relm4::factory::FactoryHashMap;
|
||||||
use relm4::RelmWidgetExt;
|
use relm4::RelmWidgetExt;
|
||||||
use relm4::{
|
use relm4::{
|
||||||
actions::{RelmAction, RelmActionGroup},
|
actions::{RelmAction, RelmActionGroup},
|
||||||
@@ -21,7 +21,7 @@ use crate::modals::unsupported::UnsupportedDialogOutput;
|
|||||||
pub(super) struct App {
|
pub(super) struct App {
|
||||||
unsupported_dialog: Controller<UnsupportedDialog>,
|
unsupported_dialog: Controller<UnsupportedDialog>,
|
||||||
about_dialog: Controller<AboutDialog>,
|
about_dialog: Controller<AboutDialog>,
|
||||||
containers: FactoryVecDeque<Container>,
|
containers: FactoryHashMap<String, Container>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
@@ -120,8 +120,9 @@ impl Component for App {
|
|||||||
UnsupportedDialogOutput::CloseApplication => AppMsg::Quit,
|
UnsupportedDialogOutput::CloseApplication => AppMsg::Quit,
|
||||||
});
|
});
|
||||||
|
|
||||||
let mut containers = FactoryVecDeque::new(gtk::ListBox::default(), sender.input_sender());
|
let mut containers = FactoryHashMap::new(gtk::ListBox::default(), sender.input_sender());
|
||||||
containers.guard().push_back(3);
|
containers.insert("123".to_string(), 2);
|
||||||
|
containers.insert("124".to_string(), 3);
|
||||||
|
|
||||||
let model = Self {
|
let model = Self {
|
||||||
about_dialog,
|
about_dialog,
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ use relm4::{gtk, ComponentParts, ComponentSender, RelmApp, RelmWidgetExt, Simple
|
|||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct Container {
|
pub struct Container {
|
||||||
|
hash: String,
|
||||||
value: u8,
|
value: u8,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -25,29 +26,27 @@ impl FactoryComponent for Container {
|
|||||||
type Widgets = ContainerWidgets;
|
type Widgets = ContainerWidgets;
|
||||||
type ParentInput = AppMsg;
|
type ParentInput = AppMsg;
|
||||||
type ParentWidget = gtk::ListBox;
|
type ParentWidget = gtk::ListBox;
|
||||||
|
type Index = String;
|
||||||
|
|
||||||
view! {
|
view! {
|
||||||
root = adw::ActionRow {
|
root = adw::ActionRow {
|
||||||
#[watch]
|
#[watch]
|
||||||
set_title: &self.value.to_string(),
|
set_title: &self.hash,
|
||||||
|
|
||||||
|
|
||||||
#[name(add_button)]
|
#[name(add_button)]
|
||||||
add_prefix = >k::Button {
|
|
||||||
set_label: "+",
|
|
||||||
connect_clicked => ContainerMsg::Start,
|
|
||||||
},
|
|
||||||
|
|
||||||
#[name(remove_button)]
|
|
||||||
add_suffix = >k::Button {
|
add_suffix = >k::Button {
|
||||||
set_label: "-",
|
#[watch]
|
||||||
|
set_label: &self.value.to_string(),
|
||||||
connect_clicked => ContainerMsg::Start,
|
connect_clicked => ContainerMsg::Start,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn init_model(value: Self::Init, _index: &DynamicIndex, _sender: FactorySender<Self>) -> Self {
|
fn init_model(value: Self::Init, index: &Self::Index, _sender: FactorySender<Self>) -> Self {
|
||||||
Self { value }
|
Self {
|
||||||
|
hash: index.clone(),
|
||||||
|
value,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn update(&mut self, msg: Self::Input, _sender: FactorySender<Self>) {
|
fn update(&mut self, msg: Self::Input, _sender: FactorySender<Self>) {
|
||||||
|
|||||||
Reference in New Issue
Block a user