{"record":{"id":"ea26a3f4b71ad976","repo":"a-b-street/abstreet","slug":"can-t-take-it-s-a-top-level-widget","errorCode":null,"errorMessage":"Can't take({}), it's a top-level widget","messagePattern":"Can't take\\((.+?)\\), it's a top-level widget","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"widgetry/src/widgets/mod.rs","lineNumber":811,"sourceCode":"    fn find_mut(&mut self, name: &str) -> Option<&mut Widget> {\n        if self.id == Some(name.to_string()) {\n            return Some(self);\n        }\n\n        if let Some(container) = self.widget.downcast_mut::<Container>() {\n            for widget in &mut container.members {\n                if let Some(w) = widget.find_mut(name) {\n                    return Some(w);\n                }\n            }\n        }\n\n        None\n    }\n\n    fn take(&mut self, name: &str) -> Option<Widget> {\n        if self.id == Some(name.to_string()) {\n            panic!(\"Can't take({}), it's a top-level widget\", name);\n        }\n\n        if let Some(container) = self.widget.downcast_mut::<Container>() {\n            let mut members = Vec::new();\n            let mut found = None;\n            for mut widget in container.members.drain(..) {\n                if widget.id == Some(name.to_string()) {\n                    found = Some(widget);\n                } else if let Some(w) = widget.take(name) {\n                    found = Some(w);\n                    members.push(widget);\n                } else {\n                    members.push(widget);\n                }\n            }\n            found\n        } else {\n            None","sourceCodeStart":793,"sourceCodeEnd":829,"githubUrl":"https://github.com/a-b-street/abstreet/blob/0964f29315820c91b171b585eb51e300164e9197/widgetry/src/widgets/mod.rs#L793-L829","documentation":"`take` removes a nested named widget from a Panel's tree and returns it, but the top-level widget itself cannot be removed without destroying the Panel. Panics if the requested name matches the top-level widget.","triggerScenarios":"Calling `Panel::take(name)` where `name` is the id of the Panel's top-level (root) widget.","commonSituations":"Assuming take works on any named widget including the root; passing the panel's own name because it was set via `.named(...)` on the root.","solutions":["Use a child/container widget name, not the root's name","If you need to replace the whole content, use replace or set_content instead of take","Check with has_widget and ensure the target is nested"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"if panel.has_widget(name) && name != ROOT_NAME { /* take is safe to attempt */ }","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Never target the root widget with take","Use replace/set_content for top-level changes","Track root's name in a constant to compare against"],"tags":["rust","panel","widgetry","invalid-target"],"backgroundTag":"invalid-argument-value","analyzedSha":"0964f29315820c91b171b585eb51e300164e9197","analyzedAt":"2026-09-13T18:02:03.421Z","contentChangedAt":"2026-09-13T18:02:03.421Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}