DEVELOPMENT ENVIRONMENT

~liljamo/deck-builder

ref: c6ba0da7707a240349fb39833e32d572c87d03dd deck-builder/client/src/util/egui/mod.rs -rw-r--r-- 1.2 KiB
c6ba0da7 — skye fix(client): fix comment in game details ui 1 year, 7 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
/*
 * This file is part of laurelin_client
 * Copyright (C) 2023 Jonni Liljamo <jonni@liljamo.com>
 *
 * Licensed under GPL-3.0-only.
 * See LICENSE for licensing information.
 */

use bevy_egui::egui;

fn password_ui(ui: &mut egui::Ui, password: &mut String) -> egui::Response {
    let state_id = ui.id().with("show_plaintext");

    let mut show_plaintext = ui.data_mut(|d| d.get_temp::<bool>(state_id).unwrap_or(false));

    let result = ui.with_layout(egui::Layout::left_to_right(egui::Align::Center), |ui| {
        // TODO: this was previously add_sized() with a max of ui.available_size()
        // just, a note if... some usecase breaks or something
        ui.add(egui::TextEdit::singleline(password).password(!show_plaintext));

        let response = ui
            .add(egui::SelectableLabel::new(show_plaintext, "👁"))
            .on_hover_text("Show/hide password");

        if response.clicked() {
            show_plaintext = !show_plaintext;
        }
    });

    ui.data_mut(|d| d.insert_temp(state_id, show_plaintext));

    result.response
}

pub fn password(password: &mut String) -> impl egui::Widget + '_ {
    move |ui: &mut egui::Ui| password_ui(ui, password)
}