Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DO NOT MERGE] WIP implementation of line decorations. #1494

Closed
wants to merge 3 commits into from
Closed
Changes from 1 commit
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

Add LineDisplayItem to Wrench, add reftest

  • Loading branch information
Gankra authored and gw3583 committed Jul 18, 2017
commit 1f461fdd793994a155ee513abb893d4c5edcb11a
@@ -0,0 +1,19 @@
---
root:
items:
- type: rect # short, horizontal
bounds: [ 4, 2, 5, 1 ]
color: green
- type: rect # short, vertical
bounds: [ 12, 14, 1, 5 ]
color: red
style: solid
- type: rect # long, horizontal
bounds: [ 34, 32, 200, 3 ]
color: blue
style: solid
- type: rect # long, vertical
bounds: [ 52, 54, 3, 200 ]
color: black
style: solid

@@ -0,0 +1,36 @@
---
root:
items:
- type: line # short, horizontal
baseline: 2
start: 4
end: 9
width: 1
orientation: horizontal
color: green
style: solid
- type: line # short, vertical
baseline: 12
start: 14
end: 19
width: 1
orientation: vertical
color: red
style: solid
- type: line # long, horizontal
baseline: 32
start: 34
end: 234
width: 3
orientation: horizontal
color: blue
style: solid
- type: line # long, vertical
baseline: 52
start: 54
end: 254
width: 3
orientation: vertical
color: black
style: solid

@@ -11,3 +11,4 @@
!= shadow-many.yaml shadow.yaml
!= shadow-complex.yaml shadow-many.yaml
!= non-opaque.yaml non-opaque-notref.yaml
== decorations.yaml decorations-ref.yaml
@@ -11,7 +11,7 @@ use std::io::Read;
use std::path::{Path, PathBuf};
use webrender::api::*;
use wrench::{Wrench, WrenchThing, layout_simple_ascii};
use yaml_helper::YamlHelper;
use yaml_helper::{YamlHelper, StringEnum};
use yaml_rust::{Yaml, YamlLoader};
use {WHITE_COLOR, BLACK_COLOR, PLATFORM_DEFAULT_FACE_NAME};

@@ -220,6 +220,19 @@ impl YamlFrameReader {
self.builder().push_rect(rect, Some(local_clip), color);
}

fn handle_line(&mut self, item: &Yaml, local_clip: LocalClip) {
let color = item["color"].as_colorf().unwrap_or(*BLACK_COLOR);
let baseline = item["baseline"].as_f32().expect("line must have baseline");
let start = item["start"].as_f32().expect("line must have start");
let end = item["end"].as_f32().expect("line must have end");
let width = item["width"].as_f32().expect("line must have width");
let orientation = item["orientation"].as_str().and_then(LineOrientation::from_str)
.expect("line must have orientation");
let style = item["style"].as_str().and_then(LineStyle::from_str)
.expect("line must have style");
self.builder().push_line(Some(local_clip), baseline, start, end, orientation, width, color, style);
}

fn handle_gradient(&mut self, item: &Yaml, local_clip: LocalClip) {
let bounds_key = if item["type"].is_badvalue() { "gradient" } else { "bounds" };
let bounds = item[bounds_key].as_rect().expect("gradient must have bounds");
@@ -562,6 +575,7 @@ impl YamlFrameReader {
let local_clip = self.get_local_clip_for_item(item, full_clip);
match item_type {
"rect" => self.handle_rect(item, local_clip),
"line" => self.handle_line(item, local_clip),
"image" => self.handle_image(wrench, item, local_clip),
"text" | "glyphs" => self.handle_text(wrench, item, local_clip),
"scroll-frame" => self.handle_scroll_frame(wrench, item),
@@ -510,6 +510,16 @@ impl YamlFrameWriter {
str_node(&mut v, "type", "rect");
color_node(&mut v, "color", item.color);
},
Line(item) => {
str_node(&mut v, "type", "line");
f32_node(&mut v, "baseline", item.baseline);
f32_node(&mut v, "start", item.start);
f32_node(&mut v, "end", item.end);
str_node(&mut v, "orientation", item.orientation.as_str());
f32_node(&mut v, "width", item.width);
color_node(&mut v, "color", item.color);
str_node(&mut v, "style", item.style.as_str());
}
Text(item) => {
let gi = display_list.get(base.glyphs());
let mut indices: Vec<u32> = vec![];
@@ -113,6 +113,18 @@ define_string_enum!(ScrollPolicy, [
Fixed = "fixed",
]);

define_string_enum!(LineOrientation, [
Horizontal = "horizontal",
Vertical = "vertical",
]);

define_string_enum!(LineStyle, [
Solid = "solid",
Dotted = "dotted",
Dashed = "dashed",
Wavy = "wavy",
]);

// Rotate around `axis` by `degrees` angle
fn make_rotation(origin: &LayoutPoint, degrees: f32, axis_x: f32, axis_y: f32, axis_z: f32)
-> LayoutTransform {
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.