79 lines
1.7 KiB
Rust
79 lines
1.7 KiB
Rust
use ::window::*;
|
|
use failure::Fallible;
|
|
|
|
struct MyWindow {
|
|
allow_close: bool,
|
|
}
|
|
|
|
impl Drop for MyWindow {
|
|
fn drop(&mut self) {
|
|
eprintln!("MyWindow dropped");
|
|
}
|
|
}
|
|
|
|
impl WindowCallbacks for MyWindow {
|
|
fn can_close(&mut self) -> bool {
|
|
eprintln!("can I close?");
|
|
if self.allow_close {
|
|
true
|
|
} else {
|
|
self.allow_close = true;
|
|
false
|
|
}
|
|
}
|
|
|
|
fn destroy(&mut self) {
|
|
eprintln!("destroy was called!");
|
|
Connection::get().unwrap().terminate_message_loop();
|
|
}
|
|
|
|
fn paint(&mut self, context: &mut dyn PaintContext) {
|
|
// Pick a purple background color
|
|
context.clear(Color::rgb(0x40, 0x20, 0x60));
|
|
|
|
// This line doesn't need anti-aliasing
|
|
context.draw_line(0, 0, 100, 100, Color::rgb(0xff, 0xff, 0xff), Operator::Over);
|
|
|
|
// This shallower line should need some
|
|
context.draw_line(
|
|
100,
|
|
0,
|
|
200,
|
|
120,
|
|
Color::rgb(0xff, 0xff, 0xff),
|
|
Operator::Over,
|
|
);
|
|
}
|
|
|
|
fn resize(&mut self, dims: Dimensions) {
|
|
eprintln!("resize {:?}", dims);
|
|
}
|
|
|
|
fn key_event(&mut self, key: &KeyEvent) -> bool {
|
|
eprintln!("{:?}", key);
|
|
false
|
|
}
|
|
|
|
fn mouse_event(&mut self, event: &MouseEvent) -> Option<MouseCursor> {
|
|
eprintln!("{:?}", event);
|
|
Some(MouseCursor::Text)
|
|
}
|
|
}
|
|
|
|
fn main() -> Fallible<()> {
|
|
let conn = Connection::init()?;
|
|
|
|
let win = Window::new_window(
|
|
"myclass",
|
|
"the title",
|
|
800,
|
|
600,
|
|
Box::new(MyWindow { allow_close: false }),
|
|
)?;
|
|
|
|
win.show();
|
|
drop(win);
|
|
|
|
conn.run_message_loop()
|
|
}
|