-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(core): 💡 simplify the structure of the text editing widget
- Loading branch information
Showing
16 changed files
with
545 additions
and
620 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -182,6 +182,6 @@ mod tests { | |
} | ||
}) | ||
.with_wnd_size(WND_SIZE) | ||
.with_comparison(0.00009) | ||
.with_comparison(0.0001) | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,52 @@ | ||
use ribir_core::prelude::*; | ||
use ribir_widgets::input::{TEXT_CARET, TEXT_HIGH_LIGHT}; | ||
use ribir_widgets::input::{INPUT, TEXT_CARET, TEXT_SELECTION, TEXTAREA}; | ||
|
||
use crate::md; | ||
|
||
pub(super) fn init(classes: &mut Classes) { | ||
classes.insert(TEXT_CARET, |_w| { | ||
fn_widget! { | ||
let mut w = @ FittedBox { | ||
box_fit: BoxFit::CoverY, | ||
@ { svgs::TEXT_CARET } | ||
}; | ||
classes.insert(TEXT_CARET, |w| { | ||
rdl! { | ||
let mut w = FatObj::new(w); | ||
let blink_interval = Duration::from_millis(500); | ||
let u = interval(blink_interval, AppCtx::scheduler()) | ||
.subscribe(move |idx| $w.write().opacity = (idx % 2) as f32); | ||
|
||
.subscribe(move |idx| $w.write().opacity = (idx % 2) as f32); | ||
let border = BuildCtx::color() | ||
.map(|color| Border::only_left(BorderSide::new(2., color.into()))); | ||
@ $w { | ||
clamp: BoxClamp::fixed_width(2.), | ||
border, | ||
on_disposed: move |_| u.unsubscribe() | ||
} | ||
} | ||
.into_widget() | ||
}); | ||
|
||
classes.insert(TEXT_HIGH_LIGHT, style_class! { | ||
background: Color::from_rgb(181, 215, 254), | ||
radius: md::RADIUS_2, | ||
classes.insert(TEXT_SELECTION, style_class! { | ||
background: { | ||
let color = BuildCtx::color(); | ||
color.into_container_color(BuildCtx::get()).map(|c| c.with_alpha(0.8)) | ||
} | ||
}); | ||
|
||
fn input_border(w: Widget) -> Widget { | ||
let mut w = FatObj::new(w); | ||
let blur = Palette::of(BuildCtx::get()).on_surface_variant(); | ||
let border = match BuildCtx::color() { | ||
Variant::Stateful(v) => pipe! { | ||
let color = if $w.has_focus() { *$v } else { blur }; | ||
Border::all(BorderSide::new(1., color.into())) | ||
} | ||
.declare_into(), | ||
Variant::Value(c) => pipe! { | ||
let color = if $w.has_focus() { c } else { blur }; | ||
Border::all(BorderSide::new(1., color.into())) | ||
} | ||
.declare_into(), | ||
}; | ||
w.border(border) | ||
.radius(md::RADIUS_2) | ||
.into_widget() | ||
} | ||
classes.insert(INPUT, input_border); | ||
classes.insert(TEXTAREA, input_border); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.