Skip to content

Commit c9f661c

Browse files
authored
Merge pull request #669 from kas-gui/push-tqvkkynnzolm
Split text effects into Colors and Decorations
2 parents d0ad14d + af96065 commit c9f661c

File tree

23 files changed

+1086
-262
lines changed

23 files changed

+1086
-262
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,4 +172,4 @@ resolver = "2"
172172

173173
[patch.crates-io.kas-text]
174174
git = "https://github.com/kas-gui/kas-text.git"
175-
rev = "f8d88435996ccacebc4893793dc47580be2251b7"
175+
rev = "dc34ef6212dbe8ba539d50a0a3bff1bf2cbad102"

crates/kas-core/Cargo.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ ab_glyph = ["kas-text/ab_glyph", "dep:ab_glyph"]
4949
shaping = ["kas-text/shaping"]
5050

5151
# Enable Markdown parsing
52-
markdown = ["kas-text/markdown"]
52+
markdown = ["pulldown-cmark"]
5353

5454
# Enable support for YAML (de)serialisation
5555
yaml = ["serde", "dep:serde_yaml2"]
@@ -116,6 +116,7 @@ swash = { version = "0.2.4", features = ["scale"] }
116116
linearize = { version = "0.1.5", features = ["derive"] }
117117
kas-text = "0.9.0"
118118
easy-cast = "0.5.4" # used in doc links
119+
pulldown-cmark = { version = "0.13.0", optional = true }
119120

120121
[dependencies.kas-macros]
121122
version = "=0.17.0" # pinned because kas-macros makes assumptions about kas-core's internals
@@ -142,6 +143,7 @@ neg_cmp_op_on_partial_ord = "allow"
142143
collapsible_if = "allow"
143144
collapsible_else_if = "allow"
144145
bool_comparison = "allow"
146+
option_map_unit_fn = "allow"
145147

146148
[lints.rust]
147149
unexpected_cfgs = { level = "warn", check-cfg = ['cfg(internal_doc)'] }

crates/kas-core/src/draw/draw.rs

Lines changed: 59 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ use super::{AnimationState, color::Rgba};
99
#[allow(unused)] use super::{DrawRounded, DrawRoundedImpl};
1010
use super::{DrawShared, DrawSharedImpl, ImageId, PassId, PassType, SharedState, WindowCommon};
1111
use crate::geom::{Offset, Quad, Rect, Vec2};
12-
use crate::text::{Effect, TextDisplay};
12+
use crate::text::{TextDisplay, format};
13+
use crate::theme::ColorsLinear;
1314
use std::any::Any;
1415
use std::time::Instant;
1516

