Skip to content

Commit

Permalink
Use theme colors in TreeBrowser
Browse files Browse the repository at this point in the history
  • Loading branch information
lynn committed May 6, 2024
1 parent 46a7ca0 commit 069e99c
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 21 deletions.
5 changes: 3 additions & 2 deletions src/web/Main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ export function Main(props: MainProps) {
const treeImg = useRef<HTMLImageElement>(null);
const [meaningCompact, setMeaningCompact] = useState(false);

const [treeFormat, setTreeFormat] = useState<TreeFormat>('png-latex');
const [treeFormat, setTreeFormat] = useState<TreeFormat>('react');
useEffect(() => {
if (props.mode) generate(props.mode);
else if (latestMode) generate(latestMode);
Expand Down Expand Up @@ -288,13 +288,14 @@ export function Main(props: MainProps) {
<label>
Tree format:
<select
value={treeFormat}
onChange={e => setTreeFormat(e.target.value as TreeFormat)}
>
<option value="react">React</option>
<option value="png-latex">Image (LaTeX)</option>
<option value="png-text">Image (plain text)</option>
<option value="textual">Text art</option>
<option value="json">JSON</option>
<option value="react">React</option>
</select>
</label>
</div>
Expand Down
14 changes: 0 additions & 14 deletions src/web/TreeBrowser.css
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,6 @@
height: 7em;
}

.tree-node-contents:hover {
background: #f0000010;
}

.tree-children {
display: flex;
flex-direction: row;
Expand All @@ -31,20 +27,10 @@
}

.tree-formula {
color: red;
font-size: 7px;
}

.tree-word {
color: #0066ff;
}

.tree-roof {
background: #eeeeff;
cursor: pointer;
padding: 0.5em;
}

.tree-roof:hover {
background: #e2e2ff;
}
21 changes: 16 additions & 5 deletions src/web/TreeBrowser.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,18 @@ import { MathJax } from 'better-react-mathjax';
import { CompactExpr, compact } from '../semantics/compact';
import { Theme } from '../tree/theme';

export function Denotation(props: { denotation: Expr; compact: boolean }) {
export function Denotation(props: {
denotation: Expr;
compact: boolean;
theme: Theme;
}) {
const expr = props.compact ? compact(props.denotation) : props.denotation;
return (
<MathJax className="tree-formula" hideUntilTypeset="every">
<MathJax
className="tree-formula"
hideUntilTypeset="every"
style={{ color: props.theme.denotationColor }}
>
{'$$\\LARGE ' + toLatex(expr) + '$$'}
</MathJax>
);
Expand All @@ -21,8 +29,9 @@ export function Node(props: {
tree: Tree | DTree;
expanded: boolean;
compactDenotations: boolean;
theme: Theme;
}) {
const { tree, compactDenotations } = props;
const { tree, compactDenotations, theme } = props;
return (
<div className="tree-node">
<div className="tree-node-contents">
Expand All @@ -31,11 +40,12 @@ export function Node(props: {
<Denotation
denotation={tree.denotation}
compact={compactDenotations}
theme={theme}
/>
)}
{'word' in tree && (
<>
<div className="tree-word">
<div className="tree-word" style={{ color: theme.wordColor }}>
{tree.word.covert ? tree.word.value : tree.word.text}
</div>
{tree.word.covert ? undefined : (
Expand Down Expand Up @@ -89,6 +99,7 @@ export function TreeBrowser(props: {
tree={tree}
expanded={expanded}
compactDenotations={compactDenotations}
theme={theme}
/>
</div>
{expanded ? (
Expand All @@ -110,7 +121,7 @@ export function TreeBrowser(props: {
preserveAspectRatio="none"
viewBox="0 0 50 10"
>
<path d="M25 0 L50 8 L0 8 Z" fill="none" stroke="black" />
<path d="M25 0 L50 8 L0 8 Z" fill="none" stroke={theme.textColor} />
</svg>
<div className="tree-word">{treeText(tree) || '(expand)'}</div>
</div>
Expand Down

0 comments on commit 069e99c

Please sign in to comment.