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