Remove inferred lifetime parameters to Printer

This commit is contained in:
Alexandre Bury 2020-07-03 20:38:08 -07:00
parent 58480d14f9
commit f047ee5f5c
29 changed files with 50 additions and 54 deletions

View File

@ -304,7 +304,7 @@ impl<'a, 'b> Printer<'a, 'b> {
/// ```
pub fn with_color<F>(&self, c: ColorStyle, f: F)
where
F: FnOnce(&Printer<'_, '_>),
F: FnOnce(&Printer),
{
let old = self.backend.set_color(c.resolve(&self.theme.palette));
f(self);
@ -315,7 +315,7 @@ impl<'a, 'b> Printer<'a, 'b> {
/// that will apply the given style on prints.
pub fn with_style<F, T>(&self, style: T, f: F)
where
F: FnOnce(&Printer<'_, '_>),
F: FnOnce(&Printer),
T: Into<Style>,
{
let style = style.into();
@ -336,7 +336,7 @@ impl<'a, 'b> Printer<'a, 'b> {
/// that will apply the given effect on prints.
pub fn with_effect<F>(&self, effect: Effect, f: F)
where
F: FnOnce(&Printer<'_, '_>),
F: FnOnce(&Printer),
{
self.backend.set_effect(effect);
f(self);
@ -347,7 +347,7 @@ impl<'a, 'b> Printer<'a, 'b> {
/// that will apply the given theme on prints.
pub fn with_theme<F>(&self, theme: &Theme, f: F)
where
F: FnOnce(&Printer<'_, '_>),
F: FnOnce(&Printer),
{
f(&self.theme(theme));
}
@ -367,7 +367,7 @@ impl<'a, 'b> Printer<'a, 'b> {
/// that will apply each given effect on prints.
pub fn with_effects<F>(&self, effects: EnumSet<Effect>, f: F)
where
F: FnOnce(&Printer<'_, '_>),
F: FnOnce(&Printer),
{
match effects.iter().next() {
None => f(self),
@ -433,7 +433,7 @@ impl<'a, 'b> Printer<'a, 'b> {
/// * Otherwise, use `ColorStyle::Primary`.
pub fn with_high_border<F>(&self, invert: bool, f: F)
where
F: FnOnce(&Printer<'_, '_>),
F: FnOnce(&Printer),
{
let color = match self.theme.borders {
BorderStyle::None => return,
@ -452,7 +452,7 @@ impl<'a, 'b> Printer<'a, 'b> {
/// * Otherwise, use `ColorStyle::primary()`.
pub fn with_low_border<F>(&self, invert: bool, f: F)
where
F: FnOnce(&Printer<'_, '_>),
F: FnOnce(&Printer),
{
let color = match self.theme.borders {
BorderStyle::None => return,
@ -470,11 +470,7 @@ impl<'a, 'b> Printer<'a, 'b> {
/// * If the printer currently has the focus,
/// uses `ColorStyle::highlight()`.
/// * Otherwise, uses `ColorStyle::highlight_inactive()`.
pub fn with_selection<F: FnOnce(&Printer<'_, '_>)>(
&self,
selection: bool,
f: F,
) {
pub fn with_selection<F: FnOnce(&Printer)>(&self, selection: bool, f: F) {
self.with_color(
if selection {
if self.focused {

View File

@ -220,9 +220,9 @@ impl ScrollBase {
/// printer.print((0,0), lines[i]);
/// });
/// ```
pub fn draw<F>(&self, printer: &Printer<'_, '_>, line_drawer: F)
pub fn draw<F>(&self, printer: &Printer, line_drawer: F)
where
F: Fn(&Printer<'_, '_>, usize),
F: Fn(&Printer, usize),
{
if self.view_height == 0 {
return;

View File

@ -13,7 +13,7 @@ pub trait View: Any + AnyView {
/// Draws the view with the given printer (includes bounds) and focus.
///
/// This is the only *required* method to implement.
fn draw(&self, printer: &Printer<'_, '_>);
fn draw(&self, printer: &Printer);
/// Called once the size for this view has been decided.
///

View File

@ -47,7 +47,7 @@ pub trait ViewWrapper: 'static {
}
/// Wraps the `draw` method.
fn wrap_draw(&self, printer: &Printer<'_, '_>) {
fn wrap_draw(&self, printer: &Printer) {
self.with_view(|v| v.draw(printer));
}
@ -103,7 +103,7 @@ pub trait ViewWrapper: 'static {
// The main point of implementing ViewWrapper is to have View for free.
impl<T: ViewWrapper> View for T {
fn draw(&self, printer: &Printer<'_, '_>) {
fn draw(&self, printer: &Printer) {
self.wrap_draw(printer);
}

View File

@ -128,7 +128,7 @@ impl Button {
}
impl View for Button {
fn draw(&self, printer: &Printer<'_, '_>) {
fn draw(&self, printer: &Printer) {
if printer.size.x == 0 {
return;
}

View File

@ -105,7 +105,7 @@ impl<T> Canvas<T> {
/// Sets the closure for `draw(&Printer)`.
pub fn set_draw<F>(&mut self, f: F)
where
F: 'static + Fn(&T, &Printer<'_, '_>),
F: 'static + Fn(&T, &Printer),
{
self.draw = Box::new(f);
}
@ -115,7 +115,7 @@ impl<T> Canvas<T> {
/// Chainable variant.
pub fn with_draw<F>(self, f: F) -> Self
where
F: 'static + Fn(&T, &Printer<'_, '_>),
F: 'static + Fn(&T, &Printer),
{
self.with(|s| s.set_draw(f))
}
@ -266,7 +266,7 @@ impl<T> Canvas<T> {
}
impl<T: 'static> View for Canvas<T> {
fn draw(&self, printer: &Printer<'_, '_>) {
fn draw(&self, printer: &Printer) {
(self.draw)(&self.state, printer);
}

View File

@ -128,7 +128,7 @@ impl Checkbox {
})
}
fn draw_internal(&self, printer: &Printer<'_, '_>) {
fn draw_internal(&self, printer: &Printer) {
printer.print((0, 0), "[ ]");
if self.checked {
printer.print((1, 0), "X");
@ -145,7 +145,7 @@ impl View for Checkbox {
self.enabled
}
fn draw(&self, printer: &Printer<'_, '_>) {
fn draw(&self, printer: &Printer) {
if self.enabled && printer.enabled {
printer.with_selection(printer.focused, |printer| {
self.draw_internal(printer)

View File

@ -25,7 +25,7 @@ impl Default for DebugView {
}
impl View for DebugView {
fn draw(&self, printer: &Printer<'_, '_>) {
fn draw(&self, printer: &Printer) {
let logs = logger::LOGS.lock().unwrap();
// Only print the last logs, so skip what doesn't fit
let skipped = logs.len().saturating_sub(printer.size.y);

View File

@ -498,7 +498,7 @@ impl Dialog {
}
}
fn draw_buttons(&self, printer: &Printer<'_, '_>) -> Option<usize> {
fn draw_buttons(&self, printer: &Printer) -> Option<usize> {
let mut buttons_height = 0;
// Current horizontal position of the next button we'll draw.
@ -546,7 +546,7 @@ impl Dialog {
Some(buttons_height)
}
fn draw_content(&self, printer: &Printer<'_, '_>, buttons_height: usize) {
fn draw_content(&self, printer: &Printer, buttons_height: usize) {
// What do we have left?
let taken = Vec2::new(0, buttons_height)
+ self.borders.combined()
@ -565,7 +565,7 @@ impl Dialog {
);
}
fn draw_title(&self, printer: &Printer<'_, '_>) {
fn draw_title(&self, printer: &Printer) {
if !self.title.is_empty() {
let len = self.title.width();
let spacing = 3; //minimum distance to borders
@ -629,7 +629,7 @@ impl Dialog {
}
impl View for Dialog {
fn draw(&self, printer: &Printer<'_, '_>) {
fn draw(&self, printer: &Printer) {
// This will be the buttons_height used by the buttons.
let buttons_height = match self.draw_buttons(printer) {
Some(height) => height,

View File

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

View File

@ -496,7 +496,7 @@ fn make_small_stars(length: usize) -> &'static str {
}
impl View for EditView {
fn draw(&self, printer: &Printer<'_, '_>) {
fn draw(&self, printer: &Printer) {
assert_eq!(
printer.size.x, self.last_length,
"Was promised {}, received {}",

View File

@ -59,7 +59,7 @@ impl<V: View> ViewWrapper for EnableableView<V> {
}
}
fn wrap_draw(&self, printer: &Printer<'_, '_>) {
fn wrap_draw(&self, printer: &Printer) {
self.view.draw(&printer.enabled(self.enabled));
}
}

View File

@ -42,7 +42,7 @@ impl<T> Layer<T> {
impl<T: View> ViewWrapper for Layer<T> {
wrap_impl!(self.view: T);
fn wrap_draw(&self, printer: &Printer<'_, '_>) {
fn wrap_draw(&self, printer: &Printer) {
printer.with_color(self.color, |printer| {
for y in 0..printer.size.y {
printer.print_hline((0, y), printer.size.x, " ");

View File

@ -441,7 +441,7 @@ fn try_focus(
}
impl View for LinearLayout {
fn draw(&self, printer: &Printer<'_, '_>) {
fn draw(&self, printer: &Printer) {
// Use pre-computed sizes
// debug!("Pre loop!");
for (i, item) in ChildIterator::new(

View File

@ -271,7 +271,7 @@ fn try_focus(
}
impl View for ListView {
fn draw(&self, printer: &Printer<'_, '_>) {
fn draw(&self, printer: &Printer) {
if self.children.is_empty() {
return;
}

View File

@ -313,7 +313,7 @@ impl MenuPopup {
}
impl View for MenuPopup {
fn draw(&self, printer: &Printer<'_, '_>) {
fn draw(&self, printer: &Printer) {
if !printer.size.fits((2, 2)) {
return;
}

View File

@ -266,7 +266,7 @@ fn show_child(s: &mut Cursive, offset: Vec2, menu: Rc<MenuTree>) {
}
impl View for Menubar {
fn draw(&self, printer: &Printer<'_, '_>) {
fn draw(&self, printer: &Printer) {
// Draw the bar at the top
printer.with_color(ColorStyle::primary(), |printer| {
printer.print_hline((0, 0), printer.size.x, " ");

View File

@ -69,7 +69,7 @@ impl<V: View> ViewWrapper for PaddedView<V> {
self.view.on_event(event.relativized(padding))
}
fn wrap_draw(&self, printer: &Printer<'_, '_>) {
fn wrap_draw(&self, printer: &Printer) {
let top_left = self.margins.top_left();
let bot_right = self.margins.bot_right();
let printer = &printer.offset(top_left).shrinked(bot_right);

View File

@ -62,7 +62,7 @@ impl<V> Panel<V> {
self.title_position = align;
}
fn draw_title(&self, printer: &Printer<'_, '_>) {
fn draw_title(&self, printer: &Printer) {
if !self.title.is_empty() {
let len = self.title.width();
let spacing = 3; //minimum distance to borders
@ -106,7 +106,7 @@ impl<V: View> ViewWrapper for Panel<V> {
self.view.required_size(req) + (2, 2)
}
fn wrap_draw(&self, printer: &Printer<'_, '_>) {
fn wrap_draw(&self, printer: &Printer) {
printer.print_box((0, 0), printer.size, true);
self.draw_title(&printer);

View File

@ -227,7 +227,7 @@ fn sub_block(extra: usize) -> &'static str {
}
impl View for ProgressBar {
fn draw(&self, printer: &Printer<'_, '_>) {
fn draw(&self, printer: &Printer) {
// Now, the bar itself...
let available = printer.size.x;

View File

@ -165,7 +165,7 @@ impl<T: 'static> RadioButton<T> {
})
}
fn draw_internal(&self, printer: &Printer<'_, '_>) {
fn draw_internal(&self, printer: &Printer) {
printer.print((0, 0), "( )");
if self.is_selected() {
printer.print((1, 0), "X");
@ -196,7 +196,7 @@ impl<T: 'static> View for RadioButton<T> {
self.enabled
}
fn draw(&self, printer: &Printer<'_, '_>) {
fn draw(&self, printer: &Printer) {
if self.enabled && printer.enabled {
printer.with_selection(printer.focused, |printer| {
self.draw_internal(printer)

View File

@ -314,7 +314,7 @@ impl<V> View for ScrollView<V>
where
V: View,
{
fn draw(&self, printer: &Printer<'_, '_>) {
fn draw(&self, printer: &Printer) {
scroll::draw(self, printer, |s, p| s.inner.draw(p));
}

View File

@ -442,7 +442,7 @@ impl<T: 'static> SelectView<T> {
self.with(|s| s.add_all(iter))
}
fn draw_item(&self, printer: &Printer<'_, '_>, i: usize) {
fn draw_item(&self, printer: &Printer, i: usize) {
let l = self.items[i].label.width();
let x = self.align.h.get_offset(l, printer.size.x);
printer.print_hline((0, 0), x, " ");
@ -873,7 +873,7 @@ where
}
impl<T: 'static> View for SelectView<T> {
fn draw(&self, printer: &Printer<'_, '_>) {
fn draw(&self, printer: &Printer) {
self.last_offset.set(printer.offset);
if self.popup {

View File

@ -75,7 +75,7 @@ impl<T: View> ViewWrapper for ShadowView<T> {
self.view.on_event(event.relativized(padding))
}
fn wrap_draw(&self, printer: &Printer<'_, '_>) {
fn wrap_draw(&self, printer: &Printer) {
if printer.size.y <= self.top_padding as usize
|| printer.size.x <= self.left_padding as usize
{

View File

@ -141,7 +141,7 @@ impl SliderView {
}
impl View for SliderView {
fn draw(&self, printer: &Printer<'_, '_>) {
fn draw(&self, printer: &Printer) {
match self.orientation {
Orientation::Vertical => {
printer.print_vline((0, 0), self.max_value, "|")

View File

@ -131,7 +131,7 @@ impl<T: View> ChildWrapper<T> {
// TODO: use macros to make this less ugly?
impl<T: View> View for ChildWrapper<T> {
fn draw(&self, printer: &Printer<'_, '_>) {
fn draw(&self, printer: &Printer) {
match *self {
ChildWrapper::Shadow(ref v) => v.draw(printer),
ChildWrapper::Backfilled(ref v) => v.draw(printer),
@ -520,7 +520,7 @@ impl StackView {
/// ease inserting layers under the stackview but above its background.
///
/// you probably just want to call draw()
pub fn draw_bg(&self, printer: &Printer<'_, '_>) {
pub fn draw_bg(&self, printer: &Printer) {
// If the background is dirty draw a new background
if self.bg_dirty.get() {
for y in 0..printer.size.y {
@ -540,7 +540,7 @@ impl StackView {
/// ease inserting layers under the stackview but above its background.
///
/// You probably just want to call draw()
pub fn draw_fg(&self, printer: &Printer<'_, '_>) {
pub fn draw_fg(&self, printer: &Printer) {
let last = self.layers.len();
printer.with_color(ColorStyle::primary(), |printer| {
for (i, (v, offset)) in
@ -605,7 +605,7 @@ where
}
impl View for StackView {
fn draw(&self, printer: &Printer<'_, '_>) {
fn draw(&self, printer: &Printer) {
// This function is included for compat with the view trait,
// it should behave the same as calling them seperately, but does
// not pause to let you insert in between the layers.

View File

@ -479,7 +479,7 @@ impl View for TextArea {
)
}
fn draw(&self, printer: &Printer<'_, '_>) {
fn draw(&self, printer: &Printer) {
printer.with_color(ColorStyle::secondary(), |printer| {
let effect = if self.enabled && printer.enabled {
Effect::Reverse

View File

@ -362,7 +362,7 @@ impl TextView {
}
impl View for TextView {
fn draw(&self, printer: &Printer<'_, '_>) {
fn draw(&self, printer: &Printer) {
let h = self.rows.len();
// If the content is smaller than the view, align it somewhere.
let offset = self.align.v.get_offset(h, printer.size.y);

View File

@ -33,7 +33,7 @@ impl<T> TrackedView<T> {
impl<T: View> ViewWrapper for TrackedView<T> {
wrap_impl!(self.view: T);
fn wrap_draw(&self, printer: &Printer<'_, '_>) {
fn wrap_draw(&self, printer: &Printer) {
self.offset.set(printer.offset);
self.view.draw(printer);
}