Skip to content

Commit 0744599

Browse files
Remove gradient background (#150)
* Remove gradient background * Linter * 3D color dependent on the theme * Linter * Linter * Update Playwright Snapshots * Lazy evaluation of colors * Linter... --------- Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
1 parent 011d841 commit 0744599

16 files changed

+36
-9
lines changed

packages/jupytercad-app/style/base.css

+2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
body[data-jp-theme-light='false'] {
2+
--jp-brand-color0: #0fa8b0 !important;
23
--jp-brand-color1: #0fa8b0 !important;
34
--jp-inverse-layout-color3: #0fa8b0 !important;
45
--jp-accept-color-normal: #0fa8b0 !important;
56
--jc-brand-color: #032122 !important;
67
}
78

89
body[data-jp-theme-light='true'] {
10+
--jp-brand-color0: #09777c !important;
911
--jp-brand-color1: #09777c !important;
1012
--jp-inverse-layout-color3: #09777c !important;
1113
--jp-accept-color-normal: #09777c !important;

packages/jupytercad-extension/src/mainview.tsx

+25-9
Original file line numberDiff line numberDiff line change
@@ -31,19 +31,27 @@ import {
3131
WorkerAction
3232
} from './types';
3333
import { FloatingAnnotation } from './annotation/view';
34-
import { throttle } from './tools';
34+
import { getCSSVariableColor, throttle } from './tools';
3535
import { Vector2 } from 'three';
3636

3737
// Apply the BVH extension
3838
THREE.BufferGeometry.prototype.computeBoundsTree = computeBoundsTree;
3939
THREE.BufferGeometry.prototype.disposeBoundsTree = disposeBoundsTree;
4040
THREE.Mesh.prototype.raycast = acceleratedRaycast;
4141

42-
const DARK_BG_COLOR = 'linear-gradient(rgb(0, 0, 42), rgb(82, 87, 110))';
43-
const LIGHT_BG_COLOR = 'radial-gradient(#efeded, #8f9091)';
42+
const DEFAULT_MESH_COLOR_CSS = '--jp-inverse-layout-color4';
43+
const DEFAULT_EDGE_COLOR_CSS = '--jp-inverse-layout-color2';
44+
const SELECTED_MESH_COLOR_CSS = '--jp-brand-color0';
4445

45-
const DEFAULT_MESH_COLOR = new THREE.Color('#434442');
46-
const SELECTED_MESH_COLOR = new THREE.Color('#AB5118');
46+
const DEFAULT_MESH_COLOR = new THREE.Color(
47+
getCSSVariableColor(DEFAULT_MESH_COLOR_CSS)
48+
);
49+
const DEFAULT_EDGE_COLOR = new THREE.Color(
50+
getCSSVariableColor(DEFAULT_EDGE_COLOR_CSS)
51+
);
52+
const SELECTED_MESH_COLOR = new THREE.Color(
53+
getCSSVariableColor(SELECTED_MESH_COLOR_CSS)
54+
);
4755

4856
export type BasicMesh = THREE.Mesh<
4957
THREE.BufferGeometry,
@@ -218,6 +226,10 @@ export class MainView extends React.Component<IProps, IStates> {
218226

219227
sceneSetup = (): void => {
220228
if (this.divRef.current !== null) {
229+
DEFAULT_MESH_COLOR.set(getCSSVariableColor(DEFAULT_MESH_COLOR_CSS));
230+
DEFAULT_EDGE_COLOR.set(getCSSVariableColor(DEFAULT_EDGE_COLOR_CSS));
231+
SELECTED_MESH_COLOR.set(getCSSVariableColor(SELECTED_MESH_COLOR_CSS));
232+
221233
this._camera = new THREE.PerspectiveCamera(90, 2, 0.1, 1000);
222234
this._camera.position.set(8, 8, 8);
223235
this._camera.up.set(0, 0, 1);
@@ -626,7 +638,7 @@ export class MainView extends React.Component<IProps, IStates> {
626638

627639
const edgeMaterial = new THREE.LineBasicMaterial({
628640
linewidth: 5,
629-
color: 'black'
641+
color: DEFAULT_EDGE_COLOR
630642
});
631643
edgeList.forEach(edge => {
632644
const edgeVertices = new THREE.Float32BufferAttribute(
@@ -989,7 +1001,7 @@ export class MainView extends React.Component<IProps, IStates> {
9891001

9901002
// Draw lines
9911003
const material = new THREE.LineBasicMaterial({
992-
color: 'black',
1004+
color: DEFAULT_EDGE_COLOR,
9931005
linewidth: 2
9941006
});
9951007
const geometry = new THREE.BufferGeometry().setFromPoints([
@@ -1046,6 +1058,11 @@ export class MainView extends React.Component<IProps, IStates> {
10461058
private _handleThemeChange = (): void => {
10471059
const lightTheme =
10481060
document.body.getAttribute('data-jp-theme-light') === 'true';
1061+
1062+
DEFAULT_MESH_COLOR.set(getCSSVariableColor(DEFAULT_MESH_COLOR_CSS));
1063+
DEFAULT_EDGE_COLOR.set(getCSSVariableColor(DEFAULT_EDGE_COLOR_CSS));
1064+
SELECTED_MESH_COLOR.set(getCSSVariableColor(SELECTED_MESH_COLOR_CSS));
1065+
10491066
this.setState(old => ({ ...old, lightTheme }));
10501067
};
10511068

@@ -1132,8 +1149,7 @@ export class MainView extends React.Component<IProps, IStates> {
11321149
ref={this.divRef}
11331150
style={{
11341151
width: '100%',
1135-
height: 'calc(100%)',
1136-
background: this.state.lightTheme ? LIGHT_BG_COLOR : DARK_BG_COLOR
1152+
height: 'calc(100%)'
11371153
}}
11381154
/>
11391155
</div>

packages/jupytercad-extension/src/tools.ts

+9
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import * as d3Color from 'd3-color';
2+
13
import { LabIcon } from '@jupyterlab/ui-components';
24

35
import jvControlLight from '../style/icon/jvcontrol.svg';
@@ -196,3 +198,10 @@ export function nearest(n: number, tol: number): number {
196198
return n;
197199
}
198200
}
201+
202+
export function getCSSVariableColor(name: string): string {
203+
const color =
204+
window.getComputedStyle(document.body).getPropertyValue(name) || '#ffffff';
205+
206+
return d3Color.rgb(color).formatHex();
207+
}
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading

0 commit comments

Comments
 (0)