Minor improvements

This commit is contained in:
Emil Ernerfeldt 2019-02-10 20:56:59 +01:00
parent 2583fd2c52
commit da6d590908
4 changed files with 45 additions and 17 deletions

View file

@ -4,7 +4,7 @@ set -eu
# Pre-requisites:
rustup target add wasm32-unknown-unknown
if ! [[ $(wasm-bindgen --version) ]]; then
cargo update -p wasm-bindgen
cargo clean
cargo install -f wasm-bindgen-cli
cargo update
fi
@ -15,17 +15,11 @@ BUILD=debug
# Clear output from old stuff:
rm -rf docs/*.wasm
function build_rust
{
echo "Build rust:"
cargo build --target wasm32-unknown-unknown
echo "Build rust:"
cargo build --target wasm32-unknown-unknown
echo "Generate JS bindings for wasm:"
FOLDER_NAME=${PWD##*/}
TARGET_NAME="example.wasm"
wasm-bindgen "target/wasm32-unknown-unknown/$BUILD/$TARGET_NAME" \
echo "Generate JS bindings for wasm:"
FOLDER_NAME=${PWD##*/}
TARGET_NAME="example.wasm"
wasm-bindgen "target/wasm32-unknown-unknown/$BUILD/$TARGET_NAME" \
--out-dir docs --no-modules --no-typescript
# --no-modules-global hoboho
}
build_rust

View file

@ -409,7 +409,7 @@ impl Region {
options: self.options,
id: self.id,
dir: self.dir,
cursor: vec2((self.available_space.x - width) / 2.0, self.cursor.y),
cursor: self.cursor + vec2((self.available_space.x - width) / 2.0, 0.0),
align,
bounding_size: vec2(0.0, 0.0),
available_space: vec2(width, self.available_space.y),
@ -560,6 +560,31 @@ impl Region {
})
}
// Helper function
pub fn floating_text(
&mut self,
pos: Vec2,
text: &str,
text_style: TextStyle,
align: (Align, Align),
text_color: Option<Color>,
) {
let font = &self.fonts()[text_style];
let (text, text_size) = font.layout_multiline(text, std::f32::INFINITY);
let x = match align.0 {
Align::Min => pos.x,
Align::Center => pos.x - 0.5 * text_size.x,
Align::Max => pos.x - text_size.x,
};
let y = match align.1 {
Align::Min => pos.y,
Align::Center => pos.y - 0.5 * text_size.y,
Align::Max => pos.y - text_size.y,
};
self.add_text(vec2(x, y), text_style, text, text_color);
}
pub fn add_text(
&mut self,
pos: Vec2,

View file

@ -134,6 +134,7 @@ impl Rect {
pub fn min(&self) -> Vec2 {
self.pos
}
pub fn max(&self) -> Vec2 {
self.pos + self.size
}
@ -141,6 +142,12 @@ impl Rect {
pub fn size(&self) -> Vec2 {
self.size
}
pub fn width(&self) -> f32 {
self.size.x
}
pub fn height(&self) -> f32 {
self.size.y
}
// Convenience functions:
pub fn left_top(&self) -> Vec2 {

View file

@ -84,8 +84,9 @@ impl App {
.rect
.min();
let mut cmds = vec![];
for i in 0..self.num_boxes {
gui.add_graphic(GuiCmd::PaintCommands(vec![PaintCmd::Rect {
cmds.push(PaintCmd::Rect {
corner_radius: self.corner_radius,
fill_color: Some(srgba(136, 136, 136, 255)),
rect: Rect::from_min_size(
@ -96,8 +97,9 @@ impl App {
width: self.stroke_width,
color: srgba(255, 255, 255, 255),
}),
}]));
});
}
gui.add_graphic(GuiCmd::PaintCommands(cmds));
});
}
}