textBlockPropertyGridComponent.tsx 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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 { TextBlock, TextWrapping } from "babylonjs-gui/2D/controls/textBlock";
  6. import { Control } from "babylonjs-gui/2D/controls/control";
  7. import { LineContainerComponent } from "../../../../../sharedUiComponents/lines/lineContainerComponent";
  8. import { TextInputLineComponent } from "../../../../../sharedUiComponents/lines/textInputLineComponent";
  9. import { LockObject } from "../../../../../sharedUiComponents/tabs/propertyGrids/lockObject";
  10. import { OptionsLineComponent } from "../../../../../sharedUiComponents/lines/optionsLineComponent";
  11. import { CheckBoxLineComponent } from "../../../../../sharedUiComponents/lines/checkBoxLineComponent";
  12. import { FloatLineComponent } from "../../../../../sharedUiComponents/lines/floatLineComponent";
  13. import { GlobalState } from '../../../../globalState';
  14. interface ITextBlockPropertyGridComponentProps {
  15. globalState: GlobalState;
  16. textBlock: TextBlock;
  17. lockObject: LockObject;
  18. onPropertyChangedObservable?: Observable<PropertyChangedEvent>;
  19. }
  20. export class TextBlockPropertyGridComponent extends React.Component<ITextBlockPropertyGridComponentProps> {
  21. constructor(props: ITextBlockPropertyGridComponentProps) {
  22. super(props);
  23. }
  24. render() {
  25. const textBlock = this.props.textBlock;
  26. var horizontalOptions = [
  27. { label: "Left", value: Control.HORIZONTAL_ALIGNMENT_LEFT },
  28. { label: "Right", value: Control.HORIZONTAL_ALIGNMENT_RIGHT },
  29. { label: "Center", value: Control.HORIZONTAL_ALIGNMENT_CENTER },
  30. ];
  31. var verticalOptions = [
  32. { label: "Top", value: Control.VERTICAL_ALIGNMENT_TOP },
  33. { label: "Bottom", value: Control.VERTICAL_ALIGNMENT_BOTTOM },
  34. { label: "Center", value: Control.VERTICAL_ALIGNMENT_CENTER },
  35. ];
  36. var wrappingOptions = [
  37. { label: "Clip", value: TextWrapping.Clip },
  38. { label: "Ellipsis", value: TextWrapping.Ellipsis },
  39. { label: "Word wrap", value: TextWrapping.WordWrap },
  40. ];
  41. return (
  42. <div className="pane">
  43. <CommonControlPropertyGridComponent globalState={this.props.globalState} lockObject={this.props.lockObject} control={textBlock} onPropertyChangedObservable={this.props.onPropertyChangedObservable} />
  44. <LineContainerComponent title="TEXTBLOCK">
  45. <TextInputLineComponent lockObject={this.props.lockObject} label="Text" target={textBlock} propertyName="text" onPropertyChangedObservable={this.props.onPropertyChangedObservable} />
  46. <OptionsLineComponent label="Horizontal text alignment" options={horizontalOptions} target={textBlock} propertyName="textHorizontalAlignment" onPropertyChangedObservable={this.props.onPropertyChangedObservable} />
  47. <OptionsLineComponent label="Vertical text alignment" options={verticalOptions} target={textBlock} propertyName="textVerticalAlignment" onPropertyChangedObservable={this.props.onPropertyChangedObservable} />
  48. <CheckBoxLineComponent label="Resize to fit" target={textBlock} propertyName="resizeToFit" onPropertyChangedObservable={this.props.onPropertyChangedObservable} />
  49. <OptionsLineComponent label="Wrapping" options={wrappingOptions} target={textBlock} propertyName="textWrapping" onPropertyChangedObservable={this.props.onPropertyChangedObservable} />
  50. <TextInputLineComponent lockObject={this.props.lockObject} label="Line spacing" target={textBlock} propertyName="lineSpacing" onPropertyChangedObservable={this.props.onPropertyChangedObservable} />
  51. </LineContainerComponent>
  52. <LineContainerComponent title="OUTLINE">
  53. <FloatLineComponent lockObject={this.props.lockObject} label="Outline width" target={textBlock} propertyName="outlineWidth" onPropertyChangedObservable={this.props.onPropertyChangedObservable} />
  54. <TextInputLineComponent lockObject={this.props.lockObject} label="Outline color" target={textBlock} propertyName="outlineColor" onPropertyChangedObservable={this.props.onPropertyChangedObservable} />
  55. </LineContainerComponent>
  56. </div>
  57. );
  58. }
  59. }