From 79988a41e07c02a9e09c15c429e03a937a8eec6d Mon Sep 17 00:00:00 2001
From: hinto-janaiyo <hinto.janaiyo@protonmail.com>
Date: Sun, 27 Nov 2022 21:47:50 -0500
Subject: [PATCH] p2pool: add sized, scrollable, selectable but not mutable
 console

This replaces the old mutable [TextEdit] with an immutable one
with a scroll area wrapped in a [Frame]. Passing a [&str] instead
of a [String] to [TextEdit] makes it auto-select only and not
mutable by the user. The background color is changed because the
immutable [TextEdit] has a hardcoded light gray color (same as the
general ui background).
---
 src/main.rs   |  1 +
 src/p2pool.rs | 19 ++++++++++++++++++-
 2 files changed, 19 insertions(+), 1 deletion(-)

diff --git a/src/main.rs b/src/main.rs
index 7892084..ec28943 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -443,6 +443,7 @@ fn init_text_styles(ctx: &egui::Context, width: f32) {
 	style.spacing.icon_width_inner = width / 35.0;
 	style.spacing.icon_width = width / 25.0;
 	style.spacing.icon_spacing = 20.0;
+	style.spacing.scroll_bar_width = width / 150.0;
 	ctx.set_style(style);
 	ctx.set_pixels_per_point(1.0);
 	ctx.request_repaint();
diff --git a/src/p2pool.rs b/src/p2pool.rs
index 2717d72..cdc758c 100644
--- a/src/p2pool.rs
+++ b/src/p2pool.rs
@@ -38,7 +38,24 @@ impl P2pool {
 		let height = height / 10.0;
 		let width = width - SPACE;
 		ui.style_mut().override_text_style = Some(Monospace);
-		ui.add_sized([width, height*3.5], TextEdit::multiline(&mut "".to_string()));
+		//ui.add_sized([width, height*3.5], TextEdit::multiline(&mut "asdf"));
+egui::Frame::none()
+.fill(Color32::from_rgb(18, 18, 18))
+.show(ui, |ui| {
+		let text_style = egui::TextStyle::Monospace;
+		let row_height = ui.text_style_height(&text_style);
+		let total_rows = 10_000;
+		let width = width-(SPACE*2.0);
+		egui::ScrollArea::vertical().max_width(width).max_height(height*3.5).auto_shrink([false; 2]).show_rows(ui, row_height, total_rows, |ui, row_range| {
+			let mut text = "".to_string();
+			for row in row_range {
+				text = format!("{}Row {}/{}\n", text, row + 1, total_rows);
+//				ui.label(text);
+			}
+			ui.add_sized([width, height*3.5], TextEdit::multiline(&mut text.as_str()));
+		});
+});
+		ui.separator();
 		ui.add_sized([width, text_edit], TextEdit::hint_text(TextEdit::singleline(&mut "".to_string()), r#"Type a command (e.g "help" or "status") and press Enter"#));
 	});