feat: use MTK toolkit widgets in login.elf, improve login.elf draw performance

This commit is contained in:
2026-06-06 17:32:57 +02:00
parent 0728dd58e5
commit 5a34376ce5
8 changed files with 210 additions and 584 deletions
+16 -34
View File
@@ -16,6 +16,9 @@
#include <gui/framebuffer.hpp>
#include <gui/draw.hpp>
#include <gui/font.hpp>
#include <gui/canvas.hpp>
#include <gui/mtk/theme.hpp>
#include <gui/mtk/widgets.hpp>
extern "C" {
unsigned char* stbi_load_from_memory(const unsigned char* buffer, int len,
@@ -29,13 +32,6 @@ enum LoginMode {
MODE_LOGIN,
};
struct FieldEditState {
int cursor;
int sel_anchor;
int sel_end;
bool has_selection;
};
struct LoginState {
gui::Framebuffer fb;
int screen_w, screen_h;
@@ -57,14 +53,20 @@ struct LoginState {
Montauk::MouseState mouse;
uint8_t prev_buttons;
FieldEditState username_edit;
FieldEditState display_name_edit;
FieldEditState password_edit;
FieldEditState confirm_edit;
gui::mtk::TextInputState username_input;
gui::mtk::TextInputState display_name_input;
gui::mtk::TextInputState password_input;
gui::mtk::TextInputState confirm_input;
uint32_t* bg_wallpaper;
int bg_wallpaper_w, bg_wallpaper_h;
bool has_wallpaper;
gui::mtk::Theme theme;
// Packed scratch buffer used only when the framebuffer pitch differs from
// width*4, since Canvas assumes a tightly packed buffer. When pitch is
// already packed we draw straight into the framebuffer back buffer.
uint32_t* compose;
};
inline constexpr gui::Color BG_COLOR = gui::Color::from_rgb(0x00, 0x00, 0x00);
@@ -127,34 +129,14 @@ struct LoginLayout {
struct LoginField {
char* text;
int* len;
int max_len;
bool is_password;
FieldEditState* edit;
int cap; // full buffer size (text capacity incl. null)
bool masked;
gui::mtk::TextInputState* state;
};
bool load_login_wallpaper(LoginState* ls);
LoginField get_field(LoginState* ls, int field);
void reset_field_edit(FieldEditState* edit);
void clear_field_selection(FieldEditState* edit);
void clear_all_field_selections(LoginState* ls);
void clamp_field_edit(FieldEditState* edit, int len);
void field_sel_range(const FieldEditState* edit, int* out_s, int* out_e);
void start_field_selection(FieldEditState* edit);
void update_field_selection(FieldEditState* edit);
int copy_slice(char* out, int cap, const char* text, int start, int end);
int slice_width(const char* text, int start, int end);
int compute_view_start(const char* text, int len, int max_text_w, int cursor);
int compute_view_end(const char* text, int len, int max_text_w, int view_start);
int field_cursor_from_mouse_x(const char* text, int len, int max_text_w,
int anchor_cursor, int rel_x);
void delete_field_range(char* buf, int* len, int start, int count);
void delete_field_selection(char* buf, int* len, FieldEditState* edit);
int password_mask_advance();
int password_slice_width(int start, int end);
int compute_password_view_start(int len, int max_text_w, int cursor);
int compute_password_view_end(int len, int max_text_w, int view_start);
int password_cursor_from_mouse_x(int len, int max_text_w, int anchor_cursor, int rel_x);
LoginLayout layout_login_screen(LoginState* ls);
void draw_login_screen(LoginState* ls);