Skip to content
Snippets Groups Projects
  • rhenck's avatar
    4a413b60
    Refactor element class and interface structure · 4a413b60
    rhenck authored
    The problem being solved is that compound-sub-elements must not have
    all the properties other elements have. For exampe positioning info.
    Sub-Elements are positioned inline. To avoid having similar class
    inheritance structures for positioned and inline elements, we use
    interface. Positioning is done via interface and is therefore optional.
    
    Those optional properties are kept in an object in a variable. This
    allows to hide specifics from element classes and removes the need to
    initialize all the fields in every class using the interface.
    The elements mostly care about their own specific properties anyway.
    
    The same technique is used for font and surface elements. Here we also
    don't want to initialize all the styles in every class.
    
    Changing values of element properties works like before. Just set the
    property as if it would be a direkt prop of the element. The element
    itself puts the value in the currect sub-object (positioningProps,
    fontProps etc).
    
    For reading the values there is a similar method, but it is not used
    anywhere by now. Since the properties panel operates on the raw values
    anyway (refer CombinedProperties) and for element components this would
    mean calling a function in the template, which caused change detection
    to run the function very often and is therefore bad practice.
    
    Additional notes and refactorings:
    - Restructure all files in common. UIElements in the same folder etc.
    - Move all interfaces to the UIElement file. This avoids circular
      imports, which would be needed to allow PositionedElement to extend
      UIElement.
    - Interface initializers also handle reading values in the old form.
    - Add PositionedElement for use in canvas overlays. This is a UIElement
      with guaranteed postionProps.
    - Don't export all Material packages from common, only the ones
      used in player and editor. The rest is only used in common and
      does not need to be exported.
    4a413b60
    History
    Refactor element class and interface structure
    rhenck authored
    The problem being solved is that compound-sub-elements must not have
    all the properties other elements have. For exampe positioning info.
    Sub-Elements are positioned inline. To avoid having similar class
    inheritance structures for positioned and inline elements, we use
    interface. Positioning is done via interface and is therefore optional.
    
    Those optional properties are kept in an object in a variable. This
    allows to hide specifics from element classes and removes the need to
    initialize all the fields in every class using the interface.
    The elements mostly care about their own specific properties anyway.
    
    The same technique is used for font and surface elements. Here we also
    don't want to initialize all the styles in every class.
    
    Changing values of element properties works like before. Just set the
    property as if it would be a direkt prop of the element. The element
    itself puts the value in the currect sub-object (positioningProps,
    fontProps etc).
    
    For reading the values there is a similar method, but it is not used
    anywhere by now. Since the properties panel operates on the raw values
    anyway (refer CombinedProperties) and for element components this would
    mean calling a function in the template, which caused change detection
    to run the function very often and is therefore bad practice.
    
    Additional notes and refactorings:
    - Restructure all files in common. UIElements in the same folder etc.
    - Move all interfaces to the UIElement file. This avoids circular
      imports, which would be needed to allow PositionedElement to extend
      UIElement.
    - Interface initializers also handle reading values in the old form.
    - Add PositionedElement for use in canvas overlays. This is a UIElement
      with guaranteed postionProps.
    - Don't export all Material packages from common, only the ones
      used in player and editor. The rest is only used in common and
      does not need to be exported.
Code owners
Assign users and groups as approvers for specific file changes. Learn more.