@@ -127,8 +128,19 @@ impl<'a, DS: DrawSharedImpl> DrawIface<'a, DS> {
127128
///
128129
/// The `text` display must be prepared prior to calling this method.
129130
/// Typically this is done using a [`crate::theme::Text`] object.
130-
pub fn text(&mut self, pos: Vec2, bounding_box: Quad, text: &TextDisplay, col: Rgba) {
131-
self.text_effects(pos, bounding_box, text, &[col], &[]);
131+
pub fn text_with_color(
132+
&mut self,
133+
pos: Vec2,
134+
bounding_box: Quad,
135+
text: &TextDisplay,
136+
theme: &ColorsLinear,
137+
col: Rgba,
138+
) {
139+
let tokens = [(0, format::Colors {
140+
color: format::Color::from_index(0).unwrap(),
141+
..Default::default()
142+
})];
143+
self.text(pos, bounding_box, text, theme, &[col], &tokens);
132144
}
133145
}
134146

@@ -223,25 +235,34 @@ pub trait Draw {
223235
/// Draw the image in the given `rect`
224236
fn image(&mut self, id: ImageId, rect: Quad);
225237

226-
/// Draw text with effects
238+
/// Draw text with a list of color effects
227239
///
228240
/// Text is drawn from `pos` and clipped to `bounding_box`.
229241
///
230-
/// The `effects` list provides underlining/strikethrough information via
231-
/// [`Effect::flags`] and an index [`Effect::color`].
232-
///
233-
/// Text colour lookup uses index `color` and is essentially:
234-
/// `colors.get(color.unwrap_or(Rgba::BLACK)`.
242+
/// The `text` display must be prepared prior to calling this method.
243+
/// Typically this is done using a [`crate::theme::Text`] object.
244+
fn text(
245+
&mut self,
246+
pos: Vec2,
247+
bounding_box: Quad,
248+
text: &TextDisplay,
249+
theme: &ColorsLinear,
250+
palette: &[Rgba],
251+
tokens: &[(u32, format::Colors)],
252+
);
253+
254+
/// Draw text decorations (e.g. underlines)
235255
///
236256
/// The `text` display must be prepared prior to calling this method.
237257
/// Typically this is done using a [`crate::theme::Text`] object.
238-
fn text_effects(
258+
fn decorate_text(
239259
&mut self,
240260
pos: Vec2,
241261
bounding_box: Quad,
242262
text: &TextDisplay,
243-
colors: &[Rgba],
244-
effects: &[Effect],
263+
theme: &ColorsLinear,
264+
palette: &[Rgba],
265+
decorations: &[(u32, format::Decoration)],
245266
);
246267
}
247268

@@ -293,17 +314,39 @@ impl<'a, DS: DrawSharedImpl> Draw for DrawIface<'a, DS> {
293314
self.shared.draw.draw_image(self.draw, self.pass, id, rect);
294315
}
295316

296-
fn text_effects(
317+
fn text(
297318
&mut self,
298319
pos: Vec2,
299320
bb: Quad,
300321
text: &TextDisplay,
301-
colors: &[Rgba],
302-
effects: &[Effect],
322+
theme: &ColorsLinear,
323+
palette: &[Rgba],
324+
tokens: &[(u32, format::Colors)],
303325
) {
304326
self.shared
305327
.draw
306-
.draw_text_effects(self.draw, self.pass, pos, bb, text, colors, effects);
328+
.draw_text(self.draw, self.pass, pos, bb, text, theme, palette, tokens);
329+
}
330+
331+
fn decorate_text(
332+
&mut self,
333+
pos: Vec2,
334+
bb: Quad,
335+
text: &TextDisplay,
336+
theme: &ColorsLinear,
337+
palette: &[Rgba],
338+
decorations: &[(u32, format::Decoration)],
339+
) {
340+
self.shared.draw.decorate_text(
341+
self.draw,
342+
self.pass,
343+
pos,
344+
bb,
345+
text,
346+
theme,
347+
palette,
348+
decorations,
349+
);
307350
}
308351
}
309352

crates/kas-core/src/draw/draw_shared.rs

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ use super::{DrawImpl, PassId};
1010
use crate::ActionRedraw;
1111
use crate::config::RasterConfig;
1212
use crate::geom::{Quad, Size, Vec2};
13-
use crate::text::{Effect, TextDisplay};
13+
use crate::text::{TextDisplay, format};
14+
use crate::theme::ColorsLinear;
1415
use std::any::Any;
1516
use std::num::NonZeroU32;
1617
use std::sync::Arc;
@@ -201,21 +202,37 @@ pub trait DrawSharedImpl: Any {
201202
/// Draw the image in the given `rect`
202203
fn draw_image(&self, draw: &mut Self::Draw, pass: PassId, id: ImageId, rect: Quad);
203204

204-
/// Draw text with effects
205+
/// Draw text with a list of color effects
205206
///
206-
/// The `effects` list provides underlining/strikethrough information via
207-
/// [`Effect::flags`] and an index [`Effect::color`].
207+
/// Text is drawn from `pos` and clipped to `bounding_box`.
208208
///
209-
/// Text colour lookup uses index `color` and is essentially:
210-
/// `colors.get(color.unwrap_or(Rgba::BLACK)`.
211-
fn draw_text_effects(
209+
/// The `text` display must be prepared prior to calling this method.
210+
/// Typically this is done using a [`crate::theme::Text`] object.
211+
fn draw_text(
212212
&mut self,
213213
draw: &mut Self::Draw,
214214
pass: PassId,
215215
pos: Vec2,
216-
bb: Quad,
216+
bounding_box: Quad,
217217
text: &TextDisplay,
218-
colors: &[Rgba],
219-
effects: &[Effect],
218+
theme: &ColorsLinear,
219+
palette: &[Rgba],
220+
tokens: &[(u32, format::Colors)],
221+
);
222+
223+
/// Draw text decorations (e.g. underlines)
224+
///
225+
/// The `text` display must be prepared prior to calling this method.
226+
/// Typically this is done using a [`crate::theme::Text`] object.
227+
fn decorate_text(
228+
&mut self,
229+
draw: &mut Self::Draw,
230+
pass: PassId,
231+
pos: Vec2,
232+
bounding_box: Quad,
233+
text: &TextDisplay,
234+
theme: &ColorsLinear,
235+
palette: &[Rgba],
236+
decorations: &[(u32, format::Decoration)],
220237
);
221238
}

0 commit comments

Comments
 (0)