Struct relm4::factory::FactoryVecDeque
source · pub struct FactoryVecDeque<C: FactoryComponent> { /* private fields */ }
Expand description
A container similar to VecDeque
that can be used to store
data associated with components that implement FactoryComponent
.
To access mutable methods of the factory, create a guard using Self::guard
.
Implementations§
source§impl<C: FactoryComponent> FactoryVecDeque<C>
impl<C: FactoryComponent> FactoryVecDeque<C>
sourcepub fn new(
widget: C::ParentWidget,
parent_sender: &Sender<C::ParentInput>
) -> Self
pub fn new( widget: C::ParentWidget, parent_sender: &Sender<C::ParentInput> ) -> Self
Creates a new FactoryVecDeque
.
Examples found in repository?
139 140 141 142 143 144 145 146 147 148 149 150 151 152
fn init(
_: Self::Init,
root: &Self::Root,
sender: ComponentSender<Self>,
) -> ComponentParts<Self> {
let model = App {
tasks: FactoryVecDeque::new(gtk::ListBox::default(), sender.input_sender()),
};
let task_list_box = model.tasks.widget();
let widgets = view_output!();
ComponentParts { model, widgets }
}
More examples
169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184
fn init(
counter: Self::Init,
root: &Self::Root,
sender: ComponentSender<Self>,
) -> ComponentParts<Self> {
let counters = FactoryVecDeque::new(gtk::Box::default(), sender.input_sender());
let model = App {
created_widgets: counter,
counters,
};
let counter_box = model.counters.widget();
let widgets = view_output!();
ComponentParts { model, widgets }
}
191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206
fn init(
counter: Self::Init,
root: &Self::Root,
sender: ComponentSender<Self>,
) -> ComponentParts<Self> {
let counters = FactoryVecDeque::new(gtk::Grid::default(), sender.input_sender());
let model = App {
created_widgets: counter,
counters,
};
let counter_grid = model.counters.widget();
let widgets = view_output!();
ComponentParts { model, widgets }
}
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101
fn init(
_init: Self::Init,
root: &Self::Root,
sender: ComponentSender<Self>,
) -> ComponentParts<Self> {
let factory_box = gtk::Box::default();
let model = App {
counters: FactoryVecDeque::new(factory_box.clone(), sender.input_sender()),
created_counters: 0,
entry: gtk::EntryBuffer::new(None),
};
let widgets = view_output!();
ComponentParts { model, widgets }
}
sourcepub fn guard(&mut self) -> FactoryVecDequeGuard<'_, C>
pub fn guard(&mut self) -> FactoryVecDequeGuard<'_, C>
Provides a FactoryVecDequeGuard
that can be used to edit the factory.
The changes will be rendered on the widgets after the guard goes out of scope.
Examples found in repository?
More examples
208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238
fn update(&mut self, msg: Self::Input, _sender: ComponentSender<Self>) {
let mut counters_guard = self.counters.guard();
match msg {
AppMsg::AddCounter => {
counters_guard.push_back(self.created_widgets);
self.created_widgets = self.created_widgets.wrapping_add(1);
}
AppMsg::RemoveCounter => {
counters_guard.pop_back();
}
AppMsg::SendFront(index) => {
counters_guard.move_front(index.current_index());
}
AppMsg::MoveDown(index) => {
let index = index.current_index();
let new_index = index + 1;
// Already at the end?
if new_index < counters_guard.len() {
counters_guard.move_to(index, new_index);
}
}
AppMsg::MoveUp(index) => {
let index = index.current_index();
// Already at the start?
if index != 0 {
counters_guard.move_to(index, index - 1);
}
}
}
}
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132
fn update(&mut self, message: Self::Input, _sender: ComponentSender<Self>) {
match message {
AppMsg::AddCounters => {
let text = self.entry.text();
if let Ok(v) = text.parse::<i32>() {
let mut guard = self.counters.guard();
if v.is_positive() {
// add as many counters as user entered
for _ in 0..v {
guard.push_back(self.created_counters);
self.created_counters += 1;
}
} else if v.is_negative() {
// remove counters
for _ in v..0 {
guard.pop_front();
}
}
// clearing the entry value clears the entry widget
self.entry.set_text("");
}
}
AppMsg::Clicked(index) => {
if let Some(counter) = self.counters.guard().get_mut(index.current_index()) {
counter.value = counter.value.wrapping_sub(1);
}
}
}
}
186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218
fn update(&mut self, msg: Self::Input, _sender: ComponentSender<Self>) {
let mut counters_guard = self.counters.guard();
match msg {
AppMsg::AddCounter => {
counters_guard.push_back(self.created_widgets);
self.created_widgets = self.created_widgets.wrapping_add(1);
}
AppMsg::RemoveCounter => {
counters_guard.pop_back();
}
AppMsg::SendFront(index) => {
counters_guard.move_front(index.current_index());
}
AppMsg::MoveDown(index) => {
let index = index.current_index();
let new_index = index + 1;
// Already at the end?
if new_index < counters_guard.len() {
counters_guard.move_to(index, new_index);
}
}
AppMsg::MoveUp(index) => {
let index = index.current_index();
// Already at the start?
if index != 0 {
counters_guard.move_to(index, index - 1);
}
}
AppMsg::Remove(index) => {
counters_guard.remove(index.current_index());
}
}
}
sourcepub fn len(&self) -> usize
pub fn len(&self) -> usize
Returns the number of elements in the FactoryVecDeque
.
Examples found in repository?
208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238
fn update(&mut self, msg: Self::Input, _sender: ComponentSender<Self>) {
let mut counters_guard = self.counters.guard();
match msg {
AppMsg::AddCounter => {
counters_guard.push_back(self.created_widgets);
self.created_widgets = self.created_widgets.wrapping_add(1);
}
AppMsg::RemoveCounter => {
counters_guard.pop_back();
}
AppMsg::SendFront(index) => {
counters_guard.move_front(index.current_index());
}
AppMsg::MoveDown(index) => {
let index = index.current_index();
let new_index = index + 1;
// Already at the end?
if new_index < counters_guard.len() {
counters_guard.move_to(index, new_index);
}
}
AppMsg::MoveUp(index) => {
let index = index.current_index();
// Already at the start?
if index != 0 {
counters_guard.move_to(index, index - 1);
}
}
}
}
More examples
186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218
fn update(&mut self, msg: Self::Input, _sender: ComponentSender<Self>) {
let mut counters_guard = self.counters.guard();
match msg {
AppMsg::AddCounter => {
counters_guard.push_back(self.created_widgets);
self.created_widgets = self.created_widgets.wrapping_add(1);
}
AppMsg::RemoveCounter => {
counters_guard.pop_back();
}
AppMsg::SendFront(index) => {
counters_guard.move_front(index.current_index());
}
AppMsg::MoveDown(index) => {
let index = index.current_index();
let new_index = index + 1;
// Already at the end?
if new_index < counters_guard.len() {
counters_guard.move_to(index, new_index);
}
}
AppMsg::MoveUp(index) => {
let index = index.current_index();
// Already at the start?
if index != 0 {
counters_guard.move_to(index, index - 1);
}
}
AppMsg::Remove(index) => {
counters_guard.remove(index.current_index());
}
}
}
sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Returns true if the FactoryVecDeque
is empty.
sourcepub fn broadcast(&self, msg: C::Input)where
C::Input: Clone,
pub fn broadcast(&self, msg: C::Input)where C::Input: Clone,
Send clone of a message to all of the elements.
sourcepub fn get(&self, index: usize) -> Option<&C>
pub fn get(&self, index: usize) -> Option<&C>
Tries to get an immutable reference to the model of one element.
Returns None
if index
is invalid.
sourcepub fn back(&self) -> Option<&C>
pub fn back(&self) -> Option<&C>
Provides a reference to the model of the back element.
Returns None
if the deque is empty.
sourcepub fn front(&self) -> Option<&C>
pub fn front(&self) -> Option<&C>
Provides a reference to the model of the front element.
Returns None
if the deque is empty.
sourcepub const fn widget(&self) -> &C::ParentWidget
pub const fn widget(&self) -> &C::ParentWidget
Returns the widget all components are attached to.
Examples found in repository?
139 140 141 142 143 144 145 146 147 148 149 150 151 152
fn init(
_: Self::Init,
root: &Self::Root,
sender: ComponentSender<Self>,
) -> ComponentParts<Self> {
let model = App {
tasks: FactoryVecDeque::new(gtk::ListBox::default(), sender.input_sender()),
};
let task_list_box = model.tasks.widget();
let widgets = view_output!();
ComponentParts { model, widgets }
}
More examples
169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184
fn init(
counter: Self::Init,
root: &Self::Root,
sender: ComponentSender<Self>,
) -> ComponentParts<Self> {
let counters = FactoryVecDeque::new(gtk::Box::default(), sender.input_sender());
let model = App {
created_widgets: counter,
counters,
};
let counter_box = model.counters.widget();
let widgets = view_output!();
ComponentParts { model, widgets }
}
191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206
fn init(
counter: Self::Init,
root: &Self::Root,
sender: ComponentSender<Self>,
) -> ComponentParts<Self> {
let counters = FactoryVecDeque::new(gtk::Grid::default(), sender.input_sender());
let model = App {
created_widgets: counter,
counters,
};
let counter_grid = model.counters.widget();
let widgets = view_output!();
ComponentParts { model, widgets }
}
sourcepub fn iter(
&self
) -> impl Iterator<Item = &C> + DoubleEndedIterator + ExactSizeIterator + FusedIterator
pub fn iter( &self ) -> impl Iterator<Item = &C> + DoubleEndedIterator + ExactSizeIterator + FusedIterator
Returns an iterator over the components.
sourcepub fn from_vec(
component_vec: Vec<C::Init>,
widget: C::ParentWidget,
parent_sender: &Sender<C::ParentInput>
) -> Self
pub fn from_vec( component_vec: Vec<C::Init>, widget: C::ParentWidget, parent_sender: &Sender<C::ParentInput> ) -> Self
Creates a FactoryVecDeque from a Vec
Trait Implementations§
source§impl<C> Clone for FactoryVecDeque<C>where
C: CloneableFactoryComponent + FactoryComponent,
impl<C> Clone for FactoryVecDeque<C>where C: CloneableFactoryComponent + FactoryComponent,
Implements the Clone Trait for FactoryVecDeque<C>
where C is Cloneable