diff options
| author | tslil clingman <> | 2020-11-10 22:30:08 -0500 |
|---|---|---|
| committer | tslil clingman <> | 2020-11-10 23:22:51 -0500 |
| commit | 0b1ba27037bd116087cb1bdcfe81d850b20eab97 (patch) | |
| tree | c3d6dcd96b27e2933c0cddf2d9cd2ccaea59ceef /src/gui/mod.rs | |
| parent | 9d8ef22f2c5645d6911f2677e877569874ccda38 (diff) | |
Refactoring
Diffstat (limited to 'src/gui/mod.rs')
| -rw-r--r-- | src/gui/mod.rs | 122 |
1 files changed, 122 insertions, 0 deletions
diff --git a/src/gui/mod.rs b/src/gui/mod.rs new file mode 100644 index 0000000..341bded --- /dev/null +++ b/src/gui/mod.rs @@ -0,0 +1,122 @@ +/* + This file is part of Takwrap. + + Takwrap is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + Foobar is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with Foobar. If not, see <https://www.gnu.org/licenses/>. +*/ + +mod boardwidget; +use crate::gui::boardwidget::*; + +use fltk::{app::*, button::*, menu::*, text::*, window::*}; + +#[derive(Clone, Copy)] +enum GUIMessage { + None, + Test, + BoardClick, +} + +pub struct GUI { + app: App, + window: DoubleWindow, + board: BoardWidget, + log: TextDisplay, + sender: Sender<GUIMessage>, + receiver: Receiver<GUIMessage>, +} + +impl GUI { + pub fn new() -> GUI { + let app = App::default(); + + // TODO: Why is this not the same as + /* + let mut window = Window::default() + .with_size(800, 600) + .with_label("Takwrap") + .center_screen(); + */ + // Windows made that way are not resizable? + + let mut window = DoubleWindow::new(0, 0, 800, 600, "Takwrap").center_screen(); + + let (sender, receiver) = channel::<GUIMessage>(); + + const MENU_HEIGHT: i32 = 24; + let mut menu = SysMenuBar::default().with_size(800, MENU_HEIGHT); + // menu.set_text_font(Font::Helvetica); + menu.set_color(Color::Light2); + menu.add_emit( + "&File/New...\t", + Shortcut::None, + MenuFlag::Normal, + sender, + GUIMessage::None, + ); + menu.add_emit( + "&File/Open...\t", + Shortcut::None, + MenuFlag::Normal, + sender, + GUIMessage::Test, + ); + + const LOG_WIDTH: i32 = 800 - 600 + MENU_HEIGHT; + let mut log = TextDisplay::default() + .with_size(LOG_WIDTH, 600 - menu.height()) + .with_pos(800 - LOG_WIDTH, menu.height()); + log.set_buffer(Some(TextBuffer::default())); + log.insert("test\n"); + + let mut board_button = Button::default() + .with_size(800 - LOG_WIDTH, 600 - menu.height()) + .below_of(&menu, 0); + board_button.set_frame(FrameType::EmbossedBox); + board_button.emit(sender, GUIMessage::BoardClick); + + window.resizable(&mut board_button); + window.end(); + window.show(); + + let board = BoardWidget::new(board_button, 5); + + // button.emit(sender, GUIMessage::Foo); + + GUI { + app, + board, + window, + log, + sender, + receiver, + } + } + + pub fn run(&mut self) -> Result<(), fltk::prelude::FltkError> { + while self.app.wait() { + if let Some(msg) = self.receiver.recv() { + match msg { + GUIMessage::BoardClick => { + let x = event_x(); + let y = event_y(); + let (x, y) = self.board.to_square(x, y); + self.log.insert(&format!("Board click ({},{})\n", x, y)); + } + _ => (), + } + } + } + Ok(()) + } +} |
