This commit is contained in:
Alexandre Bury 2018-08-22 13:33:29 -07:00
parent 2f0f632e22
commit 92f919978c
24 changed files with 91 additions and 130 deletions

View File

@ -23,8 +23,7 @@ fn main() {
.child(Button::new_raw(" New game ", show_options))
.child(Button::new_raw(" Best scores ", |s| {
s.add_layer(Dialog::info("Not yet!").title("Scores"))
}))
.child(Button::new_raw(" Exit ", |s| s.quit())),
})).child(Button::new_raw(" Exit ", |s| s.quit())),
),
);
@ -43,27 +42,23 @@ fn show_options(siv: &mut Cursive) {
size: Vec2::new(8, 8),
mines: 10,
},
)
.item(
).item(
"Medium: 16x16, 40 mines",
game::Options {
size: Vec2::new(16, 16),
mines: 40,
},
)
.item(
).item(
"Difficult: 24x24, 99 mines",
game::Options {
size: Vec2::new(24, 24),
mines: 99,
},
)
.on_submit(|s, option| {
).on_submit(|s, option| {
s.pop_layer();
new_game(s, *option);
}),
)
.dismiss_button("Back"),
).dismiss_button("Back"),
);
}
@ -276,8 +271,7 @@ fn new_game(siv: &mut Cursive, options: game::Options) {
.content(
LinearLayout::horizontal()
.child(Panel::new(BoardView::new(options))),
)
.button("Quit game", |s| {
).button("Quit game", |s| {
s.pop_layer();
}),
);

View File

@ -39,8 +39,7 @@ fn show_popup(siv: &mut Cursive) {
let content = reverse(view.get_content().source());
view.set_content(content);
});
})
.dismiss_button("Ok"),
}).dismiss_button("Ok"),
);
}

View File

@ -125,8 +125,7 @@ fn final_step(s: &mut Cursive) {
"Time travel was a success!\n\
We went forward a few seconds!!",
).center(),
)
.button("That's it?", |s| s.quit()),
).button("That's it?", |s| s.quit()),
);
}

View File

@ -27,8 +27,7 @@ fn main() {
.on_pre_event_inner('k', |s| {
s.select_up(1);
Some(EventResult::Consumed(None))
})
.on_pre_event_inner('j', |s| {
}).on_pre_event_inner('j', |s| {
s.select_down(1);
Some(EventResult::Consumed(None))
});

View File

@ -33,15 +33,13 @@ fn main() {
.on_submit(find)
.with_id("edit")
.min_width(10),
)
.button("Ok", |s| {
let text =
s.call_on_id("edit", |view: &mut EditView| {
).button("Ok", |s| {
let text = s
.call_on_id("edit", |view: &mut EditView| {
view.get_content()
}).unwrap();
find(s, &text);
})
.dismiss_button("Cancel"),
}).dismiss_button("Cancel"),
).on_event(Event::Key(Key::Esc), |s| {
s.pop_layer();
}),

View File

@ -29,8 +29,7 @@ fn main() {
};
s.set_theme(theme);
})
.button("Quit", Cursive::quit),
}).button("Quit", Cursive::quit),
);
siv.run();

View File

@ -112,10 +112,8 @@ fn main() {
(0, 2),
&format!("Speed: {}/s", convert(speed)),
);
})
.fixed_size((25, 3)),
)
.with(|l| {
}).fixed_size((25, 3)),
).with(|l| {
// If we have a file length, add a progress bar
if let Some(len) = len {
l.add_child(

View File

@ -107,8 +107,7 @@ impl Backend {
position: self.mouse_position,
offset: Vec2::zero(),
}
})
.unwrap_or(Event::Unknown(vec![]))
}).unwrap_or(Event::Unknown(vec![]))
}
BltEvent::ShiftReleased | BltEvent::ControlReleased => {
Event::Refresh
@ -167,8 +166,7 @@ impl Backend {
position: self.mouse_position,
offset: Vec2::zero(),
}
})
.unwrap_or(Event::Unknown(vec![])),
}).unwrap_or(Event::Unknown(vec![])),
KeyCode::A
| KeyCode::B
| KeyCode::C

View File

