gridPropertyGridComponent.tsx 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. import * as React from "react";
  2. import { Observable } from "babylonjs/Misc/observable";
  3. import { PropertyChangedEvent } from "../../../../propertyChangedEvent";
  4. import { CommonControlPropertyGridComponent } from "./commonControlPropertyGridComponent";
  5. import { LockObject } from "../../../../../sharedUiComponents/tabs/propertyGrids/lockObject";
  6. import { Grid } from "babylonjs-gui/2D/controls/grid";
  7. import { LineContainerComponent } from "../../../../../sharedUiComponents/lines/lineContainerComponent";
  8. import { TextLineComponent } from "../../../../../sharedUiComponents/lines/textLineComponent";
  9. import { GlobalState } from '../../../../globalState';
  10. interface IGridPropertyGridComponentProps {
  11. globalState: GlobalState;
  12. grid: Grid,
  13. lockObject: LockObject,
  14. onPropertyChangedObservable?: Observable<PropertyChangedEvent>
  15. }
  16. export class GridPropertyGridComponent extends React.Component<IGridPropertyGridComponentProps> {
  17. constructor(props: IGridPropertyGridComponentProps) {
  18. super(props);
  19. }
  20. renderRows() {
  21. const grid = this.props.grid;
  22. const rows = [];
  23. for (var index = 0; index < grid.rowCount; index++) {
  24. rows.push(grid.getRowDefinition(index)!);
  25. }
  26. return (
  27. rows.map((rd, i) => {
  28. return (
  29. <TextLineComponent key={`r${i}`} label={`Row ${i}`} value={rd.toString(grid.host, 2)} underline={i === grid.rowCount - 1} />
  30. )
  31. })
  32. );
  33. }
  34. renderColumns() {
  35. const grid = this.props.grid;
  36. const cols = [];
  37. for (var index = 0; index < grid.columnCount; index++) {
  38. cols.push(grid.getColumnDefinition(index)!);
  39. }
  40. return (
  41. cols.map((cd, i) => {
  42. return (
  43. <TextLineComponent key={`c${i}`} label={`Column ${i}`} value={cd.toString(grid.host, 2)} />
  44. )
  45. })
  46. );
  47. }
  48. render() {
  49. const grid = this.props.grid;
  50. const cols = [];
  51. for (var index = 0; index < grid.rowCount; index++) {
  52. cols.push(grid.getColumnDefinition(index));
  53. }
  54. return (
  55. <div className="pane">
  56. <CommonControlPropertyGridComponent globalState={this.props.globalState} lockObject={this.props.lockObject} control={grid} onPropertyChangedObservable={this.props.onPropertyChangedObservable} />
  57. <LineContainerComponent title="GRID">
  58. {
  59. this.renderRows()
  60. }
  61. {
  62. this.renderColumns()
  63. }
  64. </LineContainerComponent>
  65. </div>
  66. );
  67. }
  68. }