Refactor 'ui tests' conception to previews
Signed-off-by: kernelkind <kernelkind@gmail.com> Signed-off-by: William Casarin <jb55@jb55.com>
This commit is contained in:
committed by
William Casarin
parent
03e751011b
commit
cf07427204
@@ -104,5 +104,5 @@ name = "notedeck"
|
||||
path = "src/bin/notedeck.rs"
|
||||
|
||||
[[bin]]
|
||||
name = "ui_test_harness"
|
||||
path = "src/tests_ui/main.rs"
|
||||
name = "ui_preview"
|
||||
path = "src/ui_preview/main.rs"
|
||||
|
||||
@@ -7,15 +7,15 @@ use egui::{
|
||||
};
|
||||
use egui::{Image, TextBuffer, TextEdit};
|
||||
|
||||
pub struct AccountLoginView<'a> {
|
||||
pub struct DesktopAccountLoginView<'a> {
|
||||
ctx: &'a egui::Context,
|
||||
manager: &'a mut LoginManager,
|
||||
generate_y_intercept: Option<f32>,
|
||||
}
|
||||
|
||||
impl<'a> AccountLoginView<'a> {
|
||||
impl<'a> DesktopAccountLoginView<'a> {
|
||||
pub fn new(ctx: &'a egui::Context, manager: &'a mut LoginManager) -> Self {
|
||||
AccountLoginView {
|
||||
DesktopAccountLoginView {
|
||||
ctx,
|
||||
manager,
|
||||
generate_y_intercept: None,
|
||||
|
||||
@@ -4,16 +4,38 @@ use eframe::NativeOptions;
|
||||
pub const UI_SCALE_FACTOR: f32 = 0.2;
|
||||
|
||||
pub fn generate_native_options() -> NativeOptions {
|
||||
let window_builder = Box::new(|builder: egui::ViewportBuilder| {
|
||||
generate_native_options_with_builder_modifiers(|builder| {
|
||||
builder
|
||||
.with_fullsize_content_view(true)
|
||||
.with_titlebar_shown(false)
|
||||
.with_title_shown(false)
|
||||
.with_min_inner_size([660.0 * (1.0 + UI_SCALE_FACTOR) , 720.0 * (1.0 + UI_SCALE_FACTOR)])
|
||||
});
|
||||
let mut native_options = eframe::NativeOptions::default();
|
||||
native_options.window_builder = Some(window_builder);
|
||||
native_options
|
||||
.with_min_inner_size([
|
||||
660.0 * (1.0 + UI_SCALE_FACTOR),
|
||||
720.0 * (1.0 + UI_SCALE_FACTOR),
|
||||
])
|
||||
})
|
||||
}
|
||||
|
||||
fn generate_native_options_with_builder_modifiers(apply_builder_modifiers: fn(egui::ViewportBuilder) -> egui::ViewportBuilder) -> NativeOptions {
|
||||
let window_builder =
|
||||
Box::new(
|
||||
move |builder: egui::ViewportBuilder| apply_builder_modifiers(builder)
|
||||
);
|
||||
|
||||
eframe::NativeOptions {
|
||||
window_builder: Some(window_builder),
|
||||
..Default::default()
|
||||
}
|
||||
}
|
||||
|
||||
pub fn generate_mobile_emulator_native_options() -> eframe::NativeOptions {
|
||||
generate_native_options_with_builder_modifiers(|builder| {
|
||||
builder
|
||||
.with_fullsize_content_view(true)
|
||||
.with_titlebar_shown(false)
|
||||
.with_title_shown(false)
|
||||
.with_inner_size([405.0, 915.0])
|
||||
})
|
||||
}
|
||||
|
||||
pub fn setup_cc(cc: &eframe::CreationContext<'_>) {
|
||||
|
||||
@@ -1,21 +0,0 @@
|
||||
use crate::egui_test_setup::{EguiTestCase, EguiTestSetup};
|
||||
use notedeck::account_login_view::AccountLoginView;
|
||||
use notedeck::login_manager::LoginManager;
|
||||
|
||||
pub struct AccountLoginTest {
|
||||
manager: LoginManager,
|
||||
}
|
||||
|
||||
impl EguiTestCase for AccountLoginTest {
|
||||
fn new(_supr: EguiTestSetup) -> Self {
|
||||
AccountLoginTest {
|
||||
manager: LoginManager::new(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl eframe::App for AccountLoginTest {
|
||||
fn update(&mut self, ctx: &egui::Context, _: &mut eframe::Frame) {
|
||||
AccountLoginView::new(ctx, &mut self.manager).panel()
|
||||
}
|
||||
}
|
||||
@@ -1,15 +0,0 @@
|
||||
use notedeck::app_creation::setup_cc;
|
||||
|
||||
pub struct EguiTestSetup {}
|
||||
|
||||
pub trait EguiTestCase: eframe::App {
|
||||
fn new(supr: EguiTestSetup) -> Self;
|
||||
}
|
||||
|
||||
impl EguiTestSetup {
|
||||
pub fn new(cc: &eframe::CreationContext<'_>) -> Self {
|
||||
setup_cc(cc);
|
||||
|
||||
EguiTestSetup {}
|
||||
}
|
||||
}
|
||||
@@ -1,34 +0,0 @@
|
||||
mod account_login_view_test;
|
||||
mod egui_test_setup;
|
||||
use account_login_view_test::AccountLoginTest;
|
||||
use egui_test_setup::{EguiTestCase, EguiTestSetup};
|
||||
use notedeck::app_creation::generate_native_options;
|
||||
use std::env;
|
||||
|
||||
fn run_test_app<F, T, O>(create_supr: F, create_child: O)
|
||||
where
|
||||
F: 'static + FnOnce(&eframe::CreationContext<'_>) -> EguiTestSetup,
|
||||
T: 'static + EguiTestCase,
|
||||
O: 'static + FnOnce(EguiTestSetup) -> T,
|
||||
{
|
||||
tracing_subscriber::fmt::init();
|
||||
|
||||
let _ = eframe::run_native(
|
||||
"UI Test Harness",
|
||||
generate_native_options(),
|
||||
Box::new(|cc| Box::new(create_child(create_supr(cc)))),
|
||||
);
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let args: Vec<String> = env::args().collect();
|
||||
|
||||
if args.len() > 1 {
|
||||
match args[1].as_str() {
|
||||
"AccountLoginView" => run_test_app(EguiTestSetup::new, AccountLoginTest::new),
|
||||
_ => println!("Component not found."),
|
||||
}
|
||||
} else {
|
||||
println!("Please specify a component to test.");
|
||||
}
|
||||
}
|
||||
39
src/ui_preview/account_login_preview.rs
Normal file
39
src/ui_preview/account_login_preview.rs
Normal file
@@ -0,0 +1,39 @@
|
||||
use crate::egui_preview_setup::{EguiPreviewCase, EguiPreviewSetup};
|
||||
use notedeck::account_login_view::{DesktopAccountLoginView, MobileAccountLoginView};
|
||||
use notedeck::login_manager::LoginManager;
|
||||
|
||||
pub struct DesktopAccountLoginPreview {
|
||||
manager: LoginManager,
|
||||
}
|
||||
|
||||
impl EguiPreviewCase for DesktopAccountLoginPreview {
|
||||
fn new(_supr: EguiPreviewSetup) -> Self {
|
||||
DesktopAccountLoginPreview {
|
||||
manager: LoginManager::new(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl eframe::App for DesktopAccountLoginPreview {
|
||||
fn update(&mut self, ctx: &egui::Context, _: &mut eframe::Frame) {
|
||||
DesktopAccountLoginView::new(ctx, &mut self.manager).panel()
|
||||
}
|
||||
}
|
||||
|
||||
pub struct MobileAccountLoginPreview {
|
||||
manager: LoginManager,
|
||||
}
|
||||
|
||||
impl EguiPreviewCase for MobileAccountLoginPreview {
|
||||
fn new(_supr: EguiPreviewSetup) -> Self {
|
||||
MobileAccountLoginPreview {
|
||||
manager: LoginManager::new(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl eframe::App for MobileAccountLoginPreview {
|
||||
fn update(&mut self, ctx: &egui::Context, _: &mut eframe::Frame) {
|
||||
MobileAccountLoginView::new(ctx, &mut self.manager).panel()
|
||||
}
|
||||
}
|
||||
15
src/ui_preview/egui_preview_setup.rs
Normal file
15
src/ui_preview/egui_preview_setup.rs
Normal file
@@ -0,0 +1,15 @@
|
||||
use notedeck::app_creation::setup_cc;
|
||||
|
||||
pub struct EguiPreviewSetup {}
|
||||
|
||||
pub trait EguiPreviewCase: eframe::App {
|
||||
fn new(supr: EguiPreviewSetup) -> Self;
|
||||
}
|
||||
|
||||
impl EguiPreviewSetup {
|
||||
pub fn new(cc: &eframe::CreationContext<'_>) -> Self {
|
||||
setup_cc(cc);
|
||||
|
||||
EguiPreviewSetup {}
|
||||
}
|
||||
}
|
||||
46
src/ui_preview/main.rs
Normal file
46
src/ui_preview/main.rs
Normal file
@@ -0,0 +1,46 @@
|
||||
mod account_login_preview;
|
||||
mod egui_preview_setup;
|
||||
use account_login_preview::{DesktopAccountLoginPreview, MobileAccountLoginPreview};
|
||||
use egui_preview_setup::{EguiPreviewCase, EguiPreviewSetup};
|
||||
use notedeck::app_creation::{generate_native_options, generate_mobile_emulator_native_options};
|
||||
use std::env;
|
||||
|
||||
fn run_test_app<F, T, O>(create_supr: F, create_child: O, is_mobile: bool)
|
||||
where
|
||||
F: 'static + FnOnce(&eframe::CreationContext<'_>) -> EguiPreviewSetup,
|
||||
T: 'static + EguiPreviewCase,
|
||||
O: 'static + FnOnce(EguiPreviewSetup) -> T,
|
||||
{
|
||||
tracing_subscriber::fmt::init();
|
||||
|
||||
let native_options = if is_mobile {
|
||||
generate_mobile_emulator_native_options()
|
||||
} else {
|
||||
generate_native_options()
|
||||
};
|
||||
|
||||
let _ = eframe::run_native(
|
||||
"UI Preview Runner",
|
||||
native_options,
|
||||
Box::new(|cc| Box::new(create_child(create_supr(cc)))),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
fn main() {
|
||||
let args: Vec<String> = env::args().collect();
|
||||
|
||||
if args.len() > 1 {
|
||||
match args[1].as_str() {
|
||||
"DesktopAccountLoginPreview" => {
|
||||
run_test_app(EguiPreviewSetup::new, DesktopAccountLoginPreview::new, false)
|
||||
}
|
||||
"MobileAccountLoginPreview" => {
|
||||
run_test_app(EguiPreviewSetup::new, MobileAccountLoginPreview::new, true)
|
||||
}
|
||||
_ => println!("Component not found."),
|
||||
}
|
||||
} else {
|
||||
println!("Please specify a component to test.");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user