Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(PaintControls): when clicking transparent eraser palette swatch #415

Merged
merged 1 commit into from
Sep 12, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions src/components/PaintControls.vue
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ import { LABELMAP_PALETTE } from '../config';
import { usePaintToolStore } from '../store/tools/paint';
import { rgbaToHexa } from '../utils/color';

const HEXA_LENGTH = 9;

// generates both the swatches for v-color-picker and the color-to-value mapping
function convertToSwatches(
palette: typeof LABELMAP_PALETTE,
Expand Down Expand Up @@ -134,10 +136,14 @@ export default defineComponent({
});

const setBrushColor = (color: string) => {
const hexa = `${color}FF`.toUpperCase();
if (hexa in hexToValue) {
paintStore.setBrushValue(hexToValue[hexa]);
// Passthrough if #RRGGBBAA, add alpha if #RRGGBB
const withAlpha = color.length === HEXA_LENGTH ? color : `${color}FF`;
const hexa = withAlpha.toUpperCase();
const brushValue = hexToValue[hexa];
if (brushValue == null) {
throw new Error(`Brush value invalid`);
}
paintStore.setBrushValue(brushValue);
};

const brushSize = computed(() => paintStore.brushSize);
Expand Down
Loading