@ -87,39 +87,33 @@ impl Default for Cursive {
}
}
#[cfg(
all(
#[cfg(all(
not(feature = "termion-backend"),
feature = "pancurses-backend"
)
)]
))]
impl Default for Cursive {
fn default() -> Self {
Self::pancurses()
}
}
#[cfg(
all(
#[cfg(all(
not(feature = "termion-backend"),
not(feature = "pancurses-backend"),
feature = "blt-backend"
)
)]
))]
impl Default for Cursive {
fn default() -> Self {
Self::blt()
}
}
#[cfg(
all(
#[cfg(all(
not(feature = "termion-backend"),
not(feature = "pancurses-backend"),
not(feature = "blt-backend"),
feature = "ncurses-backend"
)
)]
))]
impl Default for Cursive {
fn default() -> Self {
Self::ncurses()

View File

@ -61,8 +61,8 @@ where
// `current_width` is the width of everything
// before the next token, including any space.
let mut current_width = 0;
let sum: usize =
iter.take_while(|token| {
let sum: usize = iter
.take_while(|token| {
let width = token.width();
if current_width + width > available_width {
false

View File

@ -1,6 +1,6 @@
use With;
use vec::Vec2;
use view::{SizeConstraint, View, ViewWrapper};
use With;
use XY;
/// Wrapper around another view, with a controlled size.
@ -202,7 +202,6 @@ impl<T: View> BoxView<T> {
self.invalidated = true;
}
inner_getters!(self.view: T);
}

View File

@ -406,8 +406,7 @@ impl Dialog {
if printer.size.x < overhead.horizontal() {
return None;
}
let mut offset = overhead.left
+ self
let mut offset = overhead.left + self
.align
.h
.get_offset(width, printer.size.x - overhead.horizontal());
@ -465,8 +464,7 @@ impl Dialog {
return;
}
let spacing = 3; //minimum distance to borders
let x = spacing
+ self
let x = spacing + self
.title_position
.get_offset(len, printer.size.x - 2 * spacing);
printer.with_high_border(false, |printer| {
@ -507,8 +505,7 @@ impl Dialog {
} else if position.fits_in_rect(
(self.padding + self.borders).top_left(),
self.content.size,
)
&& self.content.take_focus(Direction::none())
) && self.content.take_focus(Direction::none())
{
// Or did we click the content?
self.focus = DialogFocus::Content;

View File

@ -9,5 +9,7 @@ pub struct DummyView;
impl View for DummyView {
fn draw(&self, _: &Printer) {}
fn needs_relayout(&self) -> bool { false }
fn needs_relayout(&self) -> bool {
false
}
}

View File

@ -551,8 +551,7 @@ impl View for EditView {
} else {
Some(g)
}
})
.map(|g| g.len())
}).map(|g| g.len())
.sum();
let content = &content[..display_bytes];
@ -674,8 +673,7 @@ impl View for EditView {
if position.fits_in_rect(offset, (self.last_length, 1)) =>
{
if let Some(position) = position.checked_sub(offset) {
self.cursor = self.offset
+ simple_prefix(
self.cursor = self.offset + simple_prefix(
&self.content[self.offset..],
position.x,
).length;

View File

@ -1,5 +1,5 @@
use view::{Selector, View, ViewWrapper};
use vec::Vec2;
use view::{Selector, View, ViewWrapper};
use With;
use std::any::Any;

View File

@ -234,11 +234,7 @@ impl LinearLayout {
) -> Box<Iterator<Item = (usize, &mut Child)> + 'a> {
match source {
direction::Relative::Front => {
let start = if from_focus {
self.focus
} else {
0
};
let start = if from_focus { self.focus } else { 0 };
Box::new(self.children.iter_mut().enumerate().skip(start))
}
@ -556,25 +552,29 @@ impl View for LinearLayout {
self.move_focus(direction::Direction::front())
}
Event::Key(Key::Left)
if self.orientation == direction::Orientation::Horizontal
if self.orientation
== direction::Orientation::Horizontal
&& self.focus > 0 =>
{
self.move_focus(direction::Direction::right())
}
Event::Key(Key::Up)
if self.orientation == direction::Orientation::Vertical
if self.orientation
== direction::Orientation::Vertical
&& self.focus > 0 =>
{
self.move_focus(direction::Direction::down())
}
Event::Key(Key::Right)
if self.orientation == direction::Orientation::Horizontal
if self.orientation
== direction::Orientation::Horizontal
&& self.focus + 1 < self.children.len() =>
{
self.move_focus(direction::Direction::left())
}
Event::Key(Key::Down)
if self.orientation == direction::Orientation::Vertical
if self.orientation
== direction::Orientation::Vertical
&& self.focus + 1 < self.children.len() =>
{
self.move_focus(direction::Direction::up())

View File

@ -150,11 +150,7 @@ impl ListView {
) -> Box<Iterator<Item = (usize, &mut ListChild)> + 'a> {
match source {
direction::Relative::Front => {
let start = if from_focus {
self.focus
} else {
0
};
let start = if from_focus { self.focus } else { 0 };
Box::new(self.children.iter_mut().enumerate().skip(start))
}

View File

@ -317,14 +317,11 @@ impl View for MenuPopup {
position,
offset,
}
if self.scrollbase.scrollable()
&& position
if self.scrollbase.scrollable() && position
.checked_sub(offset + (0, 1))
.map(|position| {
self.scrollbase
.start_drag(position, self.last_size.x)
})
.unwrap_or(false) =>
self.scrollbase.start_drag(position, self.last_size.x)
}).unwrap_or(false) =>
{
fix_scroll = false;
}

View File

@ -246,8 +246,7 @@ fn show_child(s: &mut Cursive, offset: Vec2, menu: Rc<MenuTree>) {
{
cb(s);
}
})
.on_event(Key::Left, |s| {
}).on_event(Key::Left, |s| {
s.pop_layer();
s.select_menubar();
// Act as if we sent "Left" then "Down"

View File

@ -436,8 +436,7 @@ impl<T: 'static> SelectView<T> {
.checked_sub(offset)
.map(|position| {
position < self.last_size && position.y < self.len()
})
.unwrap_or(false) =>
}).unwrap_or(false) =>
{
self.focus.set(position.y - offset.y)
}
@ -446,14 +445,11 @@ impl<T: 'static> SelectView<T> {
position,
offset,
}
if self.on_submit.is_some()
&& position
if self.on_submit.is_some() && position
.checked_sub(offset)
.map(|position| {
position < self.last_size
&& position.y == self.focus()
})
.unwrap_or(false) =>
position < self.last_size && position.y == self.focus()
}).unwrap_or(false) =>
{
return self.submit();
}

View File

@ -559,8 +559,7 @@ impl View for TextArea {
.checked_sub(offset)
.map(|position| {
self.scrollbase.start_drag(position, self.last_size.x)
})
.unwrap_or(false) =>
}).unwrap_or(false) =>
{
fix_scroll = false;
}