gpui: Fix text hover & active style (#24723)
Release Notes: - N/A --- Fix this long-standing issue so that we can support Link hover colors. And renamed `text_layout` example to `text_style`. --- I spent some time studying the process of this text style change and found it a bit complicated. At first, I thought there was a problem with refine and it was not passed properly. After changing it, I found that it was not the problem. Then I found that it was because `TextRun` had already stored the `color`, `background`, `underline`, `strikethrough` in TextRun in the `request_layout` stage. They area calculate at the `request_layout` stage, but request_layout stage there was no `hitbox`, so the hover state was not obtained. ```bash cargo run -p gpui --example text_style ``` https://github.com/user-attachments/assets/24f88f73-775e-41d3-a502-75a7a39ac82b --------- Co-authored-by: Mikayla Maki <mikayla.c.maki@gmail.com>
This commit is contained in:
co-authored by
Mikayla Maki
parent
8ee6a2b454
commit
ffdf725f32
@@ -1662,7 +1662,7 @@ impl Interactivity {
|
||||
window: &mut Window,
|
||||
cx: &mut App,
|
||||
) {
|
||||
use crate::{BorderStyle, TextAlign};
|
||||
use crate::BorderStyle;
|
||||
|
||||
if global_id.is_some()
|
||||
&& (style.debug || style.debug_below || cx.has_global::<crate::DebugBelow>())
|
||||
@@ -1685,7 +1685,7 @@ impl Interactivity {
|
||||
.ok()
|
||||
.and_then(|mut text| text.pop())
|
||||
{
|
||||
text.paint(hitbox.origin, FONT_SIZE, TextAlign::Left, None, window, cx)
|
||||
text.paint(hitbox.origin, FONT_SIZE, None, None, window, cx)
|
||||
.ok();
|
||||
|
||||
let text_bounds = crate::Bounds {
|
||||
|
||||
@@ -415,7 +415,9 @@ impl TextLayout {
|
||||
|
||||
let line_height = element_state.line_height;
|
||||
let mut line_origin = bounds.origin;
|
||||
|
||||
let text_style = window.text_style();
|
||||
|
||||
for line in &element_state.lines {
|
||||
line.paint_background(
|
||||
line_origin,
|
||||
@@ -429,7 +431,7 @@ impl TextLayout {
|
||||
line.paint(
|
||||
line_origin,
|
||||
line_height,
|
||||
text_style.text_align,
|
||||
Some(&text_style),
|
||||
Some(bounds),
|
||||
window,
|
||||
cx,
|
||||
|
||||
Reference in New Issue
Block a user