DEVELOPMENT ENVIRONMENT

~liljamo/deck-builder

ref: 62b610c09d79dd7b7f844e9e06258e6a2ddef628 deck-builder/sdbclient/src/plugins/menu/accountlogin/ui.rs -rw-r--r-- 3.4 KiB
62b610c0Jonni Liljamo WIP(sdbclient): new login UI 1 year, 8 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
/*
 * This file is part of sdbclient
 * Copyright (C) 2023 Jonni Liljamo <jonni@liljamo.com>
 *
 * Licensed under GPL-3.0-only.
 * See LICENSE for licensing information.
 */

use bevy::prelude::*;
use iyes_loopless::prelude::*;

use belly::prelude::*;

use regex::Regex;

use crate::plugins::menu::MenuState;

use super::LoginState;

/// Login inputs
#[derive(Resource, Debug, Component, PartialEq, Eq, Clone)]
pub(super) struct InputsUserLogin {
    pub email: String,
    pub password: String,
    pub visible_pwd: String,
    pub error: String,
}

impl InputsUserLogin {
    pub fn new() -> Self {
        Self {
            email: "".to_string(),
            password: "".to_string(),
            visible_pwd: "".to_string(),
            error: "".to_string(),
        }
    }
}

pub(super) fn account_login_setup(mut commands: Commands /*, pwd: Res<Password>*/) {
    let input_email = commands.spawn_empty().id();
    let input_password = commands.spawn_empty().id();

    //let visible_pwd = pwd.visible.clone();

    commands.add(eml! {
        <body>
            <div c:menu>
                <span c:menutitle>
                    "Login"
                </span>

                <span>"Email:"</span>
                <textinput {input_email} bind:value=to!(input_email, Label:value | fmt.val("{val}"))/>

                <span>"Password:"</span>
                <textinput {input_password} bind:value=from!(InputsUserLogin:password | fmt.s("{s}"))/>

                <button c:menubutton on:press=connect!(|ctx| {
                    //ctx.commands().insert_resource(NextState(LoginState::LoggingIn))
                })>
                    "Login"
                </button>
                <button c:menubutton on:press=connect!(|ctx| {
                    ctx.commands().insert_resource(NextState(LoginState::None));
                    ctx.commands().insert_resource(NextState(MenuState::AccountLoggedOut));
                })>
                    "Cancel"
                </button>
            </div>
        </body>
    });
}

/*
pub fn account_login_ui(
    mut commands: Commands,
    mut egui_context: ResMut<EguiContext>,
    mut inputs: ResMut<InputsUserLogin>,
) {
    egui::Window::new("Login")
        .collapsible(false)
        .show(egui_context.ctx_mut(), |ui| {
            ui.horizontal(|ui| {
                ui.label("Email: ");
                ui.text_edit_singleline(&mut inputs.email);
            });

            ui.horizontal(|ui| {
                ui.label("Password: ");
                ui.add(eguipwd::password(&mut inputs.password));
            });

            // Show an error if there is one
            if !inputs.error.is_empty() {
                ui.horizontal(|ui| {
                    ui.label(egui::RichText::new(inputs.error.clone()).color(egui::Color32::RED));
                });
            }

            ui.with_layout(egui::Layout::right_to_left(egui::Align::Min), |ui| {
                if ui.button("Cancel").clicked() {
                    commands.insert_resource(NextState(LoginState::None));
                    commands.insert_resource(NextState(MenuState::AccountLoggedOut));
                }
                if ui.button("Login").clicked() {
                    commands.insert_resource(NextState(LoginState::LoggingIn));
                    // Reset error field
                    inputs.error = "".to_string();
                }
            })
        });
}
*/