Implemented Expander

- Updated example to show behavior
- Created styles for Expander and ExpanderRow
- Simpler implementation of `ExpanderRow`
- Deleted `ExpanderData` and replaced it with `ExpanderRow`
- Every row can now have child rows.
- Ran cargo fmt.
- Deleted settings example
- Added expander to cosmic example
- Expander icons now render

ListBox partially implemented
This commit is contained in:
Eduardo Flores 2022-10-09 11:25:46 -07:00 committed by Michael Murphy
parent a50294676d
commit 7743d0d084
22 changed files with 1222 additions and 738 deletions

View file

@ -29,9 +29,7 @@ impl<'a> FontLayoutLine<'a> {
let y = bb.min.y as i32;
outline.draw(|off_x, off_y, v| {
//TODO: ensure v * 255.0 does not overflow!
let color =
((v * 255.0) as u32) << 24 |
base & 0xFFFFFF;
let color = ((v * 255.0) as u32) << 24 | base & 0xFFFFFF;
f(x + off_x as i32, y + off_y as i32, color);
});
}
@ -42,9 +40,7 @@ impl<'a> FontLayoutLine<'a> {
let y = bb.min.y;
glyph.inner.draw(|off_x, off_y, v| {
//TODO: ensure v * 255.0 does not overflow!
let color =
((v * 255.0) as u32) << 24 |
base & 0xFFFFFF;
let color = ((v * 255.0) as u32) << 24 | base & 0xFFFFFF;
f(x + off_x as i32, y + off_y as i32, color);
});
}

View file

@ -1,4 +1,4 @@
use super::{Font, FontLineIndex, FontShapeGlyph, FontShapeWord, FontShapeLine, FontShapeSpan};
use super::{Font, FontLineIndex, FontShapeGlyph, FontShapeLine, FontShapeSpan, FontShapeWord};
pub struct FontMatches<'a> {
pub fonts: Vec<Font<'a>>,
@ -22,7 +22,7 @@ impl<'a> FontMatches<'a> {
let rtl = match buffer.direction() {
rustybuzz::Direction::RightToLeft => true,
//TODO: other directions?
_ => false,
_ => false,
};
assert_eq!(rtl, span_rtl);
@ -177,7 +177,14 @@ impl<'a> FontMatches<'a> {
FontShapeWord { blank, glyphs }
}
fn shape_span(&self, line: &str, start_span: usize, end_span: usize, line_rtl: bool, span_rtl: bool) -> FontShapeSpan {
fn shape_span(
&self,
line: &str,
start_span: usize,
end_span: usize,
line_rtl: bool,
span_rtl: bool,
) -> FontShapeSpan {
let span = &line[start_span..end_span];
log::debug!(" Span {}: '{}'", if span_rtl { "RTL" } else { "LTR" }, span);
@ -251,10 +258,6 @@ impl<'a> FontMatches<'a> {
line_rtl
};
FontShapeLine {
line_i,
rtl,
spans,
}
FontShapeLine { line_i, rtl, spans }
}
}

View file

@ -39,10 +39,7 @@ impl<'a> FontShapeGlyph<'a> {
#[cfg(feature = "rusttype")]
let inner = self.font.rusttype.glyph(self.inner)
.scaled(rusttype::Scale::uniform(font_size as f32))
.positioned(rusttype::point(
x + x_offset,
y - y_offset,
));
.positioned(rusttype::point(x + x_offset, y - y_offset));
#[cfg(feature = "swash")]
let inner = CacheKey::new(
@ -79,7 +76,13 @@ pub struct FontShapeLine<'a> {
}
impl<'a> FontShapeLine<'a> {
pub fn layout(&self, font_size: i32, line_width: i32, layout_lines: &mut Vec<FontLayoutLine<'a>>, mut layout_i: usize) {
pub fn layout(
&self,
font_size: i32,
line_width: i32,
layout_lines: &mut Vec<FontLayoutLine<'a>>,
mut layout_i: usize,
) {
let mut push_line = true;
let mut glyphs = Vec::new();
@ -128,7 +131,7 @@ impl<'a> FontShapeLine<'a> {
fit_x += word_size;
}
}
if ! word_ranges.is_empty() {
if !word_ranges.is_empty() {
while fitting_end > 0 {
if span.words[fitting_end - 1].blank {
fitting_end -= 1;
@ -174,6 +177,33 @@ impl<'a> FontShapeLine<'a> {
for (range, wrap) in word_ranges {
for word in span.words[range].iter() {
let mut word_size = 0.0;
for glyph in word.glyphs.iter() {
word_size += font_size as f32 * glyph.x_advance;
}
//TODO: make wrapping optional
let wrap = if self.rtl {
x - word_size < end_x
} else {
x + word_size > end_x
};
if wrap && !glyphs.is_empty() {
let mut glyphs_swap = Vec::new();
std::mem::swap(&mut glyphs, &mut glyphs_swap);
layout_lines.insert(
layout_i,
FontLayoutLine {
line_i: self.line_i,
glyphs: glyphs_swap,
},
);
layout_i += 1;
x = start_x;
y = 0.0;
}
for glyph in word.glyphs.iter() {
let x_advance = font_size as f32 * glyph.x_advance;
let y_advance = font_size as f32 * glyph.y_advance;
@ -185,7 +215,7 @@ impl<'a> FontShapeLine<'a> {
glyphs.push(glyph.layout(font_size, x, y));
push_line = true;
if ! self.rtl {
if !self.rtl {
x += x_advance;
}
y += y_advance;
@ -195,10 +225,13 @@ impl<'a> FontShapeLine<'a> {
if wrap {
let mut glyphs_swap = Vec::new();
std::mem::swap(&mut glyphs, &mut glyphs_swap);
layout_lines.insert(layout_i, FontLayoutLine {
line_i: self.line_i,
glyphs: glyphs_swap
});
layout_lines.insert(
layout_i,
FontLayoutLine {
line_i: self.line_i,
glyphs: glyphs_swap,
},
);
layout_i += 1;
x = start_x;
@ -208,10 +241,13 @@ impl<'a> FontShapeLine<'a> {
}
if push_line {
layout_lines.insert(layout_i, FontLayoutLine {
line_i: self.line_i,
glyphs
});
layout_lines.insert(
layout_i,
FontLayoutLine {
line_i: self.line_i,
glyphs,
},
);
}
}
}