horizontalspacerwithfixedaspect.c 946 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. // -----------------------------------------------------------
  2. class HorizontalSpacerWithFixedAspect: ScriptedWidgetEventHandler
  3. {
  4. protected Widget m_root;
  5. reference int border;
  6. reference int gap;
  7. reference float coef;
  8. float itemWidth;
  9. float itemHeight;
  10. // -----------------------------------------------------------
  11. void OnWidgetScriptInit(Widget w)
  12. {
  13. m_root = w;
  14. m_root.SetHandler(this);
  15. }
  16. // -----------------------------------------------------------
  17. override bool OnUpdate(Widget w)
  18. {
  19. if (w == m_root) UpdateLayout();
  20. return false;
  21. }
  22. protected void UpdateLayout()
  23. {
  24. Widget child = m_root.GetChildren();
  25. int index = 0;
  26. while (child)
  27. {
  28. if( index == 0 )
  29. {
  30. child.GetScreenSize(itemWidth, itemHeight);
  31. }
  32. else
  33. {
  34. child.SetFlags( WidgetFlags.EXACTPOS, false);
  35. child.SetPos(itemWidth+(itemWidth*coef), 0);
  36. }
  37. index++;
  38. child = child.GetSibling();
  39. }
  40. }
  41. };