Add right tileset toolbar
Getty Ritter
7 years ago
| 1 | 1 | use gdk; |
| 2 | 2 | use gtk::{ |
| 3 | 3 | self, |
| 4 | BoxExt, | |
| 5 | EntryExt, | |
| 4 | 6 | ContainerExt, |
| 5 | 7 | HeaderBarExt, |
| 8 | PanedExt, | |
| 6 | 9 | WindowExt, |
| 7 | 10 | WidgetExt, |
| 8 | 11 | DialogExt, |
| 12 | 15 | use std::cell::RefCell; |
| 13 | 16 | use std::process; |
| 14 | 17 | use std::rc::Rc; |
| 15 | ||
| 16 | pub struct App { | |
| 17 | pub window: gtk::Window, | |
| 18 | pub canvas: GridCanvas, | |
| 19 | pub header: Header, | |
| 20 | } | |
| 21 | ||
| 22 | pub struct Header { | |
| 23 | pub container: gtk::HeaderBar, | |
| 24 | pub open_btn: gtk::Button, | |
| 25 | pub save_btn: gtk::Button, | |
| 26 | pub save_as_btn: gtk::Button, | |
| 27 | } | |
| 28 | 18 | |
| 29 | 19 | pub struct GridCanvas { |
| 30 | 20 | pub canvas: gtk::DrawingArea, |
| 81 | 71 | } |
| 82 | 72 | } |
| 83 | 73 | |
| 74 | pub struct App { | |
| 75 | pub window: gtk::Window, | |
| 76 | pub canvas: GridCanvas, | |
| 77 | pub container: gtk::Paned, | |
| 78 | pub toolbar: Toolbar, | |
| 79 | pub header: Header, | |
| 80 | } | |
| 81 | ||
| 84 | 82 | impl App { |
| 85 | 83 | fn new() -> App { |
| 86 | 84 | let window = gtk::Window::new(gtk::WindowType::Toplevel); |
| 85 | let container = gtk::Paned::new(gtk::Orientation::Horizontal); | |
| 87 | 86 | let header = Header::new(); |
| 88 | 87 | let canvas = GridCanvas::new(); |
| 89 | 88 | |
| 91 | 90 | window.set_titlebar(&header.container); |
| 92 | 91 | window.set_title("Palladio"); |
| 93 | 92 | window.set_wmclass("palladio", "Palladio"); |
| 94 | window.add(&canvas.canvas); | |
| 95 | 93 | |
| 96 | 94 | gtk::Window::set_default_icon_name("iconname"); |
| 97 | 95 | |
| 100 | 98 | gtk::Inhibit(false) |
| 101 | 99 | }); |
| 102 | 100 | |
| 103 |
|
|
| 101 | let toolbar = Toolbar::new(); | |
| 102 | container.pack1(&canvas.canvas, true, true); | |
| 103 | container.pack2(&toolbar.toolbar, false, true); | |
| 104 | window.add(&container); | |
| 105 | ||
| 106 | App { window, header, canvas, toolbar, container } | |
| 104 | 107 | } |
| 105 | 108 | |
| 106 | 109 | pub fn run() { |
| 113 | 116 | app.window.show_all(); |
| 114 | 117 | gtk::main(); |
| 115 | 118 | } |
| 119 | } | |
| 120 | ||
| 121 | // HEADER | |
| 122 | ||
| 123 | pub struct Header { | |
| 124 | pub container: gtk::HeaderBar, | |
| 125 | pub open_btn: gtk::Button, | |
| 126 | pub save_btn: gtk::Button, | |
| 127 | pub save_as_btn: gtk::Button, | |
| 116 | 128 | } |
| 117 | 129 | |
| 118 | 130 | impl Header { |
| 170 | 182 | save_dialog.destroy(); |
| 171 | 183 | } |
| 172 | 184 | } |
| 185 | ||
| 186 | ||
| 187 | pub struct Toolbar { | |
| 188 | toolbar: gtk::Box, | |
| 189 | tile_width: gtk::Entry, | |
| 190 | tile_height: gtk::Entry, | |
| 191 | load_tileset_btn: gtk::Button, | |
| 192 | } | |
| 193 | ||
| 194 | impl Toolbar { | |
| 195 | fn new() -> Toolbar { | |
| 196 | let container = gtk::Box::new(gtk::Orientation::Vertical, 5); | |
| 197 | ||
| 198 | let tile_label = gtk::Label::new("Tileset"); | |
| 199 | ||
| 200 | let tile_width = gtk::Entry::new(); | |
| 201 | tile_width.set_text("16"); | |
| 202 | let tile_height = gtk::Entry::new(); | |
| 203 | tile_height.set_text("16"); | |
| 204 | ||
| 205 | let load_tileset_btn = gtk::Button::new_with_label("Load Tileset Image"); | |
| 206 | ||
| 207 | container.pack_start(&tile_label, false, true, 0); | |
| 208 | container.pack_start(&tile_width, false, true, 0); | |
| 209 | container.pack_start(&tile_height, false, true, 0); | |
| 210 | container.pack_start(&load_tileset_btn, false, true, 0); | |
| 211 | ||
| 212 | Toolbar { | |
| 213 | toolbar: container, | |
| 214 | tile_width, | |
| 215 | tile_height, | |
| 216 | load_tileset_btn, | |
| 217 | } | |
| 218 | } | |
| 219 | } | |