Add macro'd Default implementations

This commit is contained in:
Alexandre Bury 2016-07-16 17:28:42 -07:00
parent d4afdf024f
commit 05f66b8e1b
7 changed files with 20 additions and 34 deletions

View File

@ -61,6 +61,16 @@ macro_rules! println_stderr(
} } } }
); );
macro_rules! new_default(
($c:ident) => {
impl Default for $c {
fn default() -> Self {
Self::new()
}
}
}
);
pub mod event; pub mod event;
pub mod view; pub mod view;
@ -119,11 +129,7 @@ pub struct Cursive {
running: bool, running: bool,
} }
impl Default for Cursive { new_default!(Cursive);
fn default() -> Self {
Self::new()
}
}
// Use the Ncurses backend. // Use the Ncurses backend.
// TODO: make this feature-driven // TODO: make this feature-driven

View File

@ -34,11 +34,7 @@ pub struct Menubar {
state: State, state: State,
} }
impl Default for Menubar { new_default!(Menubar);
fn default() -> Self {
Self::new()
}
}
impl Menubar { impl Menubar {
pub fn new() -> Self { pub fn new() -> Self {

View File

@ -12,12 +12,12 @@ pub struct Checkbox {
checked: bool, checked: bool,
} }
new_default!(Checkbox);
impl Checkbox { impl Checkbox {
/// Creates a new, unchecked checkbox. /// Creates a new, unchecked checkbox.
pub fn new() -> Self { pub fn new() -> Self {
Checkbox { Checkbox { checked: false }
checked: false,
}
} }
/// Toggles the checkbox state. /// Toggles the checkbox state.
@ -66,7 +66,7 @@ impl View for Checkbox {
fn draw(&self, printer: &Printer) { fn draw(&self, printer: &Printer) {
printer.with_selection(printer.focused, |printer| { printer.with_selection(printer.focused, |printer| {
printer.print((0,0), "[ ]"); printer.print((0, 0), "[ ]");
if self.checked { if self.checked {
printer.print((1, 0), "X"); printer.print((1, 0), "X");
} }

View File

@ -27,11 +27,7 @@ pub struct EditView {
* TODO: add a max text length? */ * TODO: add a max text length? */
} }
impl Default for EditView { new_default!(EditView);
fn default() -> Self {
Self::new()
}
}
impl EditView { impl EditView {
/// Creates a new, empty edit view. /// Creates a new, empty edit view.

View File

@ -44,11 +44,7 @@ pub struct ListView {
focus: usize, focus: usize,
} }
impl Default for ListView { new_default!(ListView);
fn default() -> Self {
Self::new()
}
}
impl ListView { impl ListView {
/// Creates a new, empty `ListView`. /// Creates a new, empty `ListView`.

View File

@ -22,11 +22,7 @@ struct Layer {
virgin: bool, virgin: bool,
} }
impl Default for StackView { new_default!(StackView);
fn default() -> Self {
Self::new()
}
}
impl StackView { impl StackView {
/// Creates a new empty StackView /// Creates a new empty StackView

View File

@ -5,11 +5,7 @@ pub struct ViewPath {
pub path: Vec<usize>, pub path: Vec<usize>,
} }
impl Default for ViewPath { new_default!(ViewPath);
fn default() -> Self {
Self::new()
}
}
impl ViewPath { impl ViewPath {
/// Creates a new empty path. /// Creates a new empty path.