Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Widget traits #9

Closed
6 tasks done
dhardy opened this issue Nov 7, 2019 · 3 comments
Closed
6 tasks done

Widget traits #9

dhardy opened this issue Nov 7, 2019 · 3 comments

Comments

@dhardy
Copy link
Collaborator

dhardy commented Nov 7, 2019

This may see some adjustment but the basics are there:

  • Core data trait
  • Layout helper trait [could be merged into Widget, but little reason to do so]
  • Widget master trait
  • widget Classes, with class-specific properties
  • general properties (e.g. shortcut keys)

Additionally, we have a trait for windows and dialogs which may see revision (or be removed):

  • Window trait
@dhardy
Copy link
Collaborator Author

dhardy commented Nov 11, 2019

Additional widget properties (via data common to all widgets) are easily integrated into the CoreData struct. These may be exposed through trait methods on Core (requiring only a default forwarding implementation there and full implementation on CoreData), or may only be exposed on CoreData (which allows generic methods).

Properties exposed based on the class may be integrated into the Class trait.

I believe this suffices for the trait design (though obviously more methods will be required).

@dhardy dhardy added this to the Basic functionality milestone Nov 11, 2019
@dhardy dhardy closed this as completed Nov 26, 2019
@dhardy dhardy mentioned this issue Dec 3, 2019
@dhardy
Copy link
Collaborator Author

dhardy commented Dec 3, 2019

Currently we have the following widget traits:

  • Core (partially public API) for stuff all widgets share which can be auto-implemented against CoreData storage
  • Layout (internal API) for layout engine details (including stuff generated by macros)
  • LayoutData (internal API) for more layout engine details
  • Widget (public API) for remaining methods
  • Window for window-toolkit functionality
  • event::Handler (parameterised) for event handling (for user implementation)

Design ideas in #16 require a user-implemented and ideally parameterised trait for size and drawing:

trait Drawable {
    type Draw;
    fn size_rules(&self, draw: &mut Self::Draw, axis: layout::AxisInfo) -> layout::SizeRules;
    fn draw(&self, draw: &mut Self::Draw, ev_mgr: &event::Manager);
}

Additionally, a few other details (e.g. alignments) need to be user-customisable. In essence, we require:

  • an object-safe interface like Widget (or perhaps Layout if a few methods like Widget::get are moved up)
  • a parameterisable interface like event::Handler but also for size/draw methods

Plan:

  1. add a Drawable trait
  2. investigate combining Drawable and event::Handler
  3. investigate making the result the new Widget trait and moving some other functionality up to `Layout
  4. remove Window trait?
  5. add other details (extract from Class) and possibly remove Class entirely

@dhardy dhardy reopened this Dec 3, 2019
@dhardy
Copy link
Collaborator Author

dhardy commented Dec 7, 2019

The recent trait redesign has landed as follows:

  • Layout got a draw method (and will see new property methods)
  • Since this Layout is the trait implemented manually while everything in the Widget trait can be generated easily (except fn class, which is about to be removed), they have been switched:
  • LayoutWidget (as the new master trait)
  • (old) Widget + CoreWidgetCore (combined into one trait)

To avoid making Widget generic (which would massively complicate the macros and usage as well as complicate run-time theme replacement), some special object-safe traits, SizeHandle and DrawHandle, have been added (exact methods supported still in flux). These are a little unsafe but that unsafety is limited to the toolkit & theme implementation, and might be resolvable in the future (pending RFC 1598.

The result? Widget sizing and drawing now involves a few dynamic method dispatches, but also allows slightly more efficient code here. More significantly, all widget implementation details can now be made local to the widget.

@dhardy dhardy closed this as completed Dec 7, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant