The idea is simple: there are some Apps which have some Windows. Windows have some type of reference to their app. They need to use each-others methods. I've made some sketchy code, but when I resolve one issue I get a new one.
struct Win {
x: i32,
y: i32,
last_event: u32, // just for testing
app: App,
}
impl Win {
pub fn new(app: &mut App, x: i32, y: i32) -> Win {
let mut win = Win{app: *app, x: x, y: y, last_event: 0};
app.add_window(&mut win);
win
}
fn add_window_to_app(&mut self, app: &mut App) {
app.add_window(self);
}
pub fn on_event(&mut self, event: u32, param1: u32, param2: u32) {
self.last_event = event;
}
}
struct App {
pid: u32,
windows: Vec<Win>,
}
impl App {
pub fn new(pid: u32) -> App {
let app = App{pid: pid, windows: Vec::<Win>::new()};
app
}
pub fn add_window(&mut self, win: &mut Win) {
self.windows.push(*win);
}
pub fn on_event(&mut self, win: &mut Win, event: u32, param1: u32, param2: u32) {
win.on_event(event, param1, param2);
}
}
fn main() {
let mut app = App::new(1);
}