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

Add TextBox::with_text_color & set_text_color #1320

Merged
merged 1 commit into from
Oct 16, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down
27 changes: 25 additions & 2 deletions druid/src/widget/textbox.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.;
Expand Down Expand Up @@ -106,6 +106,16 @@ impl<T> TextBox<T> {
self
}

/// Builder-style method for setting the text color.
///
/// The argument can be either a `Color` or a [`Key<Color>`].
///
/// [`Key<Color>`]: ../struct.Key.html
pub fn with_text_color(mut self, color: impl Into<KeyOrValue<Color>>) -> Self {
self.set_text_color(color);
self
}

/// Set the text size.
///
/// The argument can be either an `f64` or a [`Key<f64>`].
Expand All @@ -131,6 +141,19 @@ impl<T> TextBox<T> {
self.placeholder.set_font(font);
}

/// Set the text color.
///
/// The argument can be either a `Color` or a [`Key<Color>`].
///
/// 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<Color>`]: ../struct.Key.html
pub fn set_text_color(&mut self, color: impl Into<KeyOrValue<Color>>) {
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
Expand Down