Skip to content

Commit

Permalink
fix toolbar selection when ESC is pressed (#126)
Browse files Browse the repository at this point in the history
de-select a mode by clicking on toolbar item a second time
  • Loading branch information
pfalstad committed Dec 9, 2024
1 parent 1dab1a7 commit 76da2e8
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 15 deletions.
26 changes: 13 additions & 13 deletions src/com/lushprojects/circuitjs1/client/CirSim.java
Original file line number Diff line number Diff line change
Expand Up @@ -3581,10 +3581,7 @@ else if (s.compareTo("DragPost") == 0)
else if (s.compareTo("Select") == 0)
setMouseMode(MODE_SELECT);

String label = classToLabelMap.get(item);
if (label != null)
toolbar.setModeLabel(label);
toolbar.highlightButton(mouseModeStr);
updateToolbar();

// else if (s.length() > 0) {
// try {
Expand Down Expand Up @@ -5584,6 +5581,7 @@ public void onPreviewNativeEvent(NativePreviewEvent e) {
if (code==KEY_ESCAPE){
setMouseMode(MODE_SELECT);
mouseModeStr = "Select";
updateToolbar();
tempMouseMode = mouseMode;
e.cancel();
}
Expand Down Expand Up @@ -5646,22 +5644,24 @@ public void onPreviewNativeEvent(NativePreviewEvent e) {
return;
setMouseMode(MODE_ADD_ELM);
mouseModeStr=c;
toolbar.highlightButton(mouseModeStr);
String label = classToLabelMap.get(c);
if (label != null)
toolbar.setModeLabel(label);
updateToolbar();
tempMouseMode = mouseMode;
}
if (cc==32) {
setMouseMode(MODE_SELECT);
mouseModeStr = "Select";
toolbar.setModeLabel(classToLabelMap.get(mouseModeStr));
tempMouseMode = mouseMode;
e.cancel();
setMouseMode(MODE_SELECT);
mouseModeStr = "Select";
updateToolbar();
tempMouseMode = mouseMode;
e.cancel();
}
}
}

void updateToolbar() {
toolbar.setModeLabel(classToLabelMap.get(mouseModeStr));
toolbar.highlightButton(mouseModeStr);
}

// factors a matrix into upper and lower triangular matrices by
// gaussian elimination. On entry, a[0..n-1][0..n-1] is the
// matrix to be factored. ipvt[] returns an integer vector of pivot
Expand Down
7 changes: 5 additions & 2 deletions src/com/lushprojects/circuitjs1/client/Toolbar.java
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,10 @@ private Label createIconButton(String iconClass, String tooltip, MyCommand comma
public void onClick(ClickEvent event) {
// un-highlight
iconLabel.getElement().getStyle().setColor("#333");
command.execute();
if (iconLabel == activeButton)
new MyCommand("main", "Select").execute();
else
command.execute();
}
});

Expand Down Expand Up @@ -263,7 +266,7 @@ public void setEuroResistors(boolean euro) {

final String inductIcon = "<svg><g transform='translate(-101.59,-58.18) scale(0.405680)'><path fill='none' stroke='currentColor' d=' M 256 176 L 264 176' stroke-linecap='round' stroke-width='3' /><path fill='none' stroke='currentColor' d=' M 296 176 L 304 176' stroke-linecap='round' stroke-width='3' /><g transform='matrix(1,0,0,1,264,176) scale(1,1)'><path fill='none' stroke='currentColor' d=' M 0 0 L 0 6.53144959545255e-16 A 5.333333333333333 5.333333333333333 0 0 1 10.666666666666666 0 L 10.666666666666666 0' stroke-linecap='round' stroke-width='3' /><path fill='none' stroke='currentColor' d=' M 10.666666666666666 0 L 10.666666666666668 6.53144959545255e-16 A 5.333333333333333 5.333333333333333 0 0 1 21.333333333333332 0 L 21.333333333333332 0' stroke-linecap='round' stroke-width='3' /><path fill='none' stroke='currentColor' d=' M 21.333333333333332 0 L 21.333333333333336 6.53144959545255e-16 A 5.333333333333333 5.333333333333333 0 0 1 32 0 L 32 0' stroke-linecap='round' stroke-width='3' /></g><path fill='currentColor' stroke='currentColor' d=' M 259 176 A 3 3 0 1 1 258.99973922528994 175.96044522459943 Z' /><path fill='currentColor' stroke='currentColor' d=' M 307 176 A 3 3 0 1 1 306.99973922528994 175.96044522459943 Z' /></g></svg>";

final String railIcon = "<svg><g><text fill='currentColor' stroke='none' font-family='sans-serif' font-size='10px' font-style='normal' font-weight='normal' text-decoration='normal' x='2' y='11' text-anchor='start' dominant-baseline='central'>+5V</text></g></svg>";
final String railIcon = "<svg><g><text style='user-select: none;' fill='currentColor' stroke='none' font-family='sans-serif' font-size='10px' font-style='normal' font-weight='normal' text-decoration='normal' x='2' y='11' text-anchor='start' dominant-baseline='central'>+5V</text></g></svg>";

final String andIcon = "<svg><g transform='translate(-143.64,-130.55) scale(0.363636)'><path fill='none' stroke='currentColor' d=' M 400 400 L 414 400' stroke-linecap='round' stroke-width='3' /><path fill='none' stroke='currentColor' d=' M 400 384 L 414 384' stroke-linecap='round' stroke-width='3' /><path fill='none' stroke='currentColor' d=' M 442 392 L 456 392' stroke-linecap='round' stroke-width='3' /><path fill='none' stroke='currentColor' d=' M 414 378 L 428 378 A 14 14 0 0 1 428 406 L 414 406 Z' stroke-linecap='round' stroke-width='3' /></g></svg>";
final String orIcon = "<svg><g transform='translate(-143.64,-153.82) scale(0.363636)'><path fill='none' stroke='currentColor' d=' M 400 464 L 414 464' stroke-linecap='round' stroke-width='3' /><path fill='none' stroke='currentColor' d=' M 400 448 L 414 448' stroke-linecap='round' stroke-width='3' /><path fill='none' stroke='currentColor' d=' M 442 456 L 456 456' stroke-linecap='round' stroke-width='3' /><path fill='none' stroke='currentColor' d=' M 413 442 L 422 442 C 434 445 434 445 442 456 C 434 467 434 467 422 470 L 413 470 C 416 456 416 456 413 442 Z' stroke-linecap='round' stroke-width='3' /></g></svg>";
Expand Down

0 comments on commit 76da2e8

Please sign in to comment.