diff --git a/CHANGELOG.md b/CHANGELOG.md index 3722cc0faa..480b37986b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -48,6 +48,7 @@ You can find its changes [documented below](#060---2020-06-01). - `request_timer` can now be called from `LayoutCtx` ([#1278] by [@Majora320]) - TextBox supports vertical movement ([#1280] by [@cmyr]) - Widgets can specify a baseline, flex rows can align baselines ([#1295] by [@cmyr]) +- `TextBox::with_text_color` and `TextBox::set_text_color` ([#1320] by [@cmyr]) ### Changed @@ -501,6 +502,7 @@ Last release without a changelog :( [#1298]: https://github.com/linebender/druid/pull/1298 [#1299]: https://github.com/linebender/druid/pull/1299 [#1311]: https://github.com/linebender/druid/pull/1311 +[#1320]: https://github.com/linebender/druid/pull/1320 [Unreleased]: https://github.com/linebender/druid/compare/v0.6.0...master [0.6.0]: https://github.com/linebender/druid/compare/v0.5.0...v0.6.0 diff --git a/druid/src/widget/textbox.rs b/druid/src/widget/textbox.rs index 5c6a2763b7..a6410bcb95 100644 --- a/druid/src/widget/textbox.rs +++ b/druid/src/widget/textbox.rs @@ -22,8 +22,8 @@ use crate::text::{ }; use crate::widget::prelude::*; use crate::{ - theme, Affine, Cursor, FontDescriptor, HotKey, Insets, KbKey, KeyOrValue, Point, Selector, - SysMods, TimerToken, + theme, Affine, Color, Cursor, FontDescriptor, HotKey, Insets, KbKey, KeyOrValue, Point, + Selector, SysMods, TimerToken, }; const BORDER_WIDTH: f64 = 1.; @@ -106,6 +106,16 @@ impl TextBox { self } + /// Builder-style method for setting the text color. + /// + /// The argument can be either a `Color` or a [`Key`]. + /// + /// [`Key`]: ../struct.Key.html + pub fn with_text_color(mut self, color: impl Into>) -> Self { + self.set_text_color(color); + self + } + /// Set the text size. /// /// The argument can be either an `f64` or a [`Key`]. @@ -131,6 +141,19 @@ impl TextBox { self.placeholder.set_font(font); } + /// Set the text color. + /// + /// The argument can be either a `Color` or a [`Key`]. + /// + /// If you change this property, you are responsible for calling + /// [`request_layout`] to ensure the label is updated. + /// + /// [`request_layout`]: ../struct.EventCtx.html#method.request_layout + /// [`Key`]: ../struct.Key.html + pub fn set_text_color(&mut self, color: impl Into>) { + self.editor.layout_mut().set_text_color(color); + } + /// Return the [`Editor`] used by this `TextBox`. /// /// This is only needed in advanced cases, such as if you want to customize