statics.ts 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. import { Control } from "./control";
  2. import { StackPanel } from "./stackPanel";
  3. import { TextBlock } from "./textBlock";
  4. /**
  5. * Forcing an export so that this code will execute
  6. * @hidden
  7. */
  8. const name = "Statics";
  9. export { name };
  10. /**
  11. * Creates a stack panel that can be used to render headers
  12. * @param control defines the control to associate with the header
  13. * @param text defines the text of the header
  14. * @param size defines the size of the header
  15. * @param options defines options used to configure the header
  16. * @returns a new StackPanel
  17. */
  18. Control.AddHeader = function (control: Control, text: string, size: string | number, options: { isHorizontal: boolean, controlFirst: boolean }): StackPanel {
  19. let panel = new StackPanel("panel");
  20. let isHorizontal = options ? options.isHorizontal : true;
  21. let controlFirst = options ? options.controlFirst : true;
  22. panel.isVertical = !isHorizontal;
  23. let header = new TextBlock("header");
  24. header.text = text;
  25. header.textHorizontalAlignment = Control.HORIZONTAL_ALIGNMENT_LEFT;
  26. if (isHorizontal) {
  27. header.width = size;
  28. } else {
  29. header.height = size;
  30. }
  31. if (controlFirst) {
  32. panel.addControl(control);
  33. panel.addControl(header);
  34. header.paddingLeft = "5px";
  35. } else {
  36. panel.addControl(header);
  37. panel.addControl(control);
  38. header.paddingRight = "5px";
  39. }
  40. header.shadowBlur = control.shadowBlur;
  41. header.shadowColor = control.shadowColor;
  42. header.shadowOffsetX = control.shadowOffsetX;
  43. header.shadowOffsetY = control.shadowOffsetY;
  44. return panel;
  45. }