diff options
| author | tslil clingman <> | 2020-01-20 12:26:30 -0800 |
|---|---|---|
| committer | tslil clingman <> | 2020-01-20 12:26:30 -0800 |
| commit | 42e504281ba8c36c0bf5c679dd767f04310655f3 (patch) | |
| tree | 3433dc52915741f67ff46e687c96646bf5af2724 /src/gui.rs | |
| parent | 8110985e6636e511f0a2e85a6f30aa8ff109320d (diff) | |
bool + log ad hoc --> Result<_,_> & refactoring
Diffstat (limited to 'src/gui.rs')
| -rw-r--r-- | src/gui.rs | 43 |
1 files changed, 30 insertions, 13 deletions
@@ -18,7 +18,7 @@ impl GameLog { } } - pub fn update<L: Fn(String)>(&self, game: &Game<L>) { + pub fn update(&self, game: &Game) { self.pieces_window.clear(); self.pieces_window.addstr(format!( "W: {:2} B: {:2}\nWC: {} BC: {}", @@ -136,7 +136,7 @@ impl BoardGUI { } } - pub fn update<L: Fn(String)>(&self, game: &Game<L>) { + pub fn update(&self, game: &Game) { // Is this really the `best' way? assert!(game.get_size() == self.size); let mut pos = Position { x: 0, y: 0 }; @@ -253,8 +253,18 @@ pub struct ActionEntry { } impl ActionEntry { + pub fn clear_entry_area(&self) { + self.window.mv(0, self.xstart); + for _i in 0..self.max_len { + self.window.addch('_'); + } + + self.window.mv(0, self.xstart); + self.window.refresh(); + } + pub fn new(ypos: i32, xpos: i32, max_len: usize) -> ActionEntry { - let txt = "Action entry: "; + let txt = "Enter action: "; let xstart = txt.len() as i32; let width = max_len as i32 + xstart + 1; @@ -268,13 +278,7 @@ impl ActionEntry { ae.window.keypad(true); ae.window.addstr(txt); - - for _i in 0..max_len { - ae.window.addch('_'); - } - - ae.window.mv(0, xstart); - ae.window.refresh(); + ae.clear_entry_area(); ae } @@ -313,6 +317,8 @@ impl ActionEntry { pub struct MessageLog { window: Window, + has_colours: bool, + red_colour: u8, } impl MessageLog { @@ -326,15 +332,26 @@ impl MessageLog { ) -> MessageLog { let ml = MessageLog { window: newwin(height, width, ypos, xpos), + has_colours: has_colours, + red_colour: red_colour, }; - if has_colours { - ml.window.attrset(ColorPair(red_colour)); - } ml } + pub fn log_message(&self, str: String) { + self.window.clear(); + if self.has_colours { + self.window.attrset(Attribute::Normal); + } + self.window.addstr(str); + self.window.refresh(); + } + pub fn log_error(&self, str: String) { self.window.clear(); + if self.has_colours { + self.window.attrset(ColorPair(self.red_colour)); + } self.window.addstr(str); self.window.refresh(); } |
