gridPropertyGridComponent.tsx 2.6 KB

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