Skip to content

Commit 3d5d408

Browse files
committed
whiteboard: select font size
1 parent 9e09f17 commit 3d5d408

File tree

7 files changed

+73
-13
lines changed

7 files changed

+73
-13
lines changed

src/packages/frontend/frame-editors/whiteboard-editor/elements/code.tsx

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,17 @@ export default function Code({ element, focused }: Props) {
1717
if (!focused) {
1818
const val =
1919
"```py\n" + (element.str?.trim() ? element.str : "Type code") + "\n```";
20-
return <Markdown value={val} style={{ width: "100%", height: "100%" }} />;
20+
return (
21+
<Markdown
22+
value={val}
23+
style={{
24+
width: "100%",
25+
height: "100%",
26+
color: element.data?.color,
27+
fontSize: element.data?.fontSize,
28+
}}
29+
/>
30+
);
2131
}
2232

2333
useEffect(() => {

src/packages/frontend/frame-editors/whiteboard-editor/elements/note.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ export const STYLE = {
1313
};
1414

1515
export default function Note({ element, focused }) {
16-
console.log(element.data?.color, avatar_fontcolor(element.data?.color));
1716
// TODO: also use white color in some cases for text.
1817
const data = {
1918
...element.data,
@@ -23,7 +22,6 @@ export default function Note({ element, focused }) {
2322
<div
2423
style={{
2524
...STYLE,
26-
fontSize: element.data?.fontSize,
2725
background: element.data?.color ?? DEFAULT_NOTE.color,
2826
}}
2927
>

src/packages/frontend/frame-editors/whiteboard-editor/elements/text.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ export default function Text({ element, focused }: Props) {
2424
value={element.str?.trim() ? element.str : "Type text"}
2525
style={{
2626
color: element.data?.color,
27+
fontSize: element.data?.fontSize,
2728
}}
2829
/>
2930
);
@@ -67,6 +68,7 @@ export default function Text({ element, focused }: Props) {
6768
file_path={path_split(frame.path).head}
6869
style={{
6970
color: element.data?.color,
71+
fontSize: element.data?.fontSize,
7072
}}
7173
value={value?.trim() ? value : "Type text"}
7274
/>
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export const DEFAULT_FONT_SIZE = 14;
2+
3+
export const minFontSize = 7;
4+
export const maxFontSize = 80;

src/packages/frontend/frame-editors/whiteboard-editor/tools/edit-bar.tsx

Lines changed: 54 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ Editing bar for editing one (or more) selected elements.
33
*/
44

55
import { useState } from "react";
6-
import { Tooltip, Button } from "antd";
6+
import { Button, InputNumber, Tooltip } from "antd";
77
import { Element } from "../types";
88
import { PANEL_STYLE } from "./panel";
99
import { Icon } from "@cocalc/frontend/components/icon";
@@ -12,6 +12,8 @@ import { Actions } from "../actions";
1212
import { BrushPreview, maxRadius } from "./pen";
1313
import ColorPicker from "@cocalc/frontend/components/color-picker";
1414

15+
import { DEFAULT_FONT_SIZE, minFontSize, maxFontSize } from "./defaults";
16+
1517
interface Props {
1618
elements: Element[];
1719
}
@@ -31,6 +33,7 @@ export default function EditBar({ elements }: Props) {
3133
}}
3234
>
3335
<div style={{ display: "flex" }}>
36+
<FontSize actions={actions} elements={elements} />
3437
<ColorButton actions={actions} elements={elements} />
3538
<DeleteButton actions={actions} elements={elements} />
3639
</div>
@@ -75,11 +78,7 @@ function ColorButton({ actions, elements }: ButtonProps) {
7578

7679
function setColor(color: string) {
7780
setColor0(color);
78-
for (const element of elements) {
79-
const data = { ...element.data, color };
80-
actions.setElement({ ...element, data }, false);
81-
}
82-
actions.syncstring_commit();
81+
setDataField({ elements, actions }, { color });
8382
}
8483

8584
return (
@@ -119,3 +118,52 @@ function getColor(elements: Element[]): string | undefined {
119118
}
120119
}
121120
}
121+
122+
function FontSize({ actions, elements }: ButtonProps) {
123+
return (
124+
<Tooltip title="Font size in pixels">
125+
<InputNumber
126+
style={{
127+
width: "64px",
128+
fontSize: "20px",
129+
color: "#666",
130+
paddingTop: "4px",
131+
}}
132+
min={minFontSize}
133+
max={maxFontSize}
134+
defaultValue={getFontSize(elements)}
135+
onChange={(fontSize) => {
136+
setDataField({ elements, actions }, { fontSize });
137+
}}
138+
/>
139+
</Tooltip>
140+
);
141+
}
142+
143+
function getFontSize(elements: Element[]): number | undefined {
144+
for (const element of elements) {
145+
if (element.data?.fontSize) {
146+
return element.data?.fontSize;
147+
}
148+
}
149+
return DEFAULT_FONT_SIZE;
150+
}
151+
152+
function setDataField(
153+
{
154+
elements,
155+
actions,
156+
}: {
157+
elements: Element[];
158+
actions: Actions;
159+
},
160+
obj: object
161+
) {
162+
for (const element of elements) {
163+
actions.setElement(
164+
{ ...element, data: { ...element.data, ...obj } },
165+
false
166+
);
167+
}
168+
actions.syncstring_commit();
169+
}

src/packages/frontend/frame-editors/whiteboard-editor/tools/note.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,8 @@ import ColorPicker from "@cocalc/frontend/components/color-picker";
1010
import { useFrameContext } from "@cocalc/frontend/frame-editors/frame-tree/frame-context";
1111
import { debounce } from "lodash";
1212
import { STYLE } from "../elements/note";
13+
import { DEFAULT_FONT_SIZE, minFontSize, maxFontSize } from "./defaults";
1314

14-
const minFontSize = 7;
15-
const maxFontSize = 64;
1615

1716
// see https://www.post-it.com/3M/en_US/post-it/ideas/color/
1817
export const COLORS = [
@@ -32,7 +31,7 @@ export const COLORS = [
3231
"#99b1f0",
3332
];
3433
const numNoteTypes = COLORS.length;
35-
export const DEFAULT_NOTE = { fontSize: 14, color: COLORS[0] };
34+
export const DEFAULT_NOTE = { fontSize: DEFAULT_FONT_SIZE, color: COLORS[0] };
3635

3736
export default function NoteToolPanel() {
3837
const frame = useFrameContext();

src/packages/frontend/frame-editors/whiteboard-editor/tools/upload.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ export default function Upload({ children, evtToDataRef }: Props) {
2626
// TOOD: this is the wrong location - should instead just let canvas save mouse location in a ref,
2727
// and don't involve Dropzone at all.
2828
const location = evtToDataRef.current?.(mouse) ?? { x: 0, y: 0 };
29-
console.log("final location = ", location);
3029
let str: string;
3130
const filename = join(dest_path, file.name);
3231
if (file.type.indexOf("image") == -1) {

0 commit comments

Comments
 (0)