widget:global_state: activate navigate() method

* allow widgets to nagivate to other widget context

Signed-off-by: Ralf Zerres <ralf.zerres@networkx.de>
This commit is contained in:
2021-03-03 11:48:16 +01:00
parent 8af49deb34
commit a40f6e94dd

View File

@@ -49,24 +49,32 @@ pub trait GlobalState {
lang lang
} }
// /// Navigates to the given entity. /// Get the text of a widget.
// fn navigate(&self, to: Entity, ctx: &mut Context<'_>) { fn get_text(&self, ctx: &mut Context<'_>, entity: Entity) -> Option<String> {
// if let Some(old_focused_element) = ctx.window().get::<Global>("global").focused_widget { let text = TextBox::text_clone(&ctx.get_widget(entity));
// let mut old_focused_element = ctx.get_widget(old_focused_element);
// old_focused_element.set("focused", false); if text.is_empty() {
// //old_focused_element.update_theme_by_state(false); return None;
// } }
// ctx.window().get_mut::<Global>("global").focused_widget = None;
// ctx.widget().set("visibility", Visibility::Collapsed); TextBox::text_set(&mut ctx.get_widget(entity), String::default());
// ctx.get_widget(to).set("visibility", Visibility::Visible); Some(text)
// } }
/// Navigates to the given entity.
fn navigate(&self, to: Entity, ctx: &mut Context<'_>) {
if let Some(old_focused_element) = *Window::focus_state_ref(&ctx.window()).focused_entity() {
ctx.push_event_by_window(FocusEvent::RemoveFocus(old_focused_element));
}
ctx.widget().set("visibility", Visibility::Collapsed);
ctx.get_widget(to).set("visibility", Visibility::Visible);
}
/// Save the our data structure and convert it to `ron` file format. /// Save the our data structure and convert it to `ron` file format.
/// The cargo package identifier (here: 'nwx.advotracker') is taken to create the app directory. /// The cargo package identifier (here: 'nwx.advotracker') is taken to create the app directory.
/// in users 'settings directory'. The directory location is OS dependant /// in users 'settings directory'. The directory location is OS dependant
/// (Windows: AppData, Unix: XDG_CONFIG_HOME, MacOS: $HOME/Library/Preferences). /// (Windows: AppData, Unix: XDG_CONFIG_HOME, MacOS: $HOME/Library/Preferences).
/// The data is stored in filename PROP_ADVOTRACKER (here: `advotracker.ron`) /// The data is stored in filename PROP_ADVOTRACKER (here: `advotracker.ron`)
fn save(&self, registry: &mut Registry, ctx: &mut Context<'_>) { fn save(&self, registry: &mut Registry, ctx: &mut Context<'_>) {
registry registry
.get::<Settings>("settings") .get::<Settings>("settings")