Add trailing commas and clean up formatting #108

Merged
glen merged 5 commits from Vectornaut/dyna3:trailing-commas into main 2025-08-04 23:34:35 +00:00
6 changed files with 80 additions and 80 deletions
Showing only changes of commit b02e682e15 - Show all commits

View file

@ -10,9 +10,9 @@ use crate::{
#[component] #[component]
pub fn AddRemove() -> View { pub fn AddRemove() -> View {
view! { view! {
div(id="add-remove") { div(id = "add-remove") {
button( button(
on:click=|_| { on:click = |_| {
let state = use_context::<AppState>(); let state = use_context::<AppState>();
batch(|| { batch(|| {
// this call is batched to avoid redundant realizations. // this call is batched to avoid redundant realizations.
@ -33,18 +33,18 @@ pub fn AddRemove() -> View {
} }
) { "Add sphere" } ) { "Add sphere" }
button( button(
on:click=|_| { on:click = |_| {
let state = use_context::<AppState>(); let state = use_context::<AppState>();
state.assembly.insert_element_default::<Point>(); state.assembly.insert_element_default::<Point>();
} }
) { "Add point" } ) { "Add point" }
button( button(
class="emoji", /* KLUDGE */ // for convenience, we're using an emoji as a temporary icon for this button class = "emoji", /* KLUDGE */ // for convenience, we're using an emoji as a temporary icon for this button
disabled={ disabled = {
let state = use_context::<AppState>(); let state = use_context::<AppState>();
state.selection.with(|sel| sel.len() != 2) state.selection.with(|sel| sel.len() != 2)
}, },
on:click=|_| { on:click = |_| {
let state = use_context::<AppState>(); let state = use_context::<AppState>();
let subjects: [_; 2] = state.selection.with( let subjects: [_; 2] = state.selection.with(
// the button is only enabled when two elements are // the button is only enabled when two elements are

View file

@ -27,15 +27,15 @@ fn RealizationStatus() -> View {
let realization_status = state.assembly.realization_status; let realization_status = state.assembly.realization_status;
view! { view! {
div( div(
id="realization-status", id = "realization-status",
class=realization_status.with( class = realization_status.with(
|status| match status { |status| match status {
Ok(_) => "", Ok(_) => "",
Err(_) => "invalid", Err(_) => "invalid",
} }
) )
) { ) {
glen marked this conversation as resolved

Confused; I thought match branches didn't need commas... seems inconsistent with the vicinity of Err(Message) => in assembly.rs above.

If the point is that a comma is required when the branch is an expression without braces and optional when the branch is enclosed in braces, then I would mildly urge keeping commas after every match branch for consistency. I don't see why match branches should have different punctuation depending on whether or not they happen to be expressions or whatever brace-enclosed things are. Perhaps we shall have to make the commas unnecessary in both contexts in Husht...

p.s. I contemplate another option below which is to always use the braces, and no commas, which might be fine as well until Husht can uniformize this...

Confused; I thought match branches didn't need commas... seems inconsistent with the vicinity of `Err(Message) =>` in assembly.rs above. If the point is that a comma is required when the branch is an expression without braces and optional when the branch is enclosed in braces, then I would mildly urge keeping commas after every match branch for consistency. I don't see why match branches should have different punctuation depending on whether or not they happen to be expressions or whatever brace-enclosed things are. Perhaps we shall have to make the commas unnecessary in both contexts in Husht... p.s. I contemplate another option below which is to always use the braces, and no commas, which might be fine as well until Husht can uniformize this...

If the point is that a comma is required when the branch is an expression without braces and optional when the branch is enclosed in braces […]

Yes, that's the point.

[…] then I would mildly urge keeping commas after every match branch for consistency.

Done, in commit bfd5d8e. I've updated the pull request description to reflect this. Rustfmt can be configured to use this style by setting match_block_trailing_comma to true.

> If the point is that a comma is required when the branch is an expression without braces and optional when the branch is enclosed in braces […] Yes, that's the point. > […] then I would mildly urge keeping commas after every match branch for consistency. Done, in commit bfd5d8e. I've updated the pull request description to reflect this. Rustfmt can be configured to use this style by setting [`match_block_trailing_comma`](https://rust-lang.github.io/rustfmt/?version=v1.8.0&search=#match_block_trailing_comma) to `true`.
div(class="status") div(class = "status")
div { div {
(realization_status.with( (realization_status.with(
|status| match status { |status| match status {
@ -103,7 +103,7 @@ fn LossHistory() -> View {
}); });
view! { view! {
div(id=CONTAINER_ID, class="diagnostics-chart") div(id = CONTAINER_ID, class = "diagnostics-chart")
} }
} }
@ -209,7 +209,7 @@ fn SpectrumHistory() -> View {
}); });
view! { view! {
div(id=CONTAINER_ID, class="diagnostics-chart") div(id = CONTAINER_ID, class = "diagnostics-chart")
} }
} }
@ -218,8 +218,8 @@ fn DiagnosticsPanel(name: &'static str, children: Children) -> View {
let diagnostics_state = use_context::<DiagnosticsState>(); let diagnostics_state = use_context::<DiagnosticsState>();
view! { view! {
div( div(
class="diagnostics-panel", class = "diagnostics-panel",
"hidden"=diagnostics_state.active_tab.with( "hidden" = diagnostics_state.active_tab.with(
|active_tab| { |active_tab| {
if active_tab == name { if active_tab == name {
None None
@ -241,16 +241,16 @@ pub fn Diagnostics() -> View {
provide_context(diagnostics_state); provide_context(diagnostics_state);
view! { view! {
div(id="diagnostics") { div(id = "diagnostics") {
div(id="diagnostics-bar") { div(id = "diagnostics-bar") {
RealizationStatus {} RealizationStatus {}
select(bind:value=active_tab) { select(bind:value = active_tab) {
option(value="loss") { "Loss" } option(value = "loss") { "Loss" }
option(value="spectrum") { "Spectrum" } option(value = "spectrum") { "Spectrum" }
} }
} }
DiagnosticsPanel(name="loss") { LossHistory {} } DiagnosticsPanel(name = "loss") { LossHistory {} }
DiagnosticsPanel(name="spectrum") { SpectrumHistory {} } DiagnosticsPanel(name = "spectrum") { SpectrumHistory {} }
} }
} }
} }

View file

@ -833,12 +833,12 @@ pub fn Display() -> View {
// switch back to integer-valued parameters when that becomes possible // switch back to integer-valued parameters when that becomes possible
// again // again
canvas( canvas(
ref=display, ref = display,
id="display", id = "display",
width="600", width = "600",
height="600", height = "600",
tabindex="0", tabindex = "0",
on:keydown=move |event: KeyboardEvent| { on:keydown = move |event: KeyboardEvent| {
if event.key() == "Shift" { if event.key() == "Shift" {
// swap navigation inputs // swap navigation inputs
roll_cw.set(yaw_right.get()); roll_cw.set(yaw_right.get());
@ -864,7 +864,7 @@ pub fn Display() -> View {
set_manip_signal(&event, 1.0); set_manip_signal(&event, 1.0);
} }
}, },
on:keyup=move |event: KeyboardEvent| { on:keyup = move |event: KeyboardEvent| {
if event.key() == "Shift" { if event.key() == "Shift" {
// swap navigation inputs // swap navigation inputs
yaw_right.set(roll_cw.get()); yaw_right.set(roll_cw.get());
@ -886,7 +886,7 @@ pub fn Display() -> View {
set_manip_signal(&event, 0.0); set_manip_signal(&event, 0.0);
} }
}, },
on:blur=move |_| { on:blur = move |_| {
pitch_up.set(0.0); pitch_up.set(0.0);
pitch_down.set(0.0); pitch_down.set(0.0);
yaw_right.set(0.0); yaw_right.set(0.0);
@ -894,7 +894,7 @@ pub fn Display() -> View {
roll_ccw.set(0.0); roll_ccw.set(0.0);
roll_cw.set(0.0); roll_cw.set(0.0);
}, },
on:click=move |event: MouseEvent| { on:click = move |event: MouseEvent| {
// find the nearest element along the pointer direction // find the nearest element along the pointer direction
let (dir, pixel_size) = event_dir(&event); let (dir, pixel_size) = event_dir(&event);
console::log_1(&JsValue::from(dir.to_string())); console::log_1(&JsValue::from(dir.to_string()));

View file

@ -45,8 +45,8 @@ fn RegulatorInput(regulator: Rc<dyn Regulator>) -> View {
view! { view! {
input( input(
r#type="text", r#type = "text",
class=move || { class = move || {
if valid.get() { if valid.get() {
set_point.with(|set_pt| { set_point.with(|set_pt| {
if set_pt.is_present() { if set_pt.is_present() {
@ -59,9 +59,9 @@ fn RegulatorInput(regulator: Rc<dyn Regulator>) -> View {
"regulator-input invalid" "regulator-input invalid"
} }
}, },
placeholder=measurement.with(|result| result.to_string()), placeholder = measurement.with(|result| result.to_string()),
bind:value=value, bind:value = value,
on:change=move |_| { on:change = move |_| {
valid.set( valid.set(
match SpecifiedValue::try_from(value.get_clone_untracked()) { match SpecifiedValue::try_from(value.get_clone_untracked()) {
Ok(set_pt) => { Ok(set_pt) => {
@ -72,11 +72,11 @@ fn RegulatorInput(regulator: Rc<dyn Regulator>) -> View {
} }
) )
}, },
on:keydown={ on:keydown = {
move |event: KeyboardEvent| { move |event: KeyboardEvent| {
match event.key().as_str() { match event.key().as_str() {
"Escape" => reset_value(), "Escape" => reset_value(),
_ => () _ => (),
} }
} }
}, },
@ -96,11 +96,11 @@ impl OutlineItem for InversiveDistanceRegulator {
self.subjects[0].label() self.subjects[0].label()
}.clone(); }.clone();
view! { view! {
li(class="regulator") { li(class = "regulator") {
div(class="regulator-label") { (other_subject_label) } div(class = "regulator-label") { (other_subject_label) }
div(class="regulator-type") { "Inversive distance" } div(class = "regulator-type") { "Inversive distance" }
RegulatorInput(regulator=self) RegulatorInput(regulator = self)
div(class="status") div(class = "status")
} }
} }
} }
@ -109,11 +109,11 @@ impl OutlineItem for InversiveDistanceRegulator {
impl OutlineItem for HalfCurvatureRegulator { impl OutlineItem for HalfCurvatureRegulator {
fn outline_item(self: Rc<Self>, _element: &Rc<dyn Element>) -> View { fn outline_item(self: Rc<Self>, _element: &Rc<dyn Element>) -> View {
view! { view! {
li(class="regulator") { li(class = "regulator") {
div(class="regulator-label") // for spacing div(class = "regulator-label") // for spacing
div(class="regulator-type") { "Half-curvature" } div(class = "regulator-type") { "Half-curvature" }
RegulatorInput(regulator=self) RegulatorInput(regulator = self)
div(class="status") div(class = "status")
} }
} }
} }
@ -152,10 +152,10 @@ fn ElementOutlineItem(element: Rc<dyn Element>) -> View {
let details_node = create_node_ref(); let details_node = create_node_ref();
view! { view! {
li { li {
details(ref=details_node) { details(ref = details_node) {
summary( summary(
class=class.get(), class = class.get(),
on:keydown={ on:keydown = {
let element_for_handler = element.clone(); let element_for_handler = element.clone();
move |event: KeyboardEvent| { move |event: KeyboardEvent| {
match event.key().as_str() { match event.key().as_str() {
@ -181,12 +181,12 @@ fn ElementOutlineItem(element: Rc<dyn Element>) -> View {
} }
) { ) {
div( div(
class="element-switch", class = "element-switch",
on:click=|event: MouseEvent| event.stop_propagation() on:click = |event: MouseEvent| event.stop_propagation()
) )
div( div(
class="element", class = "element",
on:click={ on:click = {
let state_for_handler = state.clone(); let state_for_handler = state.clone();
let element_for_handler = element.clone(); let element_for_handler = element.clone();
move |event: MouseEvent| { move |event: MouseEvent| {
@ -196,20 +196,20 @@ fn ElementOutlineItem(element: Rc<dyn Element>) -> View {
} }
} }
) { ) {
div(class="element-label") { (label) } div(class = "element-label") { (label) }
div(class="element-representation") { (rep_components) } div(class = "element-representation") { (rep_components) }
input( input(
r#type="checkbox", r#type = "checkbox",
bind:checked=element.ghost(), bind:checked = element.ghost(),
on:click=|event: MouseEvent| event.stop_propagation() on:click = |event: MouseEvent| event.stop_propagation()
) )
} }
} }
ul(class="regulators") { ul(class = "regulators") {
Keyed( Keyed(
list=regulator_list, list = regulator_list,
view=move |reg| reg.outline_item(&element), view = move |reg| reg.outline_item(&element),
key=|reg| reg.serial() key = |reg| reg.serial()
) )
} }
} }
@ -242,18 +242,18 @@ pub fn Outline() -> View {
view! { view! {
ul( ul(
id="outline", id = "outline",
on:click={ on:click = {
let state = use_context::<AppState>(); let state = use_context::<AppState>();
move |_| state.selection.update(|sel| sel.clear()) move |_| state.selection.update(|sel| sel.clear())
} }
) { ) {
Keyed( Keyed(
list=element_list, list = element_list,
view=|elt| view! { view = |elt| view! {
ElementOutlineItem(element=elt) ElementOutlineItem(element = elt)
}, },
key=|elt| elt.serial() key = |elt| elt.serial()
) )
} }
} }

View file

@ -925,17 +925,17 @@ pub fn TestAssemblyChooser() -> View {
// build the chooser // build the chooser
view! { view! {
select(bind:value=assembly_name) { select(bind:value = assembly_name) {
option(value="general") { "General" } option(value = "general") { "General" }
option(value="low-curv") { "Low-curvature" } option(value = "low-curv") { "Low-curvature" }
option(value="pointed") { "Pointed" } option(value = "pointed") { "Pointed" }
option(value="tridim-icosahedron") { "Tridiminished icosahedron" } option(value = "tridim-icosahedron") { "Tridiminished icosahedron" }
option(value="dodeca-packing") { "Dodecahedral packing" } option(value = "dodeca-packing") { "Dodecahedral packing" }
option(value="balanced") { "Balanced" } option(value = "balanced") { "Balanced" }
option(value="off-center") { "Off-center" } option(value = "off-center") { "Off-center" }
option(value="radius-ratio") { "Radius ratio" } option(value = "radius-ratio") { "Radius ratio" }
option(value="irisawa-hexlet") { "Irisawa hexlet" } option(value = "irisawa-hexlet") { "Irisawa hexlet" }
option(value="empty") { "Empty" } option(value = "empty") { "Empty" }
} }
} }
} }

View file

@ -58,7 +58,7 @@ fn main() {
provide_context(AppState::new()); provide_context(AppState::new());
view! { view! {
div(id="sidebar") { div(id = "sidebar") {
AddRemove {} AddRemove {}
Outline {} Outline {}
Diagnostics {} Diagnostics {}