Empeld
Empeld plugin documentation.
pluginbase.Objects.UI.Glue Namespace Reference

Classes

class  BuiGlue
 
class  BuiGlueExtensions
 
class  GlueAttribute
 
class  GlueObject
 
interface  INotifyPropertyUpdated
 

Functions

void Bind (string attrName, Func< object > val, Action< object > setVal, TimeSpan updateFreq)
 
void Bind (string attrName, Func< object > val, TimeSpan updateFreq)
 
void Bind (string attrName, Func< object > val)
 
void BindString (string attrName, string format, params Func< object >[] args)
 
void BindModel< T > (T model)
 
void Touch (string name)
 
void Update ()
 

Function Documentation

◆ Bind() [1/3]

void pluginbase.Objects.UI.Glue.Bind ( string  attrName,
Func< object >  val,
Action< object >  setVal,
TimeSpan  updateFreq 
)
80  {
81  BindInternal(attrName, val, setVal, updateFreq);
82  }

◆ Bind() [2/3]

void pluginbase.Objects.UI.Glue.Bind ( string  attrName,
Func< object >  val,
TimeSpan  updateFreq 
)
85  {
86  BindInternal(attrName, val, null, updateFreq);
87  }

◆ Bind() [3/3]

void pluginbase.Objects.UI.Glue.Bind ( string  attrName,
Func< object >  val 
)
90  {
91  Bind(attrName, val, TimeSpan.Zero);
92  }
void Bind(string attrName, Func< object > val)
Definition: BuiGlue.cs:89

◆ BindModel< T >()

void pluginbase.Objects.UI.Glue.BindModel< T > ( model)
Type Constraints
T :class 
100  : class
101  {
102  if (model == null)
103  {
104  throw new ArgumentNullException("Model");
105  }
106 
107  //Bind all properties and fields
108  foreach(var itr in typeof(T).GetAllMemberVars(x => Attribute.IsDefined(x, typeof(GlueAttribute))))
109  {
110  var field = itr;
111 
112  var attributes = field.Member.GetCustomAttributes(typeof(GlueAttribute), true).OfType<GlueAttribute>();
113  foreach(var attr in attributes)
114  {
115  var obj = BindInternal(attr.Name,
116  () => field.Getter(model),
117  attr.Writeable && field.Setter != null ? x => field.Setter(model, x) : (Action<object>)null,
118  attr.UpdateFrequency);
119  if (model is INotifyPropertyUpdated)
120  obj.NotifyModelEvent += ((INotifyPropertyUpdated)model).PropertyUpdated;
121  }
122  }
123 
124  //If a model is a INotifiedPropertyChanged, then lets hook into that to get ints of when something changes
125  if (model is INotifyPropertyChanged)
126  {
127  ((INotifyPropertyChanged)model).PropertyChanged += (sender, e) => this.Touch(e.PropertyName);
128  }
129 
130  //Hook into methods so we can invoke events
131  foreach(var method in typeof(T).GetAllMethods(x => Attribute.IsDefined(x, typeof(GlueAttribute))))
132  {
133  Action methodAction = (Action)Delegate.CreateDelegate(typeof(Action), model, method);
134 
135  var attributes = method.GetCustomAttributes(typeof(GlueAttribute), true).OfType<GlueAttribute>();
136  foreach(var attr in attributes)
137  {
138  _control.Target.AddCallback(
139  string.Format("__glue_{0}", attr.Name),
140  (name, args) => methodAction()
141  );
142  }
143  }
144  }
void Touch(string name)
Definition: BuiGlue.cs:146

◆ BindString()

void pluginbase.Objects.UI.Glue.BindString ( string  attrName,
string  format,
params Func< object > []  args 
)
95  {
96  Bind(attrName, () => string.Format(format, args.Select(x => x()).ToArray() ));
97  }
void Bind(string attrName, Func< object > val)
Definition: BuiGlue.cs:89

◆ Touch()

void pluginbase.Objects.UI.Glue.Touch ( string  name)
147  {
148  if (_control.IsAlive)
149  {
150  GlueObject glue;
151  if (_binds.TryGetValue(name, out glue))
152  {
153  RenderItem(name, glue);
154  }
155  }
156  }

◆ Update()

void pluginbase.Objects.UI.Glue.Update ( )
249  {
250  this.UpdateInternal();
251  }