Skip to content
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: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -172,4 +172,4 @@ resolver = "2"

[patch.crates-io.kas-text]
git = "https://github.com/kas-gui/kas-text.git"
rev = "f8d88435996ccacebc4893793dc47580be2251b7"
rev = "dc34ef6212dbe8ba539d50a0a3bff1bf2cbad102"
4 changes: 3 additions & 1 deletion crates/kas-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ ab_glyph = ["kas-text/ab_glyph", "dep:ab_glyph"]
shaping = ["kas-text/shaping"]

# Enable Markdown parsing
markdown = ["kas-text/markdown"]
markdown = ["pulldown-cmark"]

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

[dependencies.kas-macros]
version = "=0.17.0" # pinned because kas-macros makes assumptions about kas-core's internals
Expand All @@ -142,6 +143,7 @@ neg_cmp_op_on_partial_ord = "allow"
collapsible_if = "allow"
collapsible_else_if = "allow"
bool_comparison = "allow"
option_map_unit_fn = "allow"

[lints.rust]
unexpected_cfgs = { level = "warn", check-cfg = ['cfg(internal_doc)'] }
75 changes: 59 additions & 16 deletions crates/kas-core/src/draw/draw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ use super::{AnimationState, color::Rgba};
#[allow(unused)] use super::{DrawRounded, DrawRoundedImpl};
use super::{DrawShared, DrawSharedImpl, ImageId, PassId, PassType, SharedState, WindowCommon};
use crate::geom::{Offset, Quad, Rect, Vec2};
use crate::text::{Effect, TextDisplay};
use crate::text::{TextDisplay, format};
use crate::theme::ColorsLinear;
use std::any::Any;
use std::time::Instant;

Expand Down Expand Up @@ -127,8 +128,19 @@ impl<'a, DS: DrawSharedImpl> DrawIface<'a, DS> {
///
/// The `text` display must be prepared prior to calling this method.
/// Typically this is done using a [`crate::theme::Text`] object.
pub fn text(&mut self, pos: Vec2, bounding_box: Quad, text: &TextDisplay, col: Rgba) {
self.text_effects(pos, bounding_box, text, &[col], &[]);
pub fn text_with_color(
&mut self,
pos: Vec2,
bounding_box: Quad,
text: &TextDisplay,
theme: &ColorsLinear,
col: Rgba,
) {
let tokens = [(0, format::Colors {
color: format::Color::from_index(0).unwrap(),
..Default::default()
})];
self.text(pos, bounding_box, text, theme, &[col], &tokens);
}
}

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

/// Draw text with effects
/// Draw text with a list of color effects
///
/// Text is drawn from `pos` and clipped to `bounding_box`.
///
/// The `effects` list provides underlining/strikethrough information via
/// [`Effect::flags`] and an index [`Effect::color`].
///
/// Text colour lookup uses index `color` and is essentially:
/// `colors.get(color.unwrap_or(Rgba::BLACK)`.
/// The `text` display must be prepared prior to calling this method.
/// Typically this is done using a [`crate::theme::Text`] object.
fn text(
&mut self,
pos: Vec2,
bounding_box: Quad,
text: &TextDisplay,
theme: &ColorsLinear,
palette: &[Rgba],
tokens: &[(u32, format::Colors)],
);

/// Draw text decorations (e.g. underlines)
///
/// The `text` display must be prepared prior to calling this method.
/// Typically this is done using a [`crate::theme::Text`] object.
fn text_effects(
fn decorate_text(
&mut self,
pos: Vec2,
bounding_box: Quad,
text: &TextDisplay,
colors: &[Rgba],
effects: &[Effect],
theme: &ColorsLinear,
palette: &[Rgba],
decorations: &[(u32, format::Decoration)],
);
}

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

fn text_effects(
fn text(
&mut self,
pos: Vec2,
bb: Quad,
text: &TextDisplay,
colors: &[Rgba],
effects: &[Effect],
theme: &ColorsLinear,
palette: &[Rgba],
tokens: &[(u32, format::Colors)],
) {
self.shared
.draw
.draw_text_effects(self.draw, self.pass, pos, bb, text, colors, effects);
.draw_text(self.draw, self.pass, pos, bb, text, theme, palette, tokens);
}

fn decorate_text(
&mut self,
pos: Vec2,
bb: Quad,
text: &TextDisplay,
theme: &ColorsLinear,
palette: &[Rgba],
decorations: &[(u32, format::Decoration)],
) {
self.shared.draw.decorate_text(
self.draw,
self.pass,
pos,
bb,
text,
theme,
palette,
decorations,
);
}
}

Expand Down
37 changes: 27 additions & 10 deletions crates/kas-core/src/draw/draw_shared.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ use super::{DrawImpl, PassId};
use crate::ActionRedraw;
use crate::config::RasterConfig;
use crate::geom::{Quad, Size, Vec2};
use crate::text::{Effect, TextDisplay};
use crate::text::{TextDisplay, format};
use crate::theme::ColorsLinear;
use std::any::Any;
use std::num::NonZeroU32;
use std::sync::Arc;
Expand Down Expand Up @@ -201,21 +202,37 @@ pub trait DrawSharedImpl: Any {
/// Draw the image in the given `rect`
fn draw_image(&self, draw: &mut Self::Draw, pass: PassId, id: ImageId, rect: Quad);

/// Draw text with effects
/// Draw text with a list of color effects
///
/// The `effects` list provides underlining/strikethrough information via
/// [`Effect::flags`] and an index [`Effect::color`].
/// Text is drawn from `pos` and clipped to `bounding_box`.
///
/// Text colour lookup uses index `color` and is essentially:
/// `colors.get(color.unwrap_or(Rgba::BLACK)`.
fn draw_text_effects(
/// The `text` display must be prepared prior to calling this method.
/// Typically this is done using a [`crate::theme::Text`] object.
fn draw_text(
&mut self,
draw: &mut Self::Draw,
pass: PassId,
pos: Vec2,
bb: Quad,
bounding_box: Quad,
text: &TextDisplay,
colors: &[Rgba],
effects: &[Effect],
theme: &ColorsLinear,
palette: &[Rgba],
tokens: &[(u32, format::Colors)],
);

/// Draw text decorations (e.g. underlines)
///
/// The `text` display must be prepared prior to calling this method.
/// Typically this is done using a [`crate::theme::Text`] object.
fn decorate_text(
&mut self,
draw: &mut Self::Draw,
pass: PassId,
pos: Vec2,
bounding_box: Quad,
text: &TextDisplay,
theme: &ColorsLinear,
palette: &[Rgba],
decorations: &[(u32, format::Decoration)],
);
}
Loading