-
Notifications
You must be signed in to change notification settings - Fork 567
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
Common context state #970
Common context state #970
Conversation
7cf7b60
to
66db763
Compare
701d4e8
to
f1d1650
Compare
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 sure cleans up quite a bit 👍 It would deserve a Maintenance
changelog entry as well but as those purely internal only changes, there is no need for it.
Also I got a few more comments.
druid/src/core.rs
Outdated
@@ -52,6 +53,14 @@ pub struct WidgetPod<T, W> { | |||
debug_widget_text: Option<PietTextLayout>, | |||
} | |||
|
|||
/// Static state that is shared between most contexts. | |||
pub(crate) struct RootState<'a> { |
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.
How about calling this ContextState
akin to WidgetState
? Because RootState
really could mean anything.
druid/src/contexts.rs
Outdated
@@ -883,6 +855,49 @@ impl<'a, 'b: 'a> PaintCtx<'a, 'b> { | |||
} | |||
} | |||
|
|||
impl<'a> RootState<'a> { |
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.
It's a bit odd to have the impl
in a different file than the struct itself. Maybe put both into contexts.rs
?
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 is fair, I think the impl really should be here so maybe I'll move RootState
/ContextState
back here as well.
druid/src/contexts.rs
Outdated
pub struct LayoutCtx<'a, 'b: 'a, 'c> { | ||
pub(crate) root_state: &'a mut RootState<'c>, |
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 might be a bit annoying to change but it would be nice if all 'b
s refer to the RootState
s lifetime.
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.
yea that would be nice but doesn't work unfortunately. :(
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.
How so? The only 'issue' I see is PainCtx
as it does not have RootState
🤔
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.
oh sorry I thought you meant that we reuse 'b
here for both inner lifetimes.
druid/src/contexts.rs
Outdated
@@ -708,15 +680,15 @@ impl<'a> UpdateCtx<'a> { | |||
} | |||
} | |||
|
|||
impl<'a, 'b> LayoutCtx<'a, 'b> { | |||
impl<'a, 'b, 'c> LayoutCtx<'a, 'b, 'c> { |
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.
Might be useful for the macro introduced by #972 :
This 'b
and RootState
s 'a
are the only required lifetimes in this file (for two functions only), all others could be elided using '_
.
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.
interesting, I'll play around with that.
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.
cool, I was able to simplify the lifetimes quite a bit, i'd forgotten they'd relaxed that rule :)
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.
I also still keep adding them and then only realize afterwards that it was completely unnecessary 😅
66db763
to
ddeeca5
Compare
f1d1650
to
6713aa7
Compare
ddeeca5
to
5d1aa86
Compare
I think it makes sense for show_context_menu to only be available in EventCtx, but for the window menu I can imagine needing it in lifecycle and update (and I need it in update in runebender)
6713aa7
to
74fa6a9
Compare
/bloat |
🗜 Bloat check ⚖️Comparing 74fa6a9 against e024f60
|
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.
Generaly looks pretty nice!
74fa6a9
to
8fc5863
Compare
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.
Just two more nits!
druid/src/core.rs
Outdated
child_state: &mut WidgetState, | ||
window_id: WindowId, | ||
window: &WindowHandle, | ||
root_state: &mut ContextState, |
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.
Missed this root_state
.
CHANGELOG.md
Outdated
@@ -51,6 +51,7 @@ This means that druid no longer requires cairo on macOS and uses Core Graphics i | |||
- `im::Vector` support for the `List` widget. ([#940] by [@xStrom]) | |||
- `LifeCycle::Size` event to inform widgets that their size changed. ([#953] by [@xStrom]) | |||
- `Button::dynamic` constructor. ([#963] by [@totsteps]) | |||
- Add `set_menu` method to `UpdateCtx` and `LifeCycleCtx` ([#970] by [@cmyr]) |
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.
Given how all the other items under the Added section are written, probably better to remove the word Add from the start here.
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.
Looks good!
Gotta be pedantic about that changelog entry tho 🙈
CHANGELOG.md
Outdated
@@ -51,6 +51,7 @@ This means that druid no longer requires cairo on macOS and uses Core Graphics i | |||
- `im::Vector` support for the `List` widget. ([#940] by [@xStrom]) | |||
- `LifeCycle::Size` event to inform widgets that their size changed. ([#953] by [@xStrom]) | |||
- `Button::dynamic` constructor. ([#963] by [@totsteps]) | |||
- Add `set_menu` method to `UpdateCtx` and `LifeCycleCtx` ([#970] by [@cmyr]) |
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.
Let's keep the style consistent.
- Add `set_menu` method to `UpdateCtx` and `LifeCycleCtx` ([#970] by [@cmyr]) | |
- `UpdateCtx::set_menu` and `LifeCycleCtx::set_menu` ([#970] by [@cmyr]) |
This adds a new type, RootState that holds onto all of the app/window-scoped state that is shared between all non-paint contexts. Simplify context lifetimes fixup
8fc5863
to
ce8a1b2
Compare
This is two related commits:
set_menu
method to the lifecycle and update contextsThis is based on #969, which should go in first.