From 61c222471942382f781117ba34acbb9cb55d77de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9ophile=20Clet?= Date: Fri, 19 Sep 2025 16:37:04 +0200 Subject: [PATCH] nbslot_edit: add documentation and handle more edge cases --- docs/tc.preset.maxref.xml | 10 ++++++++-- javascript/tc.preset.js | 28 ++++++++++++++++++++++------ 2 files changed, 30 insertions(+), 8 deletions(-) diff --git a/docs/tc.preset.maxref.xml b/docs/tc.preset.maxref.xml index 4808bcb..4d1e27e 100644 --- a/docs/tc.preset.maxref.xml +++ b/docs/tc.preset.maxref.xml @@ -189,10 +189,16 @@ Minimum number of rows to display - Defines the minimum number of rows to display if scrollable is enabled and layout is set to 1. - If a preset is stored in a slot with a higher value than min_row, then min_row is ignored and presets are displayed up to the highest stored one. + Defines the minimum number of rows to display if scrollable is enabled. + min_rows gets overridden if the objects size can fit more rows than defined by min_rows, and/or if a stored preset is in a row above min_row. + In other words, min_rows is applied as long as scrollable is enabled, the objects size can fit more rows than min_row without scrolling (the size of a row being defined by bubblesize and margin), or a stored preset lives in a row above min_row. + + + Add/remove rows of presets + When enabled, adds a "-" and "+" buttons at the end of the presets list which, when clicked, respectively remove or add a row of empty slot(s). The minimum number of rows is capped by min_rows. + pattrstorage object to bind to Set the name of the [pattrstorage] to bind to. Its outlet must be connected to the [tc.preset] inlet. diff --git a/javascript/tc.preset.js b/javascript/tc.preset.js index 35f1ba3..8607519 100644 --- a/javascript/tc.preset.js +++ b/javascript/tc.preset.js @@ -84,7 +84,7 @@ var use_uid = 0; // Generating UID for each presets when enabled. Req var recall_passthrough = true; // By default (true), clicking a slot sends a recall message directly to [pattrstorage], and the jsui left outlet outputs a recall message once the recall is done. When disabled, clicking a slot will send a recall message straight from the jsui left outlet, so it's up to the user to forward the message to pattrstorage. It can be usefull for triggering interpolations with custom logic. var ui_rename = false; // Use the attached textedit, if any, to edit slot names directly in the JSUI frame when clicking a slot while holding the control key. When disabled, the textedit remains untouched but gets focused when clicking a slot while holding the control key. var poll_edited = 1; // If >0, check if current preset is edited every X seconds defined by the variable value. -var nbslot_edit = true; // If nbslot_edit and scrollable are enabled, the last two visible slots are replaced by buttons to add or remove lines of slot. +var nbslot_edit = false; // If nbslot_edit and scrollable are enabled, the last two visible slots are replaced by buttons to add or remove lines of slot. // (WORK) var pattrstorage_name, pattrstorage_obj = null; @@ -494,7 +494,6 @@ function paint() //Edited dot if (active_slot_edited && active_slot > 0 && selected_slot <= slots_count_display) { - post("draw edited dot\n"); set_source_rgba(edited_color); ellipse(slots[active_slot].left + 1, slots[active_slot].top + 1, slot_size/3, slot_size/3); fill(); @@ -502,7 +501,7 @@ function paint() // Hovered slot if (last_hovered > -1) { - if (shift_hold) { + if (shift_hold && last_hovered_is_preset_slot) { if (option_hold) { // About to delete set_source_rgba(empty_slot_color[0], empty_slot_color[1], empty_slot_color[2], 0.8); @@ -1486,14 +1485,32 @@ onidleout.local = 1; function onclick(x,y,but,cmd,shift,capslock,option,ctrl) { if (scrollable && nbslot_edit) { + // Click "-" if (last_hovered == true_slots_count_display - 1) { + var tmp_min_rows = min_rows; setmin_rows(min_rows-1); y_offset = -1 * (bg_height - ui_height); + if (tmp_min_rows != min_rows) { + if (layout == 0) { + last_hovered = last_hovered - columns; + } else { + last_hovered = last_hovered - 1; + } + } mgraphics.redraw(); return + // Click "+" } else if (last_hovered == true_slots_count_display) { + var tmp_min_rows = min_rows; setmin_rows(min_rows+1); y_offset = -1 * (bg_height - ui_height); + if (tmp_min_rows != min_rows) { + if (layout == 0) { + last_hovered = last_hovered + columns; + } else { + last_hovered = last_hovered + 1; + } + } mgraphics.redraw(); return } @@ -1501,7 +1518,7 @@ function onclick(x,y,but,cmd,shift,capslock,option,ctrl) if (is_typing_name) { restore_textedit(); } - if (last_hovered > -1 && pattrstorage_name != null) { + if (last_hovered > -1 && pattrstorage_name != null && last_hovered_is_preset_slot) { var output = "recall"; if (select_mode) { output = "select"; @@ -2227,7 +2244,6 @@ function setpoll_edited(v){ function run_edited_poll_task() { if (poll_edited_task.valid && !poll_edited_task.running && poll_edited > 0 && active_slot > 0) { poll_edited_task.interval = poll_edited * 1000; - post("run task!\n"); poll_edited_task.repeat(); } } @@ -2267,7 +2283,7 @@ function edited(v) { } } -declareattribute("nbslot_edit", "getnbslot_edit", "setnbslot_edit", 1, {style: "onoff", label: "Rename In UI"}); +declareattribute("nbslot_edit", "getnbslot_edit", "setnbslot_edit", 1, {style: "onoff", label: "Add/remove rows of presets"}); function getnbslot_edit() { return nbslot_edit; }