diff options
Diffstat (limited to 'widget')
-rw-r--r-- | widget/src/container.rs | 40 | ||||
-rw-r--r-- | widget/src/lazy/component.rs | 3 | ||||
-rw-r--r-- | widget/src/lib.rs | 2 | ||||
-rw-r--r-- | widget/src/scrollable.rs | 6 | ||||
-rw-r--r-- | widget/src/text_editor.rs | 15 | ||||
-rw-r--r-- | widget/src/text_input.rs | 62 |
6 files changed, 82 insertions, 46 deletions
diff --git a/widget/src/container.rs b/widget/src/container.rs index 82dc3141..86c1c7a8 100644 --- a/widget/src/container.rs +++ b/widget/src/container.rs @@ -26,6 +26,7 @@ use crate::core::layout; use crate::core::mouse; use crate::core::overlay; use crate::core::renderer; +use crate::core::theme; use crate::core::widget::tree::{self, Tree}; use crate::core::widget::{self, Operation}; use crate::core::{ @@ -714,9 +715,44 @@ pub fn bordered_box(theme: &Theme) -> Style { /// A [`Container`] with a dark background and white text. pub fn dark(_theme: &Theme) -> Style { + style(theme::palette::Pair { + color: color!(0x111111), + text: Color::WHITE, + }) +} + +/// A [`Container`] with a primary background color. +pub fn primary(theme: &Theme) -> Style { + let palette = theme.extended_palette(); + + style(palette.primary.base) +} + +/// A [`Container`] with a secondary background color. +pub fn secondary(theme: &Theme) -> Style { + let palette = theme.extended_palette(); + + style(palette.secondary.base) +} + +/// A [`Container`] with a success background color. +pub fn success(theme: &Theme) -> Style { + let palette = theme.extended_palette(); + + style(palette.success.base) +} + +/// A [`Container`] with a danger background color. +pub fn danger(theme: &Theme) -> Style { + let palette = theme.extended_palette(); + + style(palette.danger.base) +} + +fn style(pair: theme::palette::Pair) -> Style { Style { - background: Some(color!(0x111111).into()), - text_color: Some(Color::WHITE), + background: Some(pair.color.into()), + text_color: Some(pair.text), border: border::rounded(2), ..Style::default() } diff --git a/widget/src/lazy/component.rs b/widget/src/lazy/component.rs index 30822b7d..c215de7a 100644 --- a/widget/src/lazy/component.rs +++ b/widget/src/lazy/component.rs @@ -266,7 +266,10 @@ where state: tree::State::new(S::default()), children: vec![Tree::empty()], }))); + *self.tree.borrow_mut() = state.clone(); + self.diff_self(); + tree::State::new(state) } diff --git a/widget/src/lib.rs b/widget/src/lib.rs index b8cfa98f..31dcc205 100644 --- a/widget/src/lib.rs +++ b/widget/src/lib.rs @@ -12,7 +12,6 @@ mod action; mod column; mod mouse_area; mod pin; -mod row; mod space; mod stack; mod themer; @@ -28,6 +27,7 @@ pub mod pick_list; pub mod pop; pub mod progress_bar; pub mod radio; +pub mod row; pub mod rule; pub mod scrollable; pub mod slider; diff --git a/widget/src/scrollable.rs b/widget/src/scrollable.rs index 8adf5136..0cf75c04 100644 --- a/widget/src/scrollable.rs +++ b/widget/src/scrollable.rs @@ -729,7 +729,7 @@ where _ => mouse::Cursor::Unavailable, }; - let had_input_method = shell.input_method().is_open(); + let had_input_method = shell.input_method().is_enabled(); let translation = state.translation(self.direction, bounds, content_bounds); @@ -750,10 +750,10 @@ where ); if !had_input_method { - if let InputMethod::Open { position, .. } = + if let InputMethod::Enabled { position, .. } = shell.input_method_mut() { - *position = *position + translation; + *position = *position - translation; } } }; diff --git a/widget/src/text_editor.rs b/widget/src/text_editor.rs index e685256b..7e40a56a 100644 --- a/widget/src/text_editor.rs +++ b/widget/src/text_editor.rs @@ -339,10 +339,6 @@ where return InputMethod::Disabled; }; - let Some(preedit) = &state.preedit else { - return InputMethod::Allowed; - }; - let bounds = layout.bounds(); let internal = self.content.0.borrow_mut(); @@ -363,10 +359,10 @@ where let position = cursor + translation + Vector::new(0.0, f32::from(line_height)); - InputMethod::Open { + InputMethod::Enabled { position, purpose: input_method::Purpose::Normal, - preedit: Some(preedit.as_ref()), + preedit: state.preedit.as_ref().map(input_method::Preedit::as_ref), } } } @@ -759,8 +755,11 @@ where shell.request_redraw(); } Ime::Preedit { content, selection } => { - state.preedit = - Some(input_method::Preedit { content, selection }); + state.preedit = Some(input_method::Preedit { + content, + selection, + text_size: self.text_size, + }); shell.request_redraw(); } diff --git a/widget/src/text_input.rs b/widget/src/text_input.rs index 7be5bbd9..ae3dfe4c 100644 --- a/widget/src/text_input.rs +++ b/widget/src/text_input.rs @@ -406,10 +406,6 @@ where return InputMethod::Disabled; }; - let Some(preedit) = &state.is_ime_open else { - return InputMethod::Allowed; - }; - let secure_value = self.is_secure.then(|| value.secure()); let value = secure_value.as_ref().unwrap_or(value); @@ -433,14 +429,14 @@ where let x = (text_bounds.x + cursor_x).floor() - scroll_offset + alignment_offset; - InputMethod::Open { + InputMethod::Enabled { position: Point::new(x, text_bounds.y + text_bounds.height), purpose: if self.is_secure { input_method::Purpose::Secure } else { input_method::Purpose::Normal }, - preedit: Some(preedit.as_ref()), + preedit: state.preedit.as_ref().map(input_method::Preedit::as_ref), } } @@ -584,7 +580,7 @@ where let draw = |renderer: &mut Renderer, viewport| { let paragraph = if text.is_empty() && state - .is_ime_open + .preedit .as_ref() .map(|preedit| preedit.content.is_empty()) .unwrap_or(true) @@ -1260,7 +1256,7 @@ where input_method::Event::Opened | input_method::Event::Closed => { let state = state::<Renderer>(tree); - state.is_ime_open = + state.preedit = matches!(event, input_method::Event::Opened) .then(input_method::Preedit::new); @@ -1270,9 +1266,10 @@ where let state = state::<Renderer>(tree); if state.is_focused.is_some() { - state.is_ime_open = Some(input_method::Preedit { + state.preedit = Some(input_method::Preedit { content: content.to_owned(), selection: selection.clone(), + text_size: self.size, }); shell.request_redraw(); @@ -1322,23 +1319,30 @@ where let state = state::<Renderer>(tree); if let Some(focus) = &mut state.is_focused { - if focus.is_window_focused - && matches!( + if focus.is_window_focused { + if matches!( state.cursor.state(&self.value), cursor::State::Index(_) - ) - { - focus.now = *now; - - let millis_until_redraw = CURSOR_BLINK_INTERVAL_MILLIS - - (*now - focus.updated_at).as_millis() - % CURSOR_BLINK_INTERVAL_MILLIS; - - shell.request_redraw_at( - *now + Duration::from_millis( - millis_until_redraw as u64, - ), - ); + ) { + focus.now = *now; + + let millis_until_redraw = + CURSOR_BLINK_INTERVAL_MILLIS + - (*now - focus.updated_at).as_millis() + % CURSOR_BLINK_INTERVAL_MILLIS; + + shell.request_redraw_at( + *now + Duration::from_millis( + millis_until_redraw as u64, + ), + ); + } + + shell.request_input_method(&self.input_method( + state, + layout, + &self.value, + )); } } } @@ -1362,12 +1366,6 @@ where if let Event::Window(window::Event::RedrawRequested(_now)) = event { self.last_status = Some(status); - - shell.request_input_method(&self.input_method( - state, - layout, - &self.value, - )); } else if self .last_status .is_some_and(|last_status| status != last_status) @@ -1527,9 +1525,9 @@ pub struct State<P: text::Paragraph> { placeholder: paragraph::Plain<P>, icon: paragraph::Plain<P>, is_focused: Option<Focus>, - is_ime_open: Option<input_method::Preedit>, is_dragging: bool, is_pasting: Option<Value>, + preedit: Option<input_method::Preedit>, last_click: Option<mouse::Click>, cursor: Cursor, keyboard_modifiers: keyboard::Modifiers, @@ -1725,7 +1723,7 @@ fn replace_paragraph<Renderer>( bounds: Size::new(f32::INFINITY, text_bounds.height), size: text_size, horizontal_alignment: alignment::Horizontal::Left, - vertical_alignment: alignment::Vertical::Top, + vertical_alignment: alignment::Vertical::Center, shaping: text::Shaping::Advanced, wrapping: text::Wrapping::default(), }); |