Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add deferred primitive helper for group #163

Merged
merged 1 commit into from Jul 2, 2019

Conversation

nyaray
Copy link
Contributor

@nyaray nyaray commented May 30, 2019

Description

I noticed that code was getting a bit messy and wanted to put grouping options before the group children.

Motivation and Context

I found that mix formated code ended up looking messy as well as hard to read (as a human) since it put, for example, translation options far away from the group_spec call.

I don't think large graphs get much cleaner than this, without a bit of effort in how specs are represented:

@graph Graph.build(font: :roboto, font_size: 16)
        |> add_specs_to_graph([
          group_spec_r([t: {0, 500}], [
            group_spec_r([t: {500, 0}], [
              button_spec("button 1", t: {0, 0}),
              button_spec("button 2", t: {50, 0})
            ]),
            group_spec_r([t: {600, 0}], [
              button_spec("button A", t: {0, 0}),
              button_spec("button B", t: {50, 0})
            ])
          ]),
          group_spec_r([t: {140, 0}], [
            # this was left out in the other example because it cluttered it
            group_spec_r([t: {0, 110}], [
              Rotary.rotary_spec(0.0, id: {:chan, {:lmf, :q}}, mode: :fill, t: {180, 0}),
              Rotary.rotary_spec(0.0, id: {:chan, {:hmf, :q}}, mode: :fill, t: {220, 0})
            ]),
            # this was left out in the other example because it cluttered it
            group_spec_r([t: {0, 160}], [
              Rotary.add_to_graph(0.0, id: {:chan, {:hpf, :hz}}, mode: :fill, t: {100, 0}),
              Rotary.add_to_graph(0.0, id: {:chan, {:lf, :hz}}, mode: :fill, t: {140, 0}),
              Rotary.add_to_graph(0.0, id: {:chan, {:lmf, :hz}}, mode: :fill, t: {180, 0}),
              Rotary.add_to_graph(0.0, id: {:chan, {:hmf, :hz}}, mode: :fill, t: {220, 0}),
              Rotary.add_to_graph(0.0, id: {:chan, {:hf, :hz}}, mode: :fill, t: {260, 0}),
              Rotary.add_to_graph(0.0, id: {:chan, {:lpf, :hz}}, mode: :fill, t: {300, 0})
            ]),
            group_spec_r([t: {0, 350}], [
              Rotary.rotary_spec(0.50, id: {:chan, {:lf, :db}}, mode: :center, t: {0, 0}),
              Rotary.rotary_spec(0.50, id: {:chan, {:lmf, :db}}, mode: :center, t: {40, 0}),
              Rotary.rotary_spec(0.50, id: {:chan, {:hmf, :db}}, mode: :center, t: {80, 0}),
              Rotary.rotary_spec(0.50, id: {:chan, {:hf, :db}}, mode: :center, t: {120, 0})
            ])
          ])
        ])

The most readable I've found I can get it without group_spec_r is the following, but lines are wasted instead...

@top_button_grid [
  group_spec(
    [
      button_spec("button 1", translate: {0, 0}),
      button_spec("button 2", translate: {50, 0})
    ],
    translate: {500, 0}
  ),
  group_spec(
    [
      button_spec("button A", translate: {0, 0}),
      button_spec("button B", translate: {50, 0})
    ],
    translate: {600, 0}
  )
]

@chan_q ...

@chan_f ...

@chan_db [
  Rotary.rotary_spec(0.50, id: {:chan, {:lf, :db}}, mode: :center, translate: {0, 0}),
  Rotary.rotary_spec(0.50, id: {:chan, {:lmf, :db}}, mode: :center, translate: {40, 0}),
  Rotary.rotary_spec(0.50, id: {:chan, {:hmf, :db}}, mode: :center, translate: {80, 0}),
  Rotary.rotary_spec(0.50, id: {:chan, {:hf, :db}}, mode: :center, translate: {120, 0})
]

@top_controls [
  group_spec(@chan_q, translate: {0, 110}),
  group_spec(@chan_f, translate: {0, 160}),
  group_spec(@chan_db, translate: {0, 350})
]

@top_groups [
  group_spec(@top_button_grid, translate: {0, 500}),
  group_spec(@top_controls, translate: {140, 0})
]

@graph Graph.build(font: :roboto, font_size: 16)
       |> add_specs_to_graph(@top_groups)

Types of changes

  • Bug fix (a non-breaking change which fixes an issue)
  • New feature (a non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to
    not work as expected)
  • Improvement/refactoring (non-breaking change that doesn't add any feature
    but make things better)

Checklist

  • Check other PRs and make sure that the changes are not done yet.
  • The PR title is no longer than 64 characters.

Also, run some example code through mix format and fix a minor credo
issue.
@codecov
Copy link

codecov bot commented May 30, 2019

Codecov Report

Merging #163 into master will decrease coverage by 0.01%.
The diff coverage is 80%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #163      +/-   ##
==========================================
- Coverage   85.88%   85.87%   -0.02%     
==========================================
  Files          87       87              
  Lines        2338     2343       +5     
==========================================
+ Hits         2008     2012       +4     
- Misses        330      331       +1
Impacted Files Coverage Δ
lib/scenic/primitives.ex 93.15% <80%> (-0.97%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 6139eb8...bb98ab6. Read the comment docs.

@boydm
Copy link
Owner

boydm commented Jun 27, 2019

Hey. This is... beautiful.

I'm up to my neck in some other code, but am planning to get back to Scenic updates soon. This will go in for sure.

@nyaray
Copy link
Contributor Author

nyaray commented Jun 27, 2019

Thanks, I'm glad you like it! I had some other ideas about writing something interpreter-y so that graphs could be even more concise (preferring data over functions over macros) with the added benefit of that it would later be easier to build that UI editor that's been mentioned, but then I thought "no, just get something done." Maybe next time 😬

No worries, it'll go in when it goes in.

@boydm boydm merged commit bb98ab6 into boydm:master Jul 2, 2019
0 of 2 checks passed
@nyaray nyaray deleted the env-spec-arg-order branch Jul 2, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants