feat: improve MTK input boxes, right-click context menus
This commit is contained in:
@@ -79,6 +79,7 @@ struct AppState {
|
||||
int config_button_down;
|
||||
char edit_uri[MAX_PATH_LEN];
|
||||
int edit_len;
|
||||
mtk::TextInputState edit_input;
|
||||
char edit_error[128];
|
||||
int mouse_x;
|
||||
int mouse_y;
|
||||
@@ -473,6 +474,7 @@ static void close_config_popup() {
|
||||
static void open_config_popup() {
|
||||
safe_copy(g_app.edit_uri, sizeof(g_app.edit_uri), g_app.printer_uri);
|
||||
g_app.edit_len = montauk::slen(g_app.edit_uri);
|
||||
mtk::text_input_reset(g_app.edit_input, g_app.edit_len);
|
||||
g_app.edit_error[0] = '\0';
|
||||
g_app.config_button_down = 0;
|
||||
g_app.config_mouse_x = -1;
|
||||
@@ -535,8 +537,10 @@ static void render_config_popup() {
|
||||
c.text(x, y, "Enter an IPP or IPPS destination URI.", theme.text_muted);
|
||||
|
||||
mtk::draw_labeled_text_field(c, lo.input.x, lo.input_label_y, lo.input.w,
|
||||
"Printer URI", g_app.edit_uri, g_app.edit_len,
|
||||
true, false, theme, lo.input.h);
|
||||
"Printer URI", g_app.edit_uri,
|
||||
g_app.edit_input.cursor,
|
||||
true, false, theme, lo.input.h,
|
||||
g_app.edit_input.selection_anchor);
|
||||
|
||||
y = lo.input.y + lo.input.h + 12;
|
||||
c.text(x, y, "Example: ipp://printer.local/ipp/print", theme.text_muted);
|
||||
@@ -552,6 +556,10 @@ static void render_config_popup() {
|
||||
lo.cancel_btn, "Cancel",
|
||||
config_button_state(lo.cancel_btn, true, g_app.config_button_down == 2),
|
||||
theme);
|
||||
mtk::draw_text_input_context_menu(
|
||||
c, g_app.edit_input, theme,
|
||||
mtk::text_input_has_selection(g_app.edit_input,
|
||||
g_app.edit_uri, MAX_PATH_LEN));
|
||||
montauk::win_present(g_config.win_id);
|
||||
}
|
||||
|
||||
@@ -563,8 +571,38 @@ static bool handle_config_mouse(int mx, int my, uint8_t buttons, uint8_t prev_bu
|
||||
|
||||
bool left_pressed = (buttons & 1) && !(prev_buttons & 1);
|
||||
bool left_released = !(buttons & 1) && (prev_buttons & 1);
|
||||
bool right_pressed = (buttons & 2) && !(prev_buttons & 2);
|
||||
|
||||
if (g_app.edit_input.context.open || g_app.edit_input.dragging) {
|
||||
int result = mtk::text_input_handle_mouse(g_app.edit_input, lo.input,
|
||||
g_app.edit_uri, MAX_PATH_LEN,
|
||||
mx, my, buttons, prev_buttons,
|
||||
g_config.width, g_config.height,
|
||||
true);
|
||||
if (result & mtk::TEXT_INPUT_CHANGED) {
|
||||
g_app.edit_len = mtk::text_input_len(g_app.edit_uri, MAX_PATH_LEN);
|
||||
g_app.edit_error[0] = '\0';
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
if (left_pressed || right_pressed) {
|
||||
if (lo.input.contains(mx, my)) {
|
||||
g_app.config_button_down = 0;
|
||||
int result = mtk::text_input_handle_mouse(g_app.edit_input, lo.input,
|
||||
g_app.edit_uri, MAX_PATH_LEN,
|
||||
mx, my, buttons, prev_buttons,
|
||||
g_config.width, g_config.height,
|
||||
true);
|
||||
if (result & mtk::TEXT_INPUT_CHANGED) {
|
||||
g_app.edit_len = mtk::text_input_len(g_app.edit_uri, MAX_PATH_LEN);
|
||||
g_app.edit_error[0] = '\0';
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!left_pressed) return false;
|
||||
|
||||
if (left_pressed) {
|
||||
int button_down = 0;
|
||||
if (lo.save_btn.contains(mx, my))
|
||||
button_down = 1;
|
||||
@@ -601,17 +639,11 @@ static bool handle_config_key(const Montauk::KeyEvent& key) {
|
||||
save_configured_printer();
|
||||
return !g_app.config_open;
|
||||
}
|
||||
if (key.ascii == '\b' || key.scancode == 0x0E) {
|
||||
if (g_app.edit_len > 0) {
|
||||
g_app.edit_len--;
|
||||
g_app.edit_uri[g_app.edit_len] = '\0';
|
||||
g_app.edit_error[0] = '\0';
|
||||
}
|
||||
return false;
|
||||
}
|
||||
if (key.ascii >= 0x20 && key.ascii < 0x7F && g_app.edit_len < MAX_PATH_LEN - 1) {
|
||||
g_app.edit_uri[g_app.edit_len++] = key.ascii;
|
||||
g_app.edit_uri[g_app.edit_len] = '\0';
|
||||
|
||||
int result = mtk::text_input_key(g_app.edit_input, g_app.edit_uri,
|
||||
MAX_PATH_LEN, key);
|
||||
if (result & mtk::TEXT_INPUT_CHANGED) {
|
||||
g_app.edit_len = mtk::text_input_len(g_app.edit_uri, MAX_PATH_LEN);
|
||||
g_app.edit_error[0] = '\0';
|
||||
}
|
||||
return false;
|
||||
|
||||
Reference in New Issue
Block a user