Switch to step when clicking on explainer

fixes #27
This commit is contained in:
Arne Keller 2021-08-29 08:53:22 +02:00
parent 8b1371ce08
commit 5d4d8cd828
3 changed files with 24 additions and 3 deletions

View File

@ -16,7 +16,14 @@ class MathjaxExplanation extends MathjaxAdapter {
protected calculateSteps(_extraData: any) { protected calculateSteps(_extraData: any) {
let first = true; let first = true;
let stepIdx = 0;
for (let text of this.shadowRoot!.querySelectorAll<SVGGraphicsElement>(".tc-text")) { for (let text of this.shadowRoot!.querySelectorAll<SVGGraphicsElement>(".tc-text")) {
let thisStepIdx = stepIdx;
stepIdx++;
text.onclick = () => {
// @ts-ignore
this.$server!.switchToStep(thisStepIdx);
};
if (first) { if (first) {
first = false; // show first step first = false; // show first step
continue; continue;

View File

@ -1,5 +1,6 @@
package edu.kit.typicalc.view.content.typeinferencecontent; package edu.kit.typicalc.view.content.typeinferencecontent;
import com.vaadin.flow.component.ClientCallable;
import com.vaadin.flow.component.Html; import com.vaadin.flow.component.Html;
import com.vaadin.flow.component.Tag; import com.vaadin.flow.component.Tag;
import com.vaadin.flow.component.dependency.CssImport; import com.vaadin.flow.component.dependency.CssImport;
@ -21,6 +22,7 @@ import java.util.List;
@CssImport("./styles/view/explanation.css") @CssImport("./styles/view/explanation.css")
public class MathjaxExplanation extends LitTemplate implements MathjaxAdapter { public class MathjaxExplanation extends LitTemplate implements MathjaxAdapter {
private final TypeInferenceView typeInferenceView;
private final List<String> latex; private final List<String> latex;
// initialized by Vaadin // initialized by Vaadin
@ -30,13 +32,15 @@ public class MathjaxExplanation extends LitTemplate implements MathjaxAdapter {
/** /**
* Creates a new HTML element that renders the provided texts. * Creates a new HTML element that renders the provided texts.
* *
* @param view the type inference view this explanation text is attached to
* @param latex the latex texts for all steps * @param latex the latex texts for all steps
*/ */
public MathjaxExplanation(List<String> latex) { public MathjaxExplanation(TypeInferenceView view, List<String> latex) {
this.typeInferenceView = view;
this.latex = latex; this.latex = latex;
StringBuilder finalTex = new StringBuilder("<div>"); StringBuilder finalTex = new StringBuilder("<div>");
for (int i = 0; i < latex.size(); i++) { for (int i = 0; i < latex.size(); i++) {
finalTex.append("<p class='tc-text' id='tc-text-").append(i).append("'>"); finalTex.append(String.format("<p class='tc-text' id='tc-text-%d'>", i));
finalTex.append(latex.get(i)); finalTex.append(latex.get(i));
finalTex.append("</p>"); finalTex.append("</p>");
} }
@ -54,5 +58,10 @@ public class MathjaxExplanation extends LitTemplate implements MathjaxAdapter {
public void showStep(int n) { public void showStep(int n) {
getElement().callJsFunction("showStep", n); getElement().callJsFunction("showStep", n);
} }
@ClientCallable
private void switchToStep(int unificationStepIdx) {
typeInferenceView.setCurrentStep(unificationStepIdx);
}
} }

View File

@ -123,7 +123,7 @@ public class TypeInferenceView extends VerticalLayout
container.setId(CONTENT_ID2); container.setId(CONTENT_ID2);
unification = new MathjaxUnification(lc.getUnification()); unification = new MathjaxUnification(lc.getUnification());
var explainer = new ExplanationCreator(typeInferer, getLocale()); var explainer = new ExplanationCreator(typeInferer, getLocale());
this.explanation = new MathjaxExplanation(explainer.getExplanationTexts()); this.explanation = new MathjaxExplanation(this, explainer.getExplanationTexts());
if (tree == null) { if (tree == null) {
tree = new MathjaxProofTree(lc.getTree(), stepAnnotations); tree = new MathjaxProofTree(lc.getTree(), stepAnnotations);
@ -209,6 +209,11 @@ public class TypeInferenceView extends VerticalLayout
refreshElements(); refreshElements();
} }
public void setCurrentStep(int step) {
currentStep = step;
refreshElements();
}
@Override @Override
public void localeChange(LocaleChangeEvent localeChangeEvent) { public void localeChange(LocaleChangeEvent localeChangeEvent) {
if (typeInferer != null) { if (typeInferer != null) {