-
Notifications
You must be signed in to change notification settings - Fork 569
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
Implement disabled for druid controls #1717
Changes from 4 commits
fe93a1b
3e1874b
d6e34b2
500954e
f606199
6fd0b71
25d19c9
e3d8b92
77d4f8f
4d48edd
9b2c8ba
d5116de
6c79e1e
1fe6971
40be21f
5520e5b
232e7ee
eccd596
9754051
74b86b2
c181f51
cfc544e
05d45fc
b9b9aca
f091bf9
4766ceb
a901d1c
eb3cfd7
fdd510a
4ef9697
4745fe9
4567f8f
ba58aad
8d6b784
d3e73d1
7be336c
a52437c
2919953
aad03e0
8cc5aed
1b1b661
c1c51fe
b414907
9a38b81
2124684
6315f20
0c4f0de
3a70a0a
ba8ece0
37e47c5
cd79332
2e991cb
cddcf4e
4f452a0
cccf5e2
c542489
4a73d4b
573ed24
d15a590
45e2ee5
9925a05
7869dde
0ebb7b8
ced8b37
cec3486
dea7c3a
271a7df
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -96,6 +96,9 @@ pub struct Label<T> { | |||
pub struct RawLabel<T> { | ||||
layout: TextLayout<T>, | ||||
line_break_mode: LineBreaking, | ||||
|
||||
control_text: bool, | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would be more explicit about this; it's really only for widget implementors, so I would give it a longer, more explicit name. "is_control_component"? |
||||
default_text_color: KeyOrValue<Color>, | ||||
} | ||||
|
||||
/// Options for handling lines that are too wide for the label. | ||||
|
@@ -152,6 +155,8 @@ impl<T: TextStorage> RawLabel<T> { | |||
Self { | ||||
layout: TextLayout::new(), | ||||
line_break_mode: LineBreaking::Overflow, | ||||
control_text: false, | ||||
default_text_color: crate::theme::TEXT_COLOR.into(), | ||||
} | ||||
} | ||||
|
||||
|
@@ -175,6 +180,14 @@ impl<T: TextStorage> RawLabel<T> { | |||
self | ||||
} | ||||
|
||||
/// Builder-style method for making this label into a control-label. | ||||
/// | ||||
/// If this label is a control-label it will change its color when disabled. | ||||
pub fn control_text(mut self) -> Self { | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ditto, I'd go with something more explicit maybe? like Did you consider having labels always draw themselves dimmed when they're disabled? I could imagine there maybe being some downsides to this but they aren't totally clear to me.. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||||
self.control_text = true; | ||||
self | ||||
} | ||||
|
||||
/// Builder-style method for setting the font. | ||||
/// | ||||
/// The argument can be a [`FontDescriptor`] or a [`Key<FontDescriptor>`] | ||||
|
@@ -214,7 +227,9 @@ impl<T: TextStorage> RawLabel<T> { | |||
/// [`request_layout`]: ../struct.EventCtx.html#method.request_layout | ||||
/// [`Key<Color>`]: ../struct.Key.html | ||||
pub fn set_text_color(&mut self, color: impl Into<KeyOrValue<Color>>) { | ||||
self.layout.set_text_color(color); | ||||
let color = color.into(); | ||||
self.layout.set_text_color(color.clone()); | ||||
self.default_text_color = color; | ||||
} | ||||
|
||||
/// Set the text size. | ||||
|
@@ -230,6 +245,13 @@ impl<T: TextStorage> RawLabel<T> { | |||
self.layout.set_text_size(size); | ||||
} | ||||
|
||||
/// Choose if this label should be a control-label. | ||||
/// | ||||
/// If this label is a control-label it will change its color when disabled. | ||||
pub fn set_control_text(&mut self, is_control: bool) { | ||||
self.control_text = is_control; | ||||
} | ||||
|
||||
/// Set the font. | ||||
/// | ||||
/// The argument can be a [`FontDescriptor`] or a [`Key<FontDescriptor>`] | ||||
|
@@ -362,6 +384,13 @@ impl<T: Data> Label<T> { | |||
self.text_should_be_updated = true; | ||||
} | ||||
|
||||
/// Choose if this label should be a control-label. | ||||
/// | ||||
/// If this label is a control-label it will change its color when disabled. | ||||
pub fn set_control_text(&mut self, control: bool) { | ||||
self.label.set_control_text(control); | ||||
} | ||||
|
||||
/// Builder-style method for setting the text color. | ||||
/// | ||||
/// The argument can be either a `Color` or a [`Key<Color>`]. | ||||
|
@@ -382,6 +411,14 @@ impl<T: Data> Label<T> { | |||
self | ||||
} | ||||
|
||||
/// Builder-style method for making this label into a control-label. | ||||
/// | ||||
/// If this label is a control-label it will change its color when disabled. | ||||
pub fn control_text(mut self) -> Self { | ||||
self.label.set_control_text(true); | ||||
self | ||||
} | ||||
|
||||
/// Builder-style method for setting the font. | ||||
/// | ||||
/// The argument can be a [`FontDescriptor`] or a [`Key<FontDescriptor>`] | ||||
|
@@ -486,9 +523,9 @@ impl<T: Data> Widget<T> for Label<T> { | |||
if matches!(event, LifeCycle::WidgetAdded) { | ||||
self.text.resolve(data, env); | ||||
self.text_should_be_updated = false; | ||||
self.label | ||||
.lifecycle(ctx, event, &self.text.display_text(), env); | ||||
} | ||||
self.label | ||||
.lifecycle(ctx, event, &self.text.display_text(), env); | ||||
} | ||||
|
||||
#[instrument(name = "Label", level = "trace", skip(self, ctx, _old_data, data, env))] | ||||
|
@@ -548,14 +585,23 @@ impl<T: TextStorage> Widget<T> for RawLabel<T> { | |||
} | ||||
} | ||||
|
||||
#[instrument( | ||||
name = "RawLabel", | ||||
level = "trace", | ||||
skip(self, _ctx, event, data, _env) | ||||
)] | ||||
fn lifecycle(&mut self, _ctx: &mut LifeCycleCtx, event: &LifeCycle, data: &T, _env: &Env) { | ||||
if matches!(event, LifeCycle::WidgetAdded) { | ||||
self.layout.set_text(data.to_owned()); | ||||
#[instrument(name = "RawLabel", level = "trace", skip(self, ctx, event, data, _env))] | ||||
fn lifecycle(&mut self, ctx: &mut LifeCycleCtx, event: &LifeCycle, data: &T, _env: &Env) { | ||||
match event { | ||||
LifeCycle::WidgetAdded => { | ||||
self.layout.set_text(data.to_owned()); | ||||
} | ||||
LifeCycle::DisabledChanged(disabled) if self.control_text => { | ||||
dbg!("Control!"); | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||
let color = if *disabled { | ||||
KeyOrValue::Key(crate::theme::DISABLED_TEXT_COLOR) | ||||
} else { | ||||
self.default_text_color.clone() | ||||
}; | ||||
self.layout.set_text_color(color); | ||||
ctx.request_layout(); | ||||
} | ||||
_ => {} | ||||
} | ||||
} | ||||
|
||||
|
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.
Because this is heavily used elsewhere (including external projects) I would keep it around with a deprecation notice, like: