Skip to content

Commit 6947f54

Browse files
committed
trying to normalize the paddings...
1 parent bd6de14 commit 6947f54

15 files changed

+50
-17
lines changed

src/colors/Theme.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ export class Theme {
1414
readonly fontSize = 12;
1515
readonly nodeRowHeight = 20;
1616
readonly nodeBorderRadius = 5;
17+
readonly nodeMargin = 10;
1718

1819
readonly selectionBoxColor = "white";
1920

src/components/Button.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,11 @@ export class Button extends InteractiveLayoutElement
1818
override render(ctx: CanvasRenderingContext2D, maxWidth: number, maxHeight: number): void {
1919

2020
//background
21+
this.boxShadow(ctx, 2)
2122
this.roundedRect(ctx, 0,0, maxWidth, maxHeight, 2);
2223
ctx.fillStyle = Theme.config.btnBgColor;
2324
ctx.fill();
24-
25+
this.boxShadow(ctx, 0)
2526
//text
2627
this.writeText(ctx, this.label, this.fontSize, maxWidth/2, maxHeight, Theme.config.btnTextColor, "center");
2728

src/components/DraggableValue.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export class DraggableValue extends InteractiveLayoutElement {
1212
constructor( readonly name:string, readonly usesBar:boolean, readonly min:number, readonly max:number, protected step:number, protected onChange?:( value:number, percent:number )=>void )
1313
{
1414
super();
15-
this.xPadding=10
15+
//this.xPadding=10
1616
this.size = max-min;
1717
}
1818

@@ -61,6 +61,9 @@ export class DraggableValue extends InteractiveLayoutElement {
6161

6262
ctx.restore();
6363

64+
ctx.translate(5, 0);
65+
maxWidth-= 10;
66+
6467
this.writeText( ctx, this.name, this.fontSize, this.xPadding, this.rowHeight, Theme.config.barTextColor, "left");
6568
this.writeText( ctx, this.stringValue, this.fontSize, maxWidth-this.xPadding, this.rowHeight, Theme.config.barTextColor, "right");
6669

src/layout/Layout.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ export type LayoutConfig = {
2323
width?:number,
2424
lineHeight?:number,
2525
bgColor?:FillStyle
26+
xPadding?:number
2627
}
2728

2829
export class Layout extends LayoutElement {
@@ -42,6 +43,8 @@ export class Layout extends LayoutElement {
4243
...config
4344
};
4445

46+
this.xPadding = this.config.xPadding ?? 0;
47+
4548
if( this.config.lineHeight )
4649
{
4750
this.rowHeight = this.config.lineHeight;

src/layout/LayoutElement.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ export class LayoutElement extends CanvasElement {
99
private _fontColor? :FillStyle;
1010
private _rowHeight? :number ;
1111
private _layout?:Layout;
12+
private _xMargin?:number;
1213

1314
/**
1415
* Used to return the height of this element to the layout. If true it will return the nodeRowHeight defined in the theme, else
@@ -49,6 +50,11 @@ export class LayoutElement extends CanvasElement {
4950
set rowHeight( rowHeight:number ) { this._rowHeight = rowHeight }
5051
get rowHeight() { return this._rowHeight ?? this._parent?.rowHeight ?? Theme.config.nodeRowHeight }
5152

53+
set xMargin( newxMargin:number ) { this._xMargin = newxMargin }
54+
/**
55+
* Side space. Custom or inherited by a parent...
56+
*/
57+
get xMargin() { return this._xMargin ?? this._parent?.xMargin ?? 0 }
5258

5359
/**
5460
* Return the size...
@@ -77,12 +83,14 @@ export class LayoutElement extends CanvasElement {
7783
ctx.fillRect(0,0,maxWidth, maxHeight);
7884
}
7985

80-
if( this.xPadding )
86+
const xSpacing = this.xPadding ;
87+
88+
if( xSpacing )
8189
{
82-
ctx.translate(this.xPadding, 0)
90+
ctx.translate(xSpacing, 0)
8391
}
8492

85-
this.renderContents( ctx, maxWidth-this.xPadding*2, maxHeight );
93+
this.renderContents( ctx, maxWidth-xSpacing*2, maxHeight );
8694

8795
this.boxShadow(ctx, 0);
8896
}

src/nodes/WinNode.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { FillStyle } from "../colors/Theme";
1+
import { FillStyle, Theme } from "../colors/Theme";
22
import { HeaderElement } from "../components/Header";
33
import { Layout } from "../layout/Layout";
44
import { LayoutElement } from "../layout/LayoutElement";
@@ -21,7 +21,8 @@ export class WinNode extends Node {
2121

2222
new Layout( childs, {
2323
direction:"column",
24-
gap: 5
24+
gap: 5,
25+
xPadding: Theme.config.nodeMargin
2526
})
2627

2728
], {

src/nodes/preview/ScenePreview.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export class ScenePreviewNode extends WinNode {
1616
const ambientLightSlider = new DraggableValue("Ambient light", true, 0, 3, 0.1, value =>this.onAmbientLightSlider(value) );
1717
const rotationSpeedSlider = new DraggableValue("Rotation speed", true, 0, 2, 0.1, value =>scene.rotationSpeed=value);
1818
const objType = new ComboBox("Wrapping mode", scene.meshes.map(m=>m.name), value=>scene.currentObjectIndex=value );
19-
objType.xPadding = 10;
19+
//objType.xPadding = 10;
2020

2121
const materialSlots = [
2222
new MaterialProperty(0),

src/properties/BaseColorProperty.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export class BaseColorProperty extends Input {
2222
justify:"space-between"
2323
});
2424

25-
this.xPadding = 10;
25+
//this.xPadding = 10;
2626
}
2727

2828
override writeScript(script: Script): string {

src/properties/MaterialProperty.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export class MaterialProperty extends Input {
1010
this.layout = new Row([
1111
new TextLabel( `.material # ${index} ` ),
1212
] );
13-
this.xPadding = 10;
13+
//this.xPadding = 10;
1414
}
1515

1616
getMaterial() {
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { TextLabel } from "../components/TextLabel";
2+
import { Row } from "../layout/Layout";
3+
import { Input } from "./Input";
4+
5+
export class MaterialsToExport extends Input {
6+
constructor() {
7+
super(5);
8+
this.layout = new Row([
9+
new TextLabel("Materials used")
10+
])
11+
}
12+
}

0 commit comments

Comments
 (0)