mirror of
https://github.com/FliegendeWurst/cursive.git
synced 2024-11-23 17:35:00 +00:00
Add TextView::set_effect
This commit is contained in:
parent
895557e91d
commit
aa9db30a51
@ -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,6 +408,7 @@ impl View for TextView {
|
||||
|
||||
let content = self.content.lock().unwrap();
|
||||
|
||||
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];
|
||||
@ -400,6 +416,7 @@ impl View for TextView {
|
||||
let x = self.align.h.get_offset(l, printer.size.x);
|
||||
printer.print((x, 0), text);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
fn on_event(&mut self, event: Event) -> EventResult {
|
||||
|
Loading…
Reference in New Issue
Block a user