-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(editor): add editor struct to allow multiple window
- Loading branch information
1 parent
2576c61
commit 275403c
Showing
3 changed files
with
56 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
use crate::{core::Size, window::Window}; | ||
|
||
pub struct Editor { | ||
pub size: Size<u16>, | ||
pub windows: Vec<Window>, | ||
pub active_window: usize, | ||
} | ||
|
||
impl Editor { | ||
pub fn new(size: Size<u16>) -> Self { | ||
Self { | ||
size, | ||
windows: vec![], | ||
active_window: 0, | ||
} | ||
} | ||
|
||
pub fn create_new_window(&mut self) -> &mut Window { | ||
let window = Window::new(Size { | ||
width: self.size.width, | ||
height: self.size.height - 2, | ||
}); | ||
|
||
self.windows.push(window); | ||
|
||
self.windows.last_mut().unwrap() | ||
} | ||
|
||
pub fn get_active_window(&self) -> &Window { | ||
self.windows.get(self.active_window).unwrap() | ||
} | ||
|
||
pub fn get_active_window_mut(&mut self) -> &mut Window { | ||
self.windows.get_mut(self.active_window).unwrap() | ||
} | ||
|
||
pub fn set_size(&mut self, width: u16, height: u16) { | ||
self.size.width = width; | ||
self.size.height = height; | ||
|
||
for window in self.windows.iter_mut() { | ||
window.set_size(width, height) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters