-
-
Notifications
You must be signed in to change notification settings - Fork 25
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
Components are widgets #316
Conversation
Allows impl of Widget for &mut W where W: Widget
Note: only the gallery example is updated; most others will fail!
Also uses a slightly more compact layout for data-list examples
impl Layout for Self { | ||
fn size_rules(&mut self, mgr: SizeMgr, axis: AxisInfo) -> SizeRules { | ||
mgr.mark(self.style, axis) | ||
} | ||
|
||
fn draw(&mut self, mut draw: DrawMgr) { | ||
draw.mark(self.core.rect, self.style); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This inherits default implementations:
set_rect
just assigns toself.core.rect
(fine)find_id
returnsself.id()
ifself.core.rect
containscoord
— okay, but since this widget never handles click events (or any events), maybe it's better to returnNone
— that way, "forgetting" to use#[widget]
on a field to configure the widget is harmless
The same applies to Label
too. Not a change for this PR, but possibly a future one.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This idea only works if operations on invalid ids are changed to not panic. (The fix I just pushed is because a label was not configured and whose id is checked for disabled status when drawn, resulting in a crash due to use of an unconfigured id.)
Alternative to #315: components are widgets. This resolves ambiguities over whether something is a widget or a component. It is sometimes a little inefficient (storing a
WidgetId
for things like a label which don't need one), but this is not significant.Layout
andMark
components with real widgets (removeskas::component
module)WidgetChildren
and configured*
) from layout syntax; this is less important (since widgets may be embedded) and potentially confusing given that layout syntax also declares child widgetsExample: the stopwatch can now be declared as follows, with the buttons inlined into the layout:
Now, child widgets must appear as
#[widget]
fields in one of two cases:Inherits some other commits from #315: removing
Widget: 'static
bound; preferringdyn Widget
overW: Widget
in event-management code; some clean-up. Closes #315.The
Label
widget now allows replacing the text class.Minor change to layout of
examples/data-list*