feat: enable scrolling for every middle panels

This commit is contained in:
Cyrix126 2024-07-21 14:34:02 +02:00
parent e4864c7dd8
commit 3c010f6e2b
4 changed files with 122 additions and 114 deletions

View file

@ -51,125 +51,127 @@ impl P2pool {
let text_edit = size.y / 25.0;
//---------------------------------------------------------------------------------------------------- [Simple] Console
// debug!("P2Pool Tab | Rendering [Console]");
ui.group(|ui| {
let text = &lock!(api).output;
let nb_lines = num_lines(text);
let (height, width) = if self.simple {
((size.y * 0.38) - SPACE, size.x - SPACE)
} else {
(
if size.y < 600.0 {
size.y * 0.22 - SPACE
} else {
size.y * 0.36 - SPACE
},
width - SPACE,
)
};
egui::Frame::none().fill(DARK_GRAY).show(ui, |ui| {
ui.style_mut().override_text_style = Some(Name("MonospaceSmall".into()));
egui::ScrollArea::vertical()
.stick_to_bottom(true)
.max_width(width)
.max_height(height)
.auto_shrink([false; 2])
// .show_viewport(ui, |ui, _| {
.show_rows(
ui,
ui.text_style_height(&TextStyle::Name("MonospaceSmall".into())),
nb_lines,
|ui, row_range| {
for i in row_range {
if let Some(line) = text.lines().nth(i) {
ui.label(line);
}
}
},
);
});
if !self.simple {
//---------------------------------------------------------------------------------------------------- [Advanced] Console
ui.separator();
let response = ui
.add_sized(
[width, text_edit],
TextEdit::hint_text(
TextEdit::singleline(buffer),
r#"Type a command (e.g "help" or "status") and press Enter"#,
),
)
.on_hover_text(P2POOL_INPUT);
// If the user pressed enter, dump buffer contents into the process STDIN
if response.lost_focus() && ui.input(|i| i.key_pressed(egui::Key::Enter)) {
response.request_focus(); // Get focus back
let buffer = std::mem::take(buffer); // Take buffer
let mut process = lock!(process); // Lock
if process.is_alive() {
process.input.push(buffer);
} // Push only if alive
}
}
});
//---------------------------------------------------------------------------------------------------- Args
if !self.simple {
debug!("P2Pool Tab | Rendering [Arguments]");
egui::ScrollArea::vertical().show(ui, |ui| {
ui.group(|ui| {
ui.horizontal(|ui| {
let width = (width / 10.0) - SPACE;
ui.add_sized([width, text_edit], Label::new("Command arguments:"));
ui.add_sized(
[ui.available_width(), text_edit],
TextEdit::hint_text(
TextEdit::singleline(&mut self.arguments),
r#"--wallet <...> --host <...>"#,
),
let text = &lock!(api).output;
let nb_lines = num_lines(text);
let (height, width) = if self.simple {
((size.y * 0.38) - SPACE, size.x - SPACE)
} else {
(
if size.y < 600.0 {
size.y * 0.22 - SPACE
} else {
size.y * 0.36 - SPACE
},
width - SPACE,
)
.on_hover_text(P2POOL_ARGUMENTS);
self.arguments.truncate(1024);
})
};
egui::Frame::none().fill(DARK_GRAY).show(ui, |ui| {
ui.style_mut().override_text_style = Some(Name("MonospaceSmall".into()));
egui::ScrollArea::vertical()
.stick_to_bottom(true)
.max_width(width)
.max_height(height)
.auto_shrink([false; 2])
// .show_viewport(ui, |ui, _| {
.show_rows(
ui,
ui.text_style_height(&TextStyle::Name("MonospaceSmall".into())),
nb_lines,
|ui, row_range| {
for i in row_range {
if let Some(line) = text.lines().nth(i) {
ui.label(line);
}
}
},
);
});
if !self.simple {
//---------------------------------------------------------------------------------------------------- [Advanced] Console
ui.separator();
let response = ui
.add_sized(
[width, text_edit],
TextEdit::hint_text(
TextEdit::singleline(buffer),
r#"Type a command (e.g "help" or "status") and press Enter"#,
),
)
.on_hover_text(P2POOL_INPUT);
// If the user pressed enter, dump buffer contents into the process STDIN
if response.lost_focus() && ui.input(|i| i.key_pressed(egui::Key::Enter)) {
response.request_focus(); // Get focus back
let buffer = std::mem::take(buffer); // Take buffer
let mut process = lock!(process); // Lock
if process.is_alive() {
process.input.push(buffer);
} // Push only if alive
}
}
});
ui.set_enabled(self.arguments.is_empty());
}
//---------------------------------------------------------------------------------------------------- Address
debug!("P2Pool Tab | Rendering [Address]");
ui.group(|ui| {
let width = width - SPACE;
ui.spacing_mut().text_edit_width = (width) - (SPACE * 3.0);
let text;
let color;
let len = format!("{:02}", self.address.len());
if self.address.is_empty() {
text = format!("Monero Address [{}/95] ", len);
color = Color32::LIGHT_GRAY;
} else if Regexes::addr_ok(&self.address) {
text = format!("Monero Address [{}/95] ✔", len);
color = Color32::from_rgb(100, 230, 100);
} else {
text = format!("Monero Address [{}/95] ❌", len);
color = Color32::from_rgb(230, 50, 50);
//---------------------------------------------------------------------------------------------------- Args
if !self.simple {
debug!("P2Pool Tab | Rendering [Arguments]");
ui.group(|ui| {
ui.horizontal(|ui| {
let width = (width / 10.0) - SPACE;
ui.add_sized([width, text_edit], Label::new("Command arguments:"));
ui.add_sized(
[ui.available_width(), text_edit],
TextEdit::hint_text(
TextEdit::singleline(&mut self.arguments),
r#"--wallet <...> --host <...>"#,
),
)
.on_hover_text(P2POOL_ARGUMENTS);
self.arguments.truncate(1024);
})
});
ui.set_enabled(self.arguments.is_empty());
}
ui.add_sized(
[width, text_edit],
Label::new(RichText::new(text).color(color)),
);
ui.add_sized(
[width, text_edit],
TextEdit::hint_text(TextEdit::singleline(&mut self.address), "4..."),
)
.on_hover_text(P2POOL_ADDRESS);
self.address.truncate(95);
});
// let height = ui.available_height();
let size = vec2(width, height);
if self.simple {
//---------------------------------------------------------------------------------------------------- Simple
self.simple(ui, size, ping);
//---------------------------------------------------------------------------------------------------- Advanced
} else {
self.advanced(ui, size, text_edit, node_vec);
}
//---------------------------------------------------------------------------------------------------- Address
debug!("P2Pool Tab | Rendering [Address]");
ui.group(|ui| {
let width = width - SPACE;
ui.spacing_mut().text_edit_width = (width) - (SPACE * 3.0);
let text;
let color;
let len = format!("{:02}", self.address.len());
if self.address.is_empty() {
text = format!("Monero Address [{}/95] ", len);
color = Color32::LIGHT_GRAY;
} else if Regexes::addr_ok(&self.address) {
text = format!("Monero Address [{}/95] ✔", len);
color = Color32::from_rgb(100, 230, 100);
} else {
text = format!("Monero Address [{}/95] ❌", len);
color = Color32::from_rgb(230, 50, 50);
}
ui.add_sized(
[width, text_edit],
Label::new(RichText::new(text).color(color)),
);
ui.add_sized(
[width, text_edit],
TextEdit::hint_text(TextEdit::singleline(&mut self.address), "4..."),
)
.on_hover_text(P2POOL_ADDRESS);
self.address.truncate(95);
});
// let height = ui.available_height();
let size = vec2(width, height);
if self.simple {
//---------------------------------------------------------------------------------------------------- Simple
self.simple(ui, size, ping);
//---------------------------------------------------------------------------------------------------- Advanced
} else {
self.advanced(ui, size, text_edit, node_vec);
}
});
}
}

View file

@ -47,6 +47,7 @@ impl Xmrig {
let text_edit = size.y / 25.0;
//---------------------------------------------------------------------------------------------------- [Simple] Console
debug!("XMRig Tab | Rendering [Console]");
egui::ScrollArea::vertical().show(ui, |ui| {
ui.group(|ui| {
let text = &lock!(api).output;
let nb_lines = num_lines(text);
@ -483,5 +484,6 @@ impl Xmrig {
});
});
}
});
}
}

View file

@ -32,6 +32,7 @@ impl XmrigProxy {
let height = size.y;
let space_h = height / 48.0;
let text_edit = size.y / 25.0;
egui::ScrollArea::vertical().show(ui, |ui| {
ui.vertical_centered(|ui| {
ui.add_space(space_h);
ui.style_mut().override_text_style = Some(TextStyle::Heading);
@ -424,5 +425,6 @@ impl XmrigProxy {
});
});
}
});
}
}

View file

@ -36,6 +36,7 @@ impl crate::disk::state::Xvb {
let width = size.x;
let height = size.y;
let space_h = height / 48.0;
egui::ScrollArea::vertical().show(ui, |ui| {
// logo and website link
ui.vertical_centered(|ui| {
ui.add_sized(
@ -253,5 +254,6 @@ impl crate::disk::state::Xvb {
ui.hyperlink_to("Rules", XVB_URL_RULES)
.on_hover_text("Click here to read the rules and understand how the raffle works.");
});
});
}
}