Skip to content

Commit fad3de8

Browse files
committed
Refactor TextArea Example
1 parent 8b254bf commit fad3de8

4 files changed

Lines changed: 13 additions & 11 deletions

File tree

examples/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,5 +186,5 @@ name = "demo_app"
186186
path = "demo_app/main.rs"
187187

188188
[[example]]
189-
name = "textarea"
190-
path = "textarea/main.rs"
189+
name = "editor"
190+
path = "editor/main.rs"
Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,13 @@ use crate::Viewer;
33

44
use std::fs;
55

6-
const LOGO: [&str; 5] = [
7-
"TTTTT EEEEE X X TTTTT AAAAA RRRR EEEEE AAAAA ",
8-
" T E X X T A A R R E A A ",
9-
" T EEEE X T AAAAAAA RRRR EEEE AAAAAAA ",
10-
" T E X X T A A R R E A A ",
11-
" T EEEEE X X T A A R R EEEEE A A "
6+
const LOGO: [&str; 6] = [
7+
"████████╗███████╗██╗ ██╗████████╗ ███████╗██████╗ ██╗████████╗ ██████╗ ██████╗ ",
8+
"╚══██╔══╝██╔════╝╚██╗██╔╝╚══██╔══╝ ██╔════╝██╔══██╗██║╚══██╔══╝██╔═══██╗██╔══██╗",
9+
" ██║ █████╗ ╚███╔╝ ██║ █████╗ ██║ ██║██║ ██║ ██║ ██║██████╔╝",
10+
" ██║ ██╔══╝ ██╔██╗ ██║ ██╔══╝ ██║ ██║██║ ██║ ██║ ██║██╔══██╗",
11+
" ██║ ███████╗██╔╝ ██╗ ██║ ███████╗██████╔╝██║ ██║ ╚██████╔╝██║ ██║",
12+
" ╚═╝ ╚══════╝╚═╝ ╚═╝ ╚═╝ ╚══════╝╚═════╝ ╚═╝ ╚═╝ ╚═════╝ ╚═╝ ╚═╝",
1213
];
1314

1415
#[Desktop(events = [MenuEvents,DesktopEvents],
@@ -35,7 +36,7 @@ impl OnPaint for MyDesktop {
3536
fn on_paint(&self, surface: &mut Surface, theme: &Theme) {
3637
surface.clear(theme.desktop.character);
3738
let attr = CharAttribute::with_color(theme.desktop.character.foreground,theme.desktop.character.background);
38-
let x = ((surface.size().width as i32) / 2 ) - 38;
39+
let x = ((surface.size().width as i32) / 2 ) - 42;
3940
let mut y = ((surface.size().height as i32) / 2 ) - 3;
4041
for line in LOGO {
4142
surface.write_string(x, y, line, attr, false);
@@ -56,6 +57,7 @@ impl DesktopEvents for MyDesktop {
5657
self.menu_file = self.register_menu(menu!("
5758
&File, class: MyDesktop, items:[
5859
{'&Open',cmd: Open, key: F3},
60+
{---},
5961
{'E&xit',cmd: Exit, key: Escape},
6062
]
6163
"));
@@ -94,7 +96,7 @@ impl MenuEvents for MyDesktop {
9496
if let Some(file_path) = dialogs::open("Open",
9597
"",
9698
dialogs::Location::Last,
97-
Some("Comma separated values = []"),
99+
Some("Text files = []"),
98100
dialogs::OpenFileDialogFlags::Icons
99101
) {
100102
if let Ok(text_print) = fs::read_to_string(&file_path) {
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ impl Viewer {
1010
let mut w = Self {
1111
base: Window::new(path.to_str().unwrap_or("???"), Layout::new("d:c,w:50%,h:50%"), window::Flags::Sizeable),
1212
};
13-
let ta = TextArea::new(text_print, Layout::new("d:c,h:100%"), textarea::Flags::ShowLineNumber | textarea::Flags::ScrollBars);
13+
let ta = TextArea::new(text_print, Layout::new("d:c,w:100%,h:100%"), textarea::Flags::ShowLineNumber | textarea::Flags::ScrollBars);
1414
w.add(ta);
1515
w
1616
}

0 commit comments

Comments
 (0)