Skip to content

Commit

Permalink
Add new terminal size to Event::Resize
Browse files Browse the repository at this point in the history
  • Loading branch information
nabijaczleweli committed Jan 2, 2016
1 parent a1bde40 commit 854a070
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 5 deletions.
10 changes: 8 additions & 2 deletions examples/simple.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@ extern crate bear_lib_terminal;

use bear_lib_terminal::Color;
use bear_lib_terminal::geometry::Point;
use bear_lib_terminal::terminal::{self, Event, KeyCode};
use bear_lib_terminal::terminal::{self, config, Event, KeyCode};


fn main() {
terminal::open("Simple example", 80, 30);
terminal::set(config::Window::empty().resizeable(true));

terminal::print_xy(0, 0, "Your mom");
terminal::with_colors(Color::from_rgb(0xFA, 0xAF, 0x29), Color::from_rgb(0x05, 0x50, 0xD6), || terminal::print_xy(0, 1, "Colerd"));
for (i, c) in "Coloured letters with pixel-offset!".chars().enumerate() {
Expand All @@ -24,8 +26,12 @@ fn main() {
terminal::refresh();
while let Some(event) = terminal::wait_event() {
match event {
Event::Resize{width, height} => {
terminal::print_xy(0, 0, &*&format!("Width: {}\nHeight: {}", width, height));
terminal::refresh();
},
Event::Close | Event::KeyPressed{key: KeyCode::Escape, ctrl: _, shift: _} => break,
_ => (),
_ => (),
}
}
terminal::close();
Expand Down
12 changes: 10 additions & 2 deletions src/terminal/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,16 @@ pub enum KeyCode {
pub enum Event {
/// Terminal window closed.
Close,
/// Terminal window resized.
Resize,
/// Terminal window resized. Needs to have `window.resizeable = true` to occur.
///
/// Note, that, as of [`40e6253`](https://bitbucket.org/cfyzium/bearlibterminal/commits/40e625311f0cccc43b94633add4dec0d6b77c2b7),
/// the terminal window is cleared when resized.
Resize{
/// Width the terminal was resized to.
width: i32,
/// Heigth the terminal was resized to.
height: i32,
},
/// Mouse moved.
///
/// If [`precise-mouse`](config/struct.Input.html#structfield.precise_mouse) is off, generated each time mouse moves from cell to cell, otherwise,
Expand Down
9 changes: 8 additions & 1 deletion src/terminal/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ fn to_keycode(code: i32) -> Option<KeyCode> {
fn to_event(code: i32) -> Option<Event> {
match code {
ffi::TK_CLOSE => Some(Event::Close),
ffi::TK_RESIZED => Some(Event::Resize),
ffi::TK_RESIZED => Some(get_window_resize()),
ffi::TK_MOUSE_MOVE => Some(get_mouse_move()),
ffi::TK_MOUSE_SCROLL => Some(get_mouse_scroll()),
_ => to_key_event(code),
Expand All @@ -413,6 +413,13 @@ fn to_key_event(code: i32) -> Option<Event> {
}
}

fn get_window_resize() -> Event {
Event::Resize{
width: ffi::state(ffi::TK_WIDTH),
height: ffi::state(ffi::TK_HEIGHT),
}
}

fn get_mouse_move() -> Event {
Event::MouseMove{
x: ffi::state(ffi::TK_MOUSE_X),
Expand Down

0 comments on commit 854a070

Please sign in to comment.