UPDATE: We can now change the font size!
This commit is contained in:
committed by
Nicolás Hatcher Andrés
parent
7bc563ef29
commit
ce7318840d
@@ -127,6 +127,17 @@ fn update_style(old_value: &Style, style_path: &str, value: &str) -> Result<Styl
|
|||||||
"font.color" => {
|
"font.color" => {
|
||||||
style.font.color = color(value)?;
|
style.font.color = color(value)?;
|
||||||
}
|
}
|
||||||
|
"font.size_delta" => {
|
||||||
|
// This is a special case, we need to add the value to the current size
|
||||||
|
let size_delta: i32 = value
|
||||||
|
.parse()
|
||||||
|
.map_err(|_| format!("Invalid value for font size: '{value}'."))?;
|
||||||
|
let new_size = style.font.sz + size_delta;
|
||||||
|
if new_size < 1 {
|
||||||
|
return Err(format!("Invalid value for font size: '{new_size}'."));
|
||||||
|
}
|
||||||
|
style.font.sz = new_size;
|
||||||
|
}
|
||||||
"fill.bg_color" => {
|
"fill.bg_color" => {
|
||||||
style.fill.bg_color = color(value)?;
|
style.fill.bg_color = color(value)?;
|
||||||
style.fill.pattern_type = "solid".to_string();
|
style.fill.pattern_type = "solid".to_string();
|
||||||
|
|||||||
@@ -7,6 +7,8 @@ import type {
|
|||||||
import { styled } from "@mui/material/styles";
|
import { styled } from "@mui/material/styles";
|
||||||
import type {} from "@mui/system";
|
import type {} from "@mui/system";
|
||||||
import {
|
import {
|
||||||
|
AArrowDown,
|
||||||
|
AArrowUp,
|
||||||
AlignCenter,
|
AlignCenter,
|
||||||
AlignLeft,
|
AlignLeft,
|
||||||
AlignRight,
|
AlignRight,
|
||||||
@@ -67,6 +69,7 @@ type ToolbarProperties = {
|
|||||||
onNumberFormatPicked: (numberFmt: string) => void;
|
onNumberFormatPicked: (numberFmt: string) => void;
|
||||||
onBorderChanged: (border: BorderOptions) => void;
|
onBorderChanged: (border: BorderOptions) => void;
|
||||||
onClearFormatting: () => void;
|
onClearFormatting: () => void;
|
||||||
|
onIncreaseFontSize: (delta: number) => void;
|
||||||
fillColor: string;
|
fillColor: string;
|
||||||
fontColor: string;
|
fontColor: string;
|
||||||
bold: boolean;
|
bold: boolean;
|
||||||
@@ -248,6 +251,28 @@ function Toolbar(properties: ToolbarProperties) {
|
|||||||
>
|
>
|
||||||
<Type />
|
<Type />
|
||||||
</StyledButton>
|
</StyledButton>
|
||||||
|
<StyledButton
|
||||||
|
type="button"
|
||||||
|
$pressed={false}
|
||||||
|
disabled={!canEdit}
|
||||||
|
onClick={() => {
|
||||||
|
properties.onIncreaseFontSize(1);
|
||||||
|
}}
|
||||||
|
title={t("toolbar.increase_font_size")}
|
||||||
|
>
|
||||||
|
<AArrowUp />
|
||||||
|
</StyledButton>
|
||||||
|
<StyledButton
|
||||||
|
type="button"
|
||||||
|
$pressed={false}
|
||||||
|
disabled={!canEdit}
|
||||||
|
onClick={() => {
|
||||||
|
properties.onIncreaseFontSize(-1);
|
||||||
|
}}
|
||||||
|
title={t("toolbar.decrease_font_size")}
|
||||||
|
>
|
||||||
|
<AArrowDown />
|
||||||
|
</StyledButton>
|
||||||
<StyledButton
|
<StyledButton
|
||||||
type="button"
|
type="button"
|
||||||
$pressed={false}
|
$pressed={false}
|
||||||
|
|||||||
@@ -119,6 +119,10 @@ const Workbook = (props: { model: Model; workbookState: WorkbookState }) => {
|
|||||||
updateRangeStyle("num_fmt", numberFmt);
|
updateRangeStyle("num_fmt", numberFmt);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const onIncreaseFontSize = (delta: number) => {
|
||||||
|
updateRangeStyle("font.size_delta", `${delta}`);
|
||||||
|
};
|
||||||
|
|
||||||
const onCopyStyles = () => {
|
const onCopyStyles = () => {
|
||||||
const {
|
const {
|
||||||
sheet,
|
sheet,
|
||||||
@@ -541,6 +545,9 @@ const Workbook = (props: { model: Model; workbookState: WorkbookState }) => {
|
|||||||
);
|
);
|
||||||
setRedrawId((id) => id + 1);
|
setRedrawId((id) => id + 1);
|
||||||
}}
|
}}
|
||||||
|
onIncreaseFontSize={(delta: number) => {
|
||||||
|
onIncreaseFontSize(delta);
|
||||||
|
}}
|
||||||
onBorderChanged={(border: BorderOptions): void => {
|
onBorderChanged={(border: BorderOptions): void => {
|
||||||
const {
|
const {
|
||||||
sheet,
|
sheet,
|
||||||
|
|||||||
@@ -353,7 +353,7 @@ export default class WorksheetCanvas {
|
|||||||
? gridColor
|
? gridColor
|
||||||
: backgroundColor;
|
: backgroundColor;
|
||||||
|
|
||||||
const fontSize = 13;
|
const fontSize = style.font?.sz || 13;
|
||||||
let font = `${fontSize}px ${defaultCellFontFamily}`;
|
let font = `${fontSize}px ${defaultCellFontFamily}`;
|
||||||
let textColor = defaultTextColor;
|
let textColor = defaultTextColor;
|
||||||
if (style.font) {
|
if (style.font) {
|
||||||
|
|||||||
@@ -16,6 +16,8 @@
|
|||||||
"format_number": "Format number",
|
"format_number": "Format number",
|
||||||
"font_color": "Font color",
|
"font_color": "Font color",
|
||||||
"fill_color": "Fill color",
|
"fill_color": "Fill color",
|
||||||
|
"increase_font_size": "Increase font size",
|
||||||
|
"decrease_font_size": "Decrease font size",
|
||||||
"decimal_places_increase": "Increase decimal places",
|
"decimal_places_increase": "Increase decimal places",
|
||||||
"decimal_places_decrease": "Decrease decimal places",
|
"decimal_places_decrease": "Decrease decimal places",
|
||||||
"show_hide_grid_lines": "Show/hide grid lines",
|
"show_hide_grid_lines": "Show/hide grid lines",
|
||||||
|
|||||||
Reference in New Issue
Block a user