Skip to content

Commit

Permalink
stone font size support in test board
Browse files Browse the repository at this point in the history
  • Loading branch information
GreenAsJade committed Sep 17, 2024
1 parent 0522df7 commit dac25fe
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
27 changes: 27 additions & 0 deletions examples/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,26 @@ function GobanTestPage(): JSX.Element {
/>
</div>

<div className="setting">
<span>Stone font scale:</span>
<input
type="range"
value={base_config.stone_font_scale as number}
min="0.1"
max="2"
step="0.1"
onChange={(ev) => {
let ss = parseFloat(ev.target.value);
if (!ss) {
ss = 1;
}
base_config.stone_font_scale = ss;
forceUpdate();
fiddler.emit("setStoneFontScale", ss);
}}
/>
</div>

<div className="setting">
<span>Top labels:</span>
<input
Expand Down Expand Up @@ -356,6 +376,13 @@ function ReactGoban<GobanClass extends Goban>(
console.log("SSS time: ", end - start);
});

fiddler.on("setStoneFontScale", (ss) => {
const start = Date.now();
goban.setStoneFontScale(ss);
const end = Date.now();
console.log("SFS time: ", end - start);
});

fiddler.on("redraw", () => {
const start = Date.now();
goban.draw_top_labels = !!base_config.draw_top_labels;
Expand Down
9 changes: 9 additions & 0 deletions src/Goban/Goban.ts
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,15 @@ export abstract class Goban extends OGSConnectivity {
this.redraw(true);
}
}

public setStoneFontScale(new_ss: number, suppress_redraw = false): void {
const redraw = this.stone_font_scale !== new_ss && !suppress_redraw;
this.stone_font_scale = new_ss;
if (redraw) {
this.redraw(true);
}
}

public computeMetrics(): GobanMetrics {
if (!this.square_size || this.square_size <= 0) {
this.square_size = 12;
Expand Down

0 comments on commit dac25fe

Please sign in to comment.