-
Notifications
You must be signed in to change notification settings - Fork 735
Framework Design Guidelines
Charlie Kindel edited this page Jun 5, 2020
·
7 revisions
@migueldeicaza is pretty clear on his preference for Action and dislike of event/EventHandler. Based on this, here is a PROPOSAL for adjusted "rules" for this project w.r.t. events.
(DRAFT - This is all incorrect!)
-
ConsoleDriver
- Init - Uses Action
- Fine - Internal API
- PepareToRun - Uses Action -
- Fine - internal API
-
protected Action TerminalResized;- Fine - Internal API
- Init - Uses Action
-
NetMainLoop -
- Uses Action for
public Action<ConsoleKeyInfo> WindowsKeyPressed;- FIX: This should not be
public!?!?
- FIX: This should not be
- Uses Action for
-
Application
-
public static Action<MouseEvent> RootMouseEvent;- Fine - Debugging API
-
public static event EventHandler<ResizedEventArgs> Loaded- great, except
ResizedEventArgsonly includes current; best practice is to include previous. Not worth fixing.
- great, except
-
public static event EventHandler<ResizedEventArgs> Resized- great, except
ResizedEventArgsonly includes current; best practice is to include previous. Not worth fixing.
- great, except
-
-
MainLoop
-
public void Invoke (Action action)- Fine; threading related. Action works great with Tasks.
-
-
View
-
void PerformActionForSubview (View subview, Action<View> action)- Fine - Internal API
public event EventHandler<FocusEventArgs> Enter;public event EventHandler<FocusEventArgs> Leave;public event EventHandler<MouseEventEventArgs> MouseEnter;public event EventHandler<MouseEventEventArgs> MouseLeave;public event EventHandler<MouseEventEventArgs> MouseClick;-
public event EventHandler<KeyEventEventArgs> KeyPress;etc...- All fine.
-
public event EventHandler<LayoutEventArgs> LayoutComplete;- Fine.
-
-
TopLevel
-
public event EventHandler Ready;- Fine.
-
-
Button
-
public Action Clicked;- FIX - Public API that should use the
event/EventHandlermodel- BREAKING CHANGE unless we can come up with a name for an
eventthat makes more sense thanClicked(Selected???).
- BREAKING CHANGE unless we can come up with a name for an
- FIX - Public API that should use the
-
-
Checkbox
-
public event EventHandler Toggled- Fine, but ideally would include previous state (either
EventHandler<bool>or via aEventArgssubclass)
- Fine, but ideally would include previous state (either
-
-
ComboBox
-
public event EventHandler<ustring> Changed;- The implementation is questionable.
- It's sending the current text; best practice is for an event to provide previous value
- Calls to
Invokeare spread around. Ideally there would bepublic virtual void OnTextChanged()method that callsChanged?.Invoke. - The name is "Changed" but the event actually represents "the selection has been confirmed". Rename it to
SelectionChanged?
- The implementation is questionable.
-
-
Menu
-
public MenuItem (ustring title, string help, Action action, Func<bool> canExecute = null)- public Action Action { get; set; }- etc...
- FIX - Public API that should use the
event/EventHandlermodel- BREAKING CHANGE
- May be possible to introduce a parallel API retaining backwards compat (an
eventnamed namedClickedorSelected).
- FIX - Public API that should use the
-
public event EventHandler OnOpenMenu;- Should event include state? E.g. Which menu?
-
public event EventHandler OnCloseMenu;- Should event include state? E.g. Which menu?
-
-
RadioGroup
-
public Action<int> SelectionChanged;- FIX - Public API that should use the
event/EventHandlermodel.- Could avoid BREAKING CHANGE by introducing a parallel
eventnamedSelectedItemChanged.
- Could avoid BREAKING CHANGE by introducing a parallel
- FIX - Public API that should use the
-
-
ScrollView
-
public event Action ChangedPosition;- FIX - Public API that should use the
event/EventHandlermodel.- Could avoid BREAKING CHANGE by introducing a parallel
eventnamedSelectedItemChanged.
- Could avoid BREAKING CHANGE by introducing a parallel
- FIX - Public API that should use the
-
-
StatusBar
-
public Action Action { get; }etc..- FIX - Public API that should use the
event/EventHandlermodel.- Could avoid BREAKING CHANGE by introducing a parallel
eventnamedClickedorSelected
- Could avoid BREAKING CHANGE by introducing a parallel
- Unrelated: Why does
RunuseApplication.MainLoop.AddIdle()and not just doInvoke?
- FIX - Public API that should use the
-
-
FileDialog
- public Action<(string, bool)> SelectedChanged { get; set; }
- FIX - Public API that should use the
event/EventHandlermodel.-
public event EventHandler<int> SelectedItemChanged?
-
- FIX - Public API that should use the
- public Action DirectoryChanged { get; set; }
- FIX - Public API that should use the
event/EventHandlermodel.-
public event EventHandler<ustring> DirectorySelected?
-
- FIX - Public API that should use the
- public Action FileChanged { get; set; }
- FIX - Public API that should use the
event/EventHandlermodel.- `public event EventHandler FileSelected?
- FIX - Public API that should use the
- public Action<(string, bool)> SelectedChanged { get; set; }
-
ListView
-
public event EventHandler<ListViewItemEventArgs> SelectedChanged;- Fine, although ideally
ListViewItemEventArgswould include the previous state. - Rename to
SelectedItemChanged?
- Fine, although ideally
-
public event EventHandler<ListViewItemEventArgs> OpenSelectedItem;- Fine, although ideally
ListViewItemEventArgswould include the previous state.
- Fine, although ideally
-
-
TextView
-
public event EventHandler TextChanged;- Inconsistently named relative to same property on
TextField - BAD DESIGN
- Every time
Texttext changes, a copy of the ENTIRE buffer will be made and passed with this event. - For classes that deal with small amounts of data, this design would be fine. But
TextViewmay hold megabytes or more. - Ideally a
EventArgssubclass would be deinfed to make it explicitly clear that theustringis the old value AND make it easier to add more state in the future. - Instead, we should make an exception to sending state with the event and not do it.
- Should this class should be redesigned to use reference values for the text buffer, vs naively just causing copy operations?
- Every time
- Inconsistently named relative to same property on
-
-
TextField
-
public event EventHandler<ustring> Changed- Inconsistently named relative to same property on
TextView - BAD DESIGN
- Every time
Texttext changes, a copy of the ENTIRE buffer will be made and passed with this event. - For classes that deal with small amounts of data, this design would be fine. But
TextViewmay hold megabytes or more. - Instead, we should make an exception to sending state with the event and not do it.
- Should this class should be redesigned to use reference values for the text buffer, vs naively just causing copy operations?
- Every time
- Inconsistently named relative to same property on
-