move factory to use listbox

This commit is contained in:
2024-03-02 19:34:02 +01:00
parent da5fcc9887
commit 3b20535b5a
3 changed files with 18 additions and 19 deletions

View File

@@ -1,4 +1,6 @@
use crate::gtk::Align;
use relm4::factory::FactoryVecDeque; use relm4::factory::FactoryVecDeque;
use relm4::RelmWidgetExt;
use relm4::{ use relm4::{
actions::{RelmAction, RelmActionGroup}, actions::{RelmAction, RelmActionGroup},
adw, gtk, main_application, Component, ComponentController, ComponentParts, ComponentSender, adw, gtk, main_application, Component, ComponentController, ComponentParts, ComponentSender,
@@ -89,10 +91,13 @@ impl Component for App {
}, },
#[local_ref] #[local_ref]
container_box -> gtk::Box { container_box -> gtk::ListBox {
set_orientation: gtk::Orientation::Vertical, set_valign: Align::Start,
} set_margin_all: 30,
set_css_classes: &["boxed-list"],
},
} }
} }
@@ -115,7 +120,7 @@ impl Component for App {
UnsupportedDialogOutput::CloseApplication => AppMsg::Quit, UnsupportedDialogOutput::CloseApplication => AppMsg::Quit,
}); });
let mut containers = FactoryVecDeque::new(gtk::Box::default(), sender.input_sender()); let mut containers = FactoryVecDeque::new(gtk::ListBox::default(), sender.input_sender());
containers.guard().push_back(3); containers.guard().push_back(3);
let model = Self { let model = Self {
@@ -211,4 +216,3 @@ impl AppWidgets {
} }
} }
} }

View File

@@ -1,5 +1,8 @@
use crate::app::AppMsg; use crate::app::AppMsg;
use gtk::prelude::{BoxExt, ButtonExt, GtkWindowExt, OrientableExt}; use gtk::prelude::{BoxExt, ButtonExt, GtkWindowExt, OrientableExt};
use relm4::adw;
use relm4::adw::prelude::ActionRowExt;
use relm4::adw::prelude::PreferencesRowExt;
use relm4::factory::{DynamicIndex, FactoryComponent, FactorySender, FactoryVecDeque}; use relm4::factory::{DynamicIndex, FactoryComponent, FactorySender, FactoryVecDeque};
use relm4::{gtk, ComponentParts, ComponentSender, RelmApp, RelmWidgetExt, SimpleComponent}; use relm4::{gtk, ComponentParts, ComponentSender, RelmApp, RelmWidgetExt, SimpleComponent};
@@ -21,28 +24,22 @@ impl FactoryComponent for Container {
type CommandOutput = (); type CommandOutput = ();
type Widgets = ContainerWidgets; type Widgets = ContainerWidgets;
type ParentInput = AppMsg; type ParentInput = AppMsg;
type ParentWidget = gtk::Box; type ParentWidget = gtk::ListBox;
view! { view! {
root = gtk::Box { root = adw::ActionRow {
set_orientation: gtk::Orientation::Horizontal, #[watch]
set_spacing: 10, set_title: &self.value.to_string(),
#[name(label)]
gtk::Label {
#[watch]
set_label: &self.value.to_string(),
set_width_chars: 3,
},
#[name(add_button)] #[name(add_button)]
gtk::Button { add_prefix = &gtk::Button {
set_label: "+", set_label: "+",
connect_clicked => ContainerMsg::Start, connect_clicked => ContainerMsg::Start,
}, },
#[name(remove_button)] #[name(remove_button)]
gtk::Button { add_suffix = &gtk::Button {
set_label: "-", set_label: "-",
connect_clicked => ContainerMsg::Start, connect_clicked => ContainerMsg::Start,
}, },
@@ -61,4 +58,3 @@ impl FactoryComponent for Container {
} }
} }
} }

View File

@@ -47,4 +47,3 @@ fn main() {
app.run::<App>(()); app.run::<App>(());
} }