Blender's GPU Accelerated UI, Decoupled from it's original codebase. Supports Rust, Python, JS, React, C & C++. Twice as good as GPUI
reset default
Preetham Pemmasani6b3a82acfe6b
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 5e1a764..c9c5f5e 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -7,6 +7,14 @@ All notable changes to **blenderui** (BUI). The format follows## [Unreleased]### Fixed+- **Backspace over a Blender value resets it to its default, not to zero** (number fields, sliders,+ vector fields, checkboxes; the right-click "Reset to Default Value" already did, and the docs always+ said Backspace resets to the default). A widget's default is the value it was made with, or an+ explicit `default`, in every language: the kit records the first value a widget gets as its default+ (`NF_DEFAULT_SET`) and the dead "zero" flag of `reset` is gone. Text fields still clear.+- **Website:** the interactive panel on the home page is labelled as a browser sketch, and it now does+ what the text next to it says: dragging down across X, Y and Z edits all three, and Ctrl+C / Ctrl+V+ over a field copy and paste a value.- **macOS:** Python printed `objc: Class BUIKitView is implemented in both buipy... and_buiimgui...` (also `BUIKitNSWindow`, `BUIKitWindowDelegate`, `BUIKitAppDelegate`) when bothextensions were loaded: each linked the whole kit, Cocoa host included, so the classes werediff --git a/bindings/python/tests/test_components.py b/bindings/python/tests/test_components.pyindex 83c05b3..4b31504 100644--- a/bindings/python/tests/test_components.py+++ b/bindings/python/tests/test_components.py@@ -163,7 +163,7 @@ def test_slider_relative_drag():def test_value_shortcuts():- a, b = NumberField("A", 3.5), NumberField("B", 0.0)+ a, b = NumberField("A", 3.5), NumberField("B", 2.0) # B's default is the 2.0 it was made withd = Driver(Column(a, b))d.hover(a)d.key("c", "c", mods(ctrl=True)) # copy@@ -172,9 +172,9 @@ def test_value_shortcuts():assert b.value == 3.5d.key("minus", "-") # negateassert b.value == -3.5- d.key("BackSpace") # clear- assert b.value == 0- assert d.wheel(b, +1, mods(ctrl=True)) and abs(b.value - 0.1) < 1e-9 # Ctrl+Wheel+ d.key("BackSpace") # reset to the default, not to zero+ assert b.value == 2.0+ assert d.wheel(b, +1, mods(ctrl=True)) and abs(b.value - 2.1) < 1e-9 # Ctrl+Wheeldef test_checkbox_drag_toggle():@@ -272,9 +272,10 @@ def test_vector_and_color():v = VectorField("Loc", (1.0, 2.0, 3.0), on_change=seen.append)sw = ColorSwatch("", (1.0, 0.0, 0.0, 1.0))d = Driver(Column(v, sw))+ v.fields[1].set_value(7.0)d.hover(v.fields[1])- d.key("BackSpace")- assert v.value == (1.0, 0.0, 3.0) and seen[-1] == (1.0, 0.0, 3.0)+ d.key("BackSpace") # back to the 2.0 it was made with+ assert v.value == (1.0, 2.0, 3.0) and seen[-1] == (1.0, 2.0, 3.0)d.click(sw)tabs = d.ctx.picker_part("tabs")d.click(tabs, dx=5) # RGB tabdiff --git a/bindings/rust/blenderui/tests/headless.rs b/bindings/rust/blenderui/tests/headless.rsindex 880abe3..279bf33 100644--- a/bindings/rust/blenderui/tests/headless.rs+++ b/bindings/rust/blenderui/tests/headless.rs@@ -302,3 +302,37 @@ fn incremental_frames_match_fresh_renders() {}});}++struct Number {+ number: Option<f64>,+}++impl Render for Number {+ fn render(&mut self, _: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {+ body().m_0().child(NumberField().id("n").attr("value", "5").on_change(cx.listener(+ |this, e: &ChangeEvent, _, cx| {+ this.number = Some(e.number);+ cx.notify();+ },+ )))+ }+}++/// Backspace over a Blender field goes back to the value it was made with (not to zero).+#[test]+fn backspace_resets_to_the_value_the_field_was_made_with() {+ Application::headless().run(|cx| {+ let win = open(cx, 300.0, 100.0, Number { number: None });+ let id = win.id;+ cx.draw(id);+ let n = cx.element_bounds(id, "n").unwrap();+ let (x, y) = (n.origin.x + n.size.width / 2.0, n.origin.y + n.size.height / 2.0);+ cx.simulate_drag(id, (x, y), (x + 60.0, y));+ let moved = win.root().read(cx).number.expect("the drag changes the value");+ assert!((moved - 5.0).abs() > 0.01, "the drag should change the value, got {moved}");+ cx.simulate_mouse_move(id, x, y);+ cx.simulate_key(id, "", "BackSpace");+ let back = win.root().read(cx).number.unwrap();+ assert!((back - 5.0).abs() < 1e-9, "Backspace should give 5, got {back}");+ });+}diff --git a/docs/components.md b/docs/components.mdindex ec68228..157369f 100644--- a/docs/components.md+++ b/docs/components.md@@ -68,7 +68,7 @@ Value components (`NumberField`, `NumberSlider`, `Checkbox`, `Toggle`,|---|---|| `value` | Current value (assigning it notifies `on_change`) || `set_value(v, notify=True)` | Set, optionally without the callback |-| `reset()` | Back to the default (also Backspace over the widget) |+| `reset()` | Back to the default: the value the widget was made with, or its explicit `default` (also Backspace over the widget; text fields clear) || `on_change=` | `fn(value)`, called when the user or code changes it |## Layoutdiff --git a/kit/intern/kit_core.c b/kit/intern/kit_core.cindex 9b6a9f4..3de02ee 100644--- a/kit/intern/kit_core.c+++ b/kit/intern/kit_core.c@@ -604,7 +604,7 @@ static void vc_reset(void *data){BKNode *n = (BKNode *)data;if (n->cls->reset) {- n->cls->reset(n, false);+ n->cls->reset(n);}}@@ -644,7 +644,7 @@ int bk_value_key(BKNode *n, BKEvent *e)}if (bk_keysym_is(e->keysym, "BackSpace")) {if (c->reset) {- c->reset(n, true);+ c->reset(n);}return 1;}@@ -933,6 +933,10 @@ int BK_set_num(BKNode *n, const char *key, double v)bk_relayout(n);}else {+ if (!(n->flags & NF_DEFAULT_SET)) { /* the value a widget is made with is its default */+ n->defval = v;+ n->flags |= NF_DEFAULT_SET;+ }bk_set_value_silent(n, v);}return 1;@@ -943,6 +947,7 @@ int BK_set_num(BKNode *n, const char *key, double v)}if (strcmp(key, "default") == 0) {n->defval = v;+ n->flags |= NF_DEFAULT_SET;return 1;}if (strcmp(key, "min") == 0) {diff --git a/kit/intern/kit_intern.h b/kit/intern/kit_intern.hindex 1a25136..a8ef667 100644--- a/kit/intern/kit_intern.h+++ b/kit/intern/kit_intern.h@@ -274,7 +274,7 @@ typedef struct BKClass {int (*to_text)(BKNode *n, char *buf, int size);int (*from_text)(BKNode *n, const char *s); /* 1 when set */void (*step)(BKNode *n, int dir);- void (*reset)(BKNode *n, bool to_zero);+ void (*reset)(BKNode *n); /* back to the default (Backspace, "Reset to Default Value") */void (*negate)(BKNode *n);void (*activate)(BKNode *n);/* class-specific properties (consulted before the generic ones) */@@ -331,6 +331,7 @@ enum {NF_OPAQUE = 1 << 24, /* root: the host paints every pixel, skip the region clear */NF_HTML = 1 << 25, /* "html": Chrome's default form-control look and interaction */NF_ACTIVE_DEFAULT = 1 << 26, /* buttons: UI_BUT_ACTIVE_DEFAULT (drawn with the select colors) */+ NF_DEFAULT_SET = 1 << 27, /* `defval` was set: by "default", or by the first "value" a widget got */};#define BK_HTML(n) (((n)->flags & NF_HTML) != 0)diff --git a/kit/intern/kit_views.c b/kit/intern/kit_views.cindex c3827b0..996c458 100644--- a/kit/intern/kit_views.c+++ b/kit/intern/kit_views.c@@ -997,7 +997,7 @@ static int tree_to_text(BKNode *n, char *buf, int size)return 1;}-static void tree_reset(BKNode *n, bool zero)+static void tree_reset(BKNode *n){}diff --git a/kit/intern/kit_widgets.c b/kit/intern/kit_widgets.cindex 0658d16..737f2ab 100644--- a/kit/intern/kit_widgets.c+++ b/kit/intern/kit_widgets.c@@ -1647,9 +1647,9 @@ static void bool_step(BKNode *n, int dir)bool_toggle(n);}-static void bool_reset(BKNode *n, bool zero)+static void bool_reset(BKNode *n){- bk_set_value(n, zero ? 0 : n->defval);+ bk_set_value(n, n->defval);}static int bool_press(BKNode *n, BKEvent *e)@@ -1811,9 +1811,9 @@ static void number_step(BKNode *n, int dir)bk_set_value(n, n->value + dir * step);}-static void number_reset(BKNode *n, bool zero)+static void number_reset(BKNode *n){- bk_set_value(n, zero ? 0.0 : n->defval);+ bk_set_value(n, n->defval);}static void number_negate(BKNode *n)@@ -2345,7 +2345,7 @@ static int text_from_text(BKNode *n, const char *s)return 1;}-static void text_reset(BKNode *n, bool zero)+static void text_reset(BKNode *n){text_from_text(n, "");}@@ -2690,7 +2690,7 @@ static void choice_step(BKNode *n, int dir)}}-static void choice_reset(BKNode *n, bool zero)+static void choice_reset(BKNode *n){bk_set_value(n, n->defval);}@@ -3018,7 +3018,7 @@ static int swatch_from_text(BKNode *n, const char *s)return 1;}-static void swatch_reset(BKNode *n, bool zero)+static void swatch_reset(BKNode *n){const float black[4] = {0, 0, 0, 1};BK_set_color(n, "set_value", black);diff --git a/website/src/content/docs/concepts/blender-widgets.mdx b/website/src/content/docs/concepts/blender-widgets.mdxindex cb7bf68..8771b7f 100644--- a/website/src/content/docs/concepts/blender-widgets.mdx+++ b/website/src/content/docs/concepts/blender-widgets.mdx@@ -87,7 +87,7 @@ Hover a value (number, slider, checkbox, color …) and use these:| <Kbd keys="Ctrl+Wheel" /> | Steps the value up or down || <Kbd keys="Ctrl+C" /> / <Kbd keys="Ctrl+V" /> | Copies or pastes the value || <Kbd keys="Ctrl+Alt+C" /> / <Kbd keys="Ctrl+Alt+V" /> | Copies or pastes a whole vector (X, Y and Z together) |-| <Kbd>Backspace</Kbd> | Resets to the default |+| <Kbd>Backspace</Kbd> | Resets to the default: the value the widget was made with, or its explicit `default`. Text fields clear. || <Kbd>-</Kbd> | Negates a number || Right-click | Opens the context menu: Copy, Paste, Reset |