.create(data, |obj, data|
{
// init data
- data.groups.data().extend(groups.clone());
+ data.groups.data_mut().extend(groups.clone());
// create dialog UI
obj.grid(|a| {
let mut notebook = SubList::new();
notebook.set_header(elm.collection.name.as_str());
- let sublist_data = notebook.list().data();
+ let sublist_data = notebook.list().data_mut();
for child in elm.children.iter() {
sublist_data.push(child.collection.clone());
}
});
b.onactivate(|e|{
if let EventType::SubList(sl) = &e.event_type {
-
+ if let Some(nb) = sl.get_from(&e.data.notebooks) {
+ if let Some(current) = &e.data.selected_notebook {
+ e.obj.ctx.detach(current);
+ }
+
+ let notebook = Notebook::new();
+ let doc = UiDoc::new(notebook);
+
+ // TODO: load notes
+
+ e.obj.ctx.attach(&doc);
+ e.data.selected_notebook = Some(doc);
+ }
}
});
});
#![allow(dead_code)]
use std::ffi::{c_char, c_void, CStr, CString};
-use crate::ui::{event, ffi, UiDouble, UiInteger, UiString, UiText, UiRange, ListSelection, UiObject, NoAppData};
+use crate::ui::{event, ffi, UiDouble, UiInteger, UiString, UiText, UiRange, ListSelection, UiObject, NoAppData, UiSourceList};
use crate::ui::ffi::{UiEvent, UiSubListEventData};
pub struct Event<'a, T> {
}
}
}
+
+ pub fn get_from<'a, T>(&self, sourcelist: &'a UiSourceList<T>) -> Option<&'a T> {
+ if self.row_index < 0 {
+ return None;
+ }
+
+ sourcelist
+ .get(self.sublist_index)?
+ .data()
+ .get(self.row_index as usize)
+ }
}
&mut self.list
}
- pub fn data(&mut self) -> &mut Vec<E> {
+ pub fn data_mut(&mut self) -> &mut Vec<E> {
+ self.list.data_mut()
+ }
+
+ pub fn data(&self) -> &Vec<E> {
self.list.data()
}
}
list
}
- pub fn data(&mut self) -> &mut Vec<T> {
+ pub fn data_mut(&mut self) -> &mut Vec<T> {
self.data.as_mut()
}
+
+ pub fn data(&self) -> &Vec<T> {
+ self.data.as_ref()
+ }
pub fn init(&mut self, ctx: &UiContext, name: Option<&str>) {
let c_string = name.map(|n| CString::new(n).unwrap());