Add TextView::set_effect

This commit is contained in:
Alexandre Bury 2018-01-05 14:14:24 +01:00
parent 895557e91d
commit aa9db30a51

View File

@ -8,6 +8,7 @@ use owning_ref::{ArcRef, OwningHandle};
use std::ops::Deref;
use std::sync::{Mutex, MutexGuard};
use std::sync::Arc;
use theme::Effect;
use unicode_width::UnicodeWidthStr;
use utils::{LinesIterator, Row};
use vec::Vec2;
@ -140,6 +141,7 @@ pub struct TextView {
rows: Vec<Row>,
align: Align,
effect: Effect,
// If `false`, disable scrolling.
scrollable: bool,
@ -185,6 +187,7 @@ impl TextView {
pub fn new_with_content(content: TextContent) -> Self {
TextView {
content: content.content,
effect: Effect::Simple,
rows: Vec::new(),
scrollable: true,
scrollbase: ScrollBase::new(),
@ -218,6 +221,18 @@ impl TextView {
self.with(|s| s.set_scrollable(scrollable))
}
/// Sets the effect for the entire content.
pub fn set_effect(&mut self, effect: Effect) {
self.effect = effect;
}
/// Sets the effect for the entire content.
///
/// Chainable variant.
pub fn effect(self, effect: Effect) -> Self {
self.with(|s| s.set_effect(effect))
}
/// Sets the horizontal alignment for this view.
pub fn h_align(mut self, h: HAlign) -> Self {
self.align.h = h;
@ -393,12 +408,14 @@ impl View for TextView {
let content = self.content.lock().unwrap();
self.scrollbase.draw(printer, |printer, i| {
let row = &self.rows[i];
let text = &content.content[row.start..row.end];
let l = text.width();
let x = self.align.h.get_offset(l, printer.size.x);
printer.print((x, 0), text);
printer.with_effect(self.effect, |printer| {
self.scrollbase.draw(printer, |printer, i| {
let row = &self.rows[i];
let text = &content.content[row.start..row.end];
let l = text.width();
let x = self.align.h.get_offset(l, printer.size.x);
printer.print((x, 0), text);
});
});
}