зеркало из
https://github.com/glebtv/tui-textarea.git
synced 2026-09-03 14:26:17 +03:00
Alignment for TextArea (#3)
* Add alignment for text * Add alignment for text * Go back tui version
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
bf4246482e
Коммит
3387f93319
@@ -7,6 +7,7 @@ use crate::search::Search;
|
||||
use crate::util::spaces;
|
||||
use crate::widget::{Renderer, Viewport};
|
||||
use crate::word::{find_word_end_forward, find_word_start_backward};
|
||||
use tui::layout::Alignment;
|
||||
use tui::style::{Modifier, Style};
|
||||
use tui::text::Spans;
|
||||
use tui::widgets::{Block, Widget};
|
||||
@@ -47,6 +48,7 @@ pub struct TextArea<'a> {
|
||||
yank: String,
|
||||
#[cfg(feature = "search")]
|
||||
search: Search,
|
||||
alignment: Alignment,
|
||||
}
|
||||
|
||||
/// Convert any iterator whose elements can be converted into [`String`] into [`TextArea`]. Each [`String`] element is
|
||||
@@ -143,6 +145,7 @@ impl<'a> TextArea<'a> {
|
||||
yank: String::new(),
|
||||
#[cfg(feature = "search")]
|
||||
search: Search::default(),
|
||||
alignment: Alignment::Left,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1269,6 +1272,16 @@ impl<'a> TextArea<'a> {
|
||||
self.cursor
|
||||
}
|
||||
|
||||
/// Get alignment text
|
||||
pub fn set_alignment(&mut self, alignment: Alignment) {
|
||||
self.alignment = alignment;
|
||||
}
|
||||
|
||||
/// Get current alignment text
|
||||
pub fn alignment(&self) -> Alignment {
|
||||
self.alignment
|
||||
}
|
||||
|
||||
/// Check if the textarea has a empty content.
|
||||
/// ```
|
||||
/// use tui_textarea::TextArea;
|
||||
|
||||
@@ -116,7 +116,7 @@ impl<'a> Widget for Renderer<'a> {
|
||||
let top_col = next_scroll_top(top_col, cursor.1 as u16, width);
|
||||
|
||||
let text = self.text(top_row as usize, height as usize);
|
||||
let mut inner = Paragraph::new(text).style(self.0.style());
|
||||
let mut inner = Paragraph::new(text).style(self.0.style()).alignment(self.0.alignment());
|
||||
if let Some(b) = self.0.block() {
|
||||
inner = inner.block(b.clone());
|
||||
}
|
||||
|
||||
Ссылка в новой задаче
Block a user