tooltip wrap, clippy
[skip ci]
This commit is contained in:
14
Cargo.lock
generated
14
Cargo.lock
generated
@@ -6375,6 +6375,19 @@ dependencies = [
|
|||||||
"tokio-util",
|
"tokio-util",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "wayvr_ipc"
|
||||||
|
version = "0.1.0"
|
||||||
|
source = "git+https://github.com/olekolek1000/wayvr-ipc.git?rev=6d253ef9e36db0f181566030a4990454ecb60395#6d253ef9e36db0f181566030a4990454ecb60395"
|
||||||
|
dependencies = [
|
||||||
|
"anyhow",
|
||||||
|
"bytes",
|
||||||
|
"log",
|
||||||
|
"serde",
|
||||||
|
"serde_json",
|
||||||
|
"smallvec",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "web-sys"
|
name = "web-sys"
|
||||||
version = "0.3.83"
|
version = "0.3.83"
|
||||||
@@ -7042,6 +7055,7 @@ dependencies = [
|
|||||||
"wayland-client",
|
"wayland-client",
|
||||||
"wayland-egl",
|
"wayland-egl",
|
||||||
"wayvr-ipc",
|
"wayvr-ipc",
|
||||||
|
"wayvr_ipc",
|
||||||
"wgui",
|
"wgui",
|
||||||
"winit",
|
"winit",
|
||||||
"wlx-capture",
|
"wlx-capture",
|
||||||
|
|||||||
@@ -13,10 +13,7 @@ use wgui::{
|
|||||||
widget::{label::WidgetLabel, rectangle::WidgetRectangle},
|
widget::{label::WidgetLabel, rectangle::WidgetRectangle},
|
||||||
windowing::{WguiWindow, WguiWindowParams, WguiWindowParamsExtra, WguiWindowPlacement},
|
windowing::{WguiWindow, WguiWindowParams, WguiWindowParamsExtra, WguiWindowPlacement},
|
||||||
};
|
};
|
||||||
use wlx_common::{
|
use wlx_common::{dash_interface::BoxDashInterface, timestep::Timestep};
|
||||||
dash_interface::{self, BoxDashInterface},
|
|
||||||
timestep::Timestep,
|
|
||||||
};
|
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
assets, settings,
|
assets, settings,
|
||||||
@@ -173,8 +170,6 @@ impl Frontend {
|
|||||||
let mut layout = self.layout.borrow_mut();
|
let mut layout = self.layout.borrow_mut();
|
||||||
|
|
||||||
tab.update(TabUpdateParams {
|
tab.update(TabUpdateParams {
|
||||||
globals: &self.globals,
|
|
||||||
frontend_tasks: &self.tasks,
|
|
||||||
layout: &mut layout,
|
layout: &mut layout,
|
||||||
interface: &mut self.interface,
|
interface: &mut self.interface,
|
||||||
})?;
|
})?;
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ use wgui::{
|
|||||||
};
|
};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
frontend::{Frontend, FrontendTask},
|
frontend::FrontendTask,
|
||||||
settings,
|
settings,
|
||||||
tab::{Tab, TabParams, TabType},
|
tab::{Tab, TabParams, TabType},
|
||||||
various,
|
various,
|
||||||
|
|||||||
@@ -33,8 +33,6 @@ pub struct TabParams<'a> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub struct TabUpdateParams<'a> {
|
pub struct TabUpdateParams<'a> {
|
||||||
pub globals: &'a WguiGlobals,
|
|
||||||
pub frontend_tasks: &'a FrontendTasks,
|
|
||||||
pub layout: &'a mut Layout,
|
pub layout: &'a mut Layout,
|
||||||
pub interface: &'a mut BoxDashInterface,
|
pub interface: &'a mut BoxDashInterface,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -51,7 +51,6 @@ impl TabProcesses {
|
|||||||
layout: params.layout,
|
layout: params.layout,
|
||||||
parent_id: state.get_widget_id("process_list_parent")?,
|
parent_id: state.get_widget_id("process_list_parent")?,
|
||||||
globals: params.globals.clone(),
|
globals: params.globals.clone(),
|
||||||
frontend_tasks: params.frontend_tasks.clone(),
|
|
||||||
})?,
|
})?,
|
||||||
state,
|
state,
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -9,12 +9,12 @@ use wgui::{
|
|||||||
i18n::Translation,
|
i18n::Translation,
|
||||||
layout::{Layout, LayoutTask, LayoutTasks, WidgetID},
|
layout::{Layout, LayoutTask, LayoutTasks, WidgetID},
|
||||||
renderer_vk::{
|
renderer_vk::{
|
||||||
text::{FontWeight, TextStyle},
|
text::{FontWeight, HorizontalAlign, TextStyle},
|
||||||
util::centered_matrix,
|
util::centered_matrix,
|
||||||
},
|
},
|
||||||
taffy::{
|
taffy::{
|
||||||
self,
|
self,
|
||||||
prelude::{length, percent},
|
prelude::{auto, length, percent},
|
||||||
},
|
},
|
||||||
widget::{
|
widget::{
|
||||||
div::WidgetDiv,
|
div::WidgetDiv,
|
||||||
@@ -102,6 +102,10 @@ impl ToastManager {
|
|||||||
top: length(8.0),
|
top: length(8.0),
|
||||||
bottom: length(8.0),
|
bottom: length(8.0),
|
||||||
},
|
},
|
||||||
|
max_size: taffy::Size {
|
||||||
|
width: length(400.0),
|
||||||
|
height: auto(),
|
||||||
|
},
|
||||||
..Default::default()
|
..Default::default()
|
||||||
},
|
},
|
||||||
)?;
|
)?;
|
||||||
@@ -114,6 +118,8 @@ impl ToastManager {
|
|||||||
content,
|
content,
|
||||||
style: TextStyle {
|
style: TextStyle {
|
||||||
weight: Some(FontWeight::Bold),
|
weight: Some(FontWeight::Bold),
|
||||||
|
align: Some(HorizontalAlign::Center),
|
||||||
|
wrap: true,
|
||||||
..Default::default()
|
..Default::default()
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -17,6 +17,8 @@ use wlx_common::dash_interface::BoxDashInterface;
|
|||||||
|
|
||||||
use crate::util::desktop_finder;
|
use crate::util::desktop_finder;
|
||||||
|
|
||||||
|
// the compiler wants to scream
|
||||||
|
#[allow(irrefutable_let_patterns)]
|
||||||
pub fn get_desktop_file_icon_path(desktop_file: &desktop_finder::DesktopFile) -> AssetPathOwned {
|
pub fn get_desktop_file_icon_path(desktop_file: &desktop_finder::DesktopFile) -> AssetPathOwned {
|
||||||
/*
|
/*
|
||||||
FIXME: why is the compiler complaining about trailing irrefutable patterns there?!?!
|
FIXME: why is the compiler complaining about trailing irrefutable patterns there?!?!
|
||||||
|
|||||||
@@ -1,19 +1,15 @@
|
|||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
|
|
||||||
use anyhow::Context;
|
|
||||||
use wayvr_ipc::packet_server;
|
use wayvr_ipc::packet_server;
|
||||||
use wgui::{
|
use wgui::{
|
||||||
assets::AssetPath,
|
assets::AssetPath,
|
||||||
components::{button::ComponentButton, checkbox::ComponentCheckbox, slider::ComponentSlider},
|
components::button::ComponentButton,
|
||||||
event::StyleSetRequest,
|
|
||||||
globals::WguiGlobals,
|
globals::WguiGlobals,
|
||||||
i18n::Translation,
|
i18n::Translation,
|
||||||
layout::{Layout, WidgetID},
|
layout::{Layout, WidgetID},
|
||||||
parser::{Fetchable, ParseDocumentParams, ParserState},
|
parser::{Fetchable, ParseDocumentParams, ParserState},
|
||||||
taffy::prelude::length,
|
widget::ConstructEssentials,
|
||||||
widget::{ConstructEssentials, label::WidgetLabel, rectangle::WidgetRectangle},
|
|
||||||
};
|
};
|
||||||
use wlx_common::dash_interface::{self, BoxDashInterface};
|
use wlx_common::dash_interface::BoxDashInterface;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
frontend::{FrontendTask, FrontendTasks},
|
frontend::{FrontendTask, FrontendTasks},
|
||||||
@@ -91,7 +87,7 @@ impl View {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn update(&mut self, layout: &mut Layout, interface: &mut BoxDashInterface) -> anyhow::Result<()> {
|
pub fn update(&mut self, _layout: &mut Layout, interface: &mut BoxDashInterface) -> anyhow::Result<()> {
|
||||||
for task in self.tasks.drain() {
|
for task in self.tasks.drain() {
|
||||||
match task {
|
match task {
|
||||||
Task::SetVisible(v) => self.action_set_visible(interface, v),
|
Task::SetVisible(v) => self.action_set_visible(interface, v),
|
||||||
|
|||||||
@@ -22,7 +22,6 @@ use wgui::{
|
|||||||
use wlx_common::dash_interface::BoxDashInterface;
|
use wlx_common::dash_interface::BoxDashInterface;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
frontend::FrontendTasks,
|
|
||||||
task::Tasks,
|
task::Tasks,
|
||||||
util::{
|
util::{
|
||||||
self,
|
self,
|
||||||
@@ -39,7 +38,6 @@ enum Task {
|
|||||||
|
|
||||||
pub struct Params<'a> {
|
pub struct Params<'a> {
|
||||||
pub globals: WguiGlobals,
|
pub globals: WguiGlobals,
|
||||||
pub frontend_tasks: FrontendTasks,
|
|
||||||
pub layout: &'a mut Layout,
|
pub layout: &'a mut Layout,
|
||||||
pub parent_id: WidgetID,
|
pub parent_id: WidgetID,
|
||||||
}
|
}
|
||||||
@@ -48,7 +46,6 @@ pub struct View {
|
|||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
pub parser_state: ParserState,
|
pub parser_state: ParserState,
|
||||||
tasks: Tasks<Task>,
|
tasks: Tasks<Task>,
|
||||||
frontend_tasks: FrontendTasks,
|
|
||||||
globals: WguiGlobals,
|
globals: WguiGlobals,
|
||||||
id_list_parent: WidgetID,
|
id_list_parent: WidgetID,
|
||||||
}
|
}
|
||||||
@@ -71,7 +68,6 @@ impl View {
|
|||||||
Ok(Self {
|
Ok(Self {
|
||||||
parser_state,
|
parser_state,
|
||||||
tasks,
|
tasks,
|
||||||
frontend_tasks: params.frontend_tasks,
|
|
||||||
globals: params.globals,
|
globals: params.globals,
|
||||||
id_list_parent: list_parent.id,
|
id_list_parent: list_parent.id,
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -393,7 +393,7 @@ fn register_event_mouse_release(
|
|||||||
|
|
||||||
#[allow(clippy::too_many_lines)]
|
#[allow(clippy::too_many_lines)]
|
||||||
pub fn construct(ess: &mut ConstructEssentials, params: Params) -> anyhow::Result<(WidgetPair, Rc<ComponentButton>)> {
|
pub fn construct(ess: &mut ConstructEssentials, params: Params) -> anyhow::Result<(WidgetPair, Rc<ComponentButton>)> {
|
||||||
let mut globals = ess.layout.state.globals.clone();
|
let globals = ess.layout.state.globals.clone();
|
||||||
let mut style = params.style;
|
let mut style = params.style;
|
||||||
|
|
||||||
// force-override style
|
// force-override style
|
||||||
|
|||||||
@@ -382,7 +382,7 @@ impl Layout {
|
|||||||
|
|
||||||
let mut iter = |idx: usize| -> anyhow::Result<bool> {
|
let mut iter = |idx: usize| -> anyhow::Result<bool> {
|
||||||
let child_id = self.state.tree.get_child_id(parent_node_id, idx);
|
let child_id = self.state.tree.get_child_id(parent_node_id, idx);
|
||||||
self.push_event_widget(child_id, event, event_result, alterables, user_data, false)?;
|
self.push_event_widget(child_id, event, event_result, alterables, user_data)?;
|
||||||
Ok(!event_result.can_propagate())
|
Ok(!event_result.can_propagate())
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -403,7 +403,6 @@ impl Layout {
|
|||||||
event_result: &mut EventResult,
|
event_result: &mut EventResult,
|
||||||
alterables: &mut EventAlterables,
|
alterables: &mut EventAlterables,
|
||||||
user_data: &mut (&'a mut U1, &'a mut U2),
|
user_data: &mut (&'a mut U1, &'a mut U2),
|
||||||
is_root_node: bool,
|
|
||||||
) -> anyhow::Result<()> {
|
) -> anyhow::Result<()> {
|
||||||
let l = self.state.tree.layout(node_id)?;
|
let l = self.state.tree.layout(node_id)?;
|
||||||
let Some(widget_id) = self.state.tree.get_node_context(node_id).copied() else {
|
let Some(widget_id) = self.state.tree.get_node_context(node_id).copied() else {
|
||||||
@@ -495,7 +494,6 @@ impl Layout {
|
|||||||
&mut event_result,
|
&mut event_result,
|
||||||
&mut alterables,
|
&mut alterables,
|
||||||
&mut (user1, user2),
|
&mut (user1, user2),
|
||||||
true,
|
|
||||||
)?;
|
)?;
|
||||||
self.process_alterables(alterables)?;
|
self.process_alterables(alterables)?;
|
||||||
Ok(event_result)
|
Ok(event_result)
|
||||||
|
|||||||
@@ -39,11 +39,11 @@ impl WidgetSprite {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_color(&mut self, color: drawing::Color) {
|
pub const fn set_color(&mut self, color: drawing::Color) {
|
||||||
self.params.color = Some(color);
|
self.params.color = Some(color);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_color(&self) -> Option<drawing::Color> {
|
pub const fn get_color(&self) -> Option<drawing::Color> {
|
||||||
self.params.color
|
self.params.color
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -83,6 +83,12 @@ impl DashInterfaceEmulated {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Default for DashInterfaceEmulated {
|
||||||
|
fn default() -> Self {
|
||||||
|
Self::new()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl DashInterface for DashInterfaceEmulated {
|
impl DashInterface for DashInterfaceEmulated {
|
||||||
fn display_create(&mut self, params: WvrDisplayCreateParams) -> anyhow::Result<WvrDisplayHandle> {
|
fn display_create(&mut self, params: WvrDisplayCreateParams) -> anyhow::Result<WvrDisplayHandle> {
|
||||||
let res = self.displays.add(EmuDisplay {
|
let res = self.displays.add(EmuDisplay {
|
||||||
@@ -108,10 +114,16 @@ impl DashInterface for DashInterfaceEmulated {
|
|||||||
Ok(self.displays.iter().map(|(handle, disp)| disp.to(handle)).collect())
|
Ok(self.displays.iter().map(|(handle, disp)| disp.to(handle)).collect())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn display_remove(&mut self, handle: WvrDisplayHandle) -> anyhow::Result<()> {
|
fn display_remove(&mut self, wvr_handle: WvrDisplayHandle) -> anyhow::Result<()> {
|
||||||
self
|
let handle = EmuDisplayHandle::new(wvr_handle.idx, wvr_handle.generation);
|
||||||
.displays
|
|
||||||
.remove(&EmuDisplayHandle::new(handle.idx, handle.generation));
|
for (_, process) in self.processes.iter() {
|
||||||
|
if process.display_handle == wvr_handle {
|
||||||
|
anyhow::bail!("Cannot remove display: stop {} process first.", process.name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
self.displays.remove(&handle);
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,170 +1,166 @@
|
|||||||
#[macro_export]
|
#[macro_export]
|
||||||
macro_rules! gen_id {
|
macro_rules! gen_id {
|
||||||
(
|
(
|
||||||
$container_name:ident,
|
$container_name:ident,
|
||||||
$instance_name:ident,
|
$instance_name:ident,
|
||||||
$cell_name:ident,
|
$cell_name:ident,
|
||||||
$handle_name:ident) => {
|
$handle_name:ident) => {
|
||||||
//ThingCell
|
//ThingCell
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct $cell_name {
|
pub struct $cell_name {
|
||||||
pub obj: $instance_name,
|
pub obj: $instance_name,
|
||||||
pub generation: u64,
|
pub generation: u64,
|
||||||
}
|
}
|
||||||
|
|
||||||
//ThingVec
|
//ThingVec
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct $container_name {
|
pub struct $container_name {
|
||||||
// Vec<Option<ThingCell>>
|
// Vec<Option<ThingCell>>
|
||||||
pub vec: Vec<Option<$cell_name>>,
|
pub vec: Vec<Option<$cell_name>>,
|
||||||
|
|
||||||
cur_generation: u64,
|
cur_generation: u64,
|
||||||
}
|
}
|
||||||
|
|
||||||
//ThingHandle
|
//ThingHandle
|
||||||
#[derive(Default, Debug, Clone, Copy, PartialEq, Hash, Eq)]
|
#[derive(Default, Debug, Clone, Copy, PartialEq, Hash, Eq)]
|
||||||
pub struct $handle_name {
|
pub struct $handle_name {
|
||||||
idx: u32,
|
idx: u32,
|
||||||
generation: u64,
|
generation: u64,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
impl $handle_name {
|
impl $handle_name {
|
||||||
pub const fn reset(&mut self) {
|
pub const fn reset(&mut self) {
|
||||||
self.generation = 0;
|
self.generation = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub const fn is_set(&self) -> bool {
|
pub const fn is_set(&self) -> bool {
|
||||||
self.generation > 0
|
self.generation > 0
|
||||||
}
|
}
|
||||||
|
|
||||||
pub const fn id(&self) -> u32 {
|
pub const fn id(&self) -> u32 {
|
||||||
self.idx
|
self.idx
|
||||||
}
|
}
|
||||||
|
|
||||||
pub const fn new(idx: u32, generation: u64) -> Self {
|
pub const fn new(idx: u32, generation: u64) -> Self {
|
||||||
Self { idx, generation }
|
Self { idx, generation }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//ThingVec
|
//ThingVec
|
||||||
impl $container_name {
|
impl $container_name {
|
||||||
pub const fn new() -> Self {
|
#[allow(clippy::new_without_default)]
|
||||||
Self {
|
pub const fn new() -> Self {
|
||||||
vec: Vec::new(),
|
Self {
|
||||||
cur_generation: 0,
|
vec: Vec::new(),
|
||||||
}
|
cur_generation: 0,
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn iter(&self) -> impl Iterator<Item = ($handle_name, &$instance_name)> {
|
pub fn iter(&self) -> impl Iterator<Item = ($handle_name, &$instance_name)> {
|
||||||
self.vec.iter().enumerate().filter_map(|(idx, opt_cell)| {
|
self.vec.iter().enumerate().filter_map(|(idx, opt_cell)| {
|
||||||
opt_cell.as_ref().map(|cell| {
|
opt_cell.as_ref().map(|cell| {
|
||||||
let handle = $container_name::get_handle(&cell, idx);
|
let handle = $container_name::get_handle(&cell, idx);
|
||||||
(handle, &cell.obj)
|
(handle, &cell.obj)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn iter_mut(
|
pub fn iter_mut(&mut self) -> impl Iterator<Item = ($handle_name, &mut $instance_name)> {
|
||||||
&mut self,
|
self.vec.iter_mut().enumerate().filter_map(|(idx, opt_cell)| {
|
||||||
) -> impl Iterator<Item = ($handle_name, &mut $instance_name)> {
|
opt_cell.as_mut().map(|cell| {
|
||||||
self.vec
|
let handle = $container_name::get_handle(&cell, idx);
|
||||||
.iter_mut()
|
(handle, &mut cell.obj)
|
||||||
.enumerate()
|
})
|
||||||
.filter_map(|(idx, opt_cell)| {
|
})
|
||||||
opt_cell.as_mut().map(|cell| {
|
}
|
||||||
let handle = $container_name::get_handle(&cell, idx);
|
|
||||||
(handle, &mut cell.obj)
|
|
||||||
})
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
pub const fn get_handle(cell: &$cell_name, idx: usize) -> $handle_name {
|
pub const fn get_handle(cell: &$cell_name, idx: usize) -> $handle_name {
|
||||||
$handle_name {
|
$handle_name {
|
||||||
idx: idx as u32,
|
idx: idx as u32,
|
||||||
generation: cell.generation,
|
generation: cell.generation,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn find_unused_idx(&mut self) -> Option<u32> {
|
fn find_unused_idx(&mut self) -> Option<u32> {
|
||||||
for (num, obj) in self.vec.iter().enumerate() {
|
for (num, obj) in self.vec.iter().enumerate() {
|
||||||
if obj.is_none() {
|
if obj.is_none() {
|
||||||
return Some(num as u32);
|
return Some(num as u32);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn add(&mut self, obj: $instance_name) -> $handle_name {
|
pub fn add(&mut self, obj: $instance_name) -> $handle_name {
|
||||||
self.cur_generation += 1;
|
self.cur_generation += 1;
|
||||||
let generation = self.cur_generation;
|
let generation = self.cur_generation;
|
||||||
|
|
||||||
let unused_idx = self.find_unused_idx();
|
let unused_idx = self.find_unused_idx();
|
||||||
|
|
||||||
let idx = if let Some(idx) = unused_idx {
|
let idx = if let Some(idx) = unused_idx {
|
||||||
idx
|
idx
|
||||||
} else {
|
} else {
|
||||||
self.vec.len() as u32
|
self.vec.len() as u32
|
||||||
};
|
};
|
||||||
|
|
||||||
let handle = $handle_name { idx, generation };
|
let handle = $handle_name { idx, generation };
|
||||||
|
|
||||||
let cell = $cell_name { obj, generation };
|
let cell = $cell_name { obj, generation };
|
||||||
|
|
||||||
if let Some(idx) = unused_idx {
|
if let Some(idx) = unused_idx {
|
||||||
self.vec[idx as usize] = Some(cell);
|
self.vec[idx as usize] = Some(cell);
|
||||||
} else {
|
} else {
|
||||||
self.vec.push(Some(cell))
|
self.vec.push(Some(cell))
|
||||||
}
|
}
|
||||||
|
|
||||||
handle
|
handle
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn remove(&mut self, handle: &$handle_name) {
|
pub fn remove(&mut self, handle: &$handle_name) {
|
||||||
// Out of bounds, ignore
|
// Out of bounds, ignore
|
||||||
if handle.idx as usize >= self.vec.len() {
|
if handle.idx as usize >= self.vec.len() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Remove only if the generation matches
|
// Remove only if the generation matches
|
||||||
if let Some(cell) = &self.vec[handle.idx as usize] {
|
if let Some(cell) = &self.vec[handle.idx as usize] {
|
||||||
if cell.generation == handle.generation {
|
if cell.generation == handle.generation {
|
||||||
self.vec[handle.idx as usize] = None;
|
self.vec[handle.idx as usize] = None;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get(&self, handle: &$handle_name) -> Option<&$instance_name> {
|
pub fn get(&self, handle: &$handle_name) -> Option<&$instance_name> {
|
||||||
// Out of bounds, ignore
|
// Out of bounds, ignore
|
||||||
if handle.idx as usize >= self.vec.len() {
|
if handle.idx as usize >= self.vec.len() {
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(cell) = &self.vec[handle.idx as usize] {
|
if let Some(cell) = &self.vec[handle.idx as usize] {
|
||||||
if cell.generation == handle.generation {
|
if cell.generation == handle.generation {
|
||||||
return Some(&cell.obj);
|
return Some(&cell.obj);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_mut(&mut self, handle: &$handle_name) -> Option<&mut $instance_name> {
|
pub fn get_mut(&mut self, handle: &$handle_name) -> Option<&mut $instance_name> {
|
||||||
// Out of bounds, ignore
|
// Out of bounds, ignore
|
||||||
if handle.idx as usize >= self.vec.len() {
|
if handle.idx as usize >= self.vec.len() {
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(cell) = &mut self.vec[handle.idx as usize] {
|
if let Some(cell) = &mut self.vec[handle.idx as usize] {
|
||||||
if cell.generation == handle.generation {
|
if cell.generation == handle.generation {
|
||||||
return Some(&mut cell.obj);
|
return Some(&mut cell.obj);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Example usage:
|
/* Example usage:
|
||||||
|
|||||||
Reference in New Issue
Block a user