feat: Add set_grid for wasm (#3)

main
bokuweb 2019-12-12 18:10:57 +09:00 committed by GitHub
parent c518d73530
commit c37c48128d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 39 additions and 2 deletions

View File

@ -5,8 +5,8 @@ use crate::xml_builder::*;
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub struct Table { pub struct Table {
pub rows: Vec<TableRow>, pub rows: Vec<TableRow>,
pub grid: Vec<usize>,
property: TableProperty, property: TableProperty,
grid: Vec<usize>,
} }
impl Table { impl Table {

View File

@ -1 +1 @@
# * *

View File

@ -321,6 +321,11 @@ export class Table {
* @returns {Table} * @returns {Table}
*/ */
add_row(row: TableRow): Table; add_row(row: TableRow): Table;
/**
* @param {Uint32Array} grid
* @returns {Table}
*/
set_grid(grid: Uint32Array): Table;
} }
/** /**
*/ */

View File

@ -160,6 +160,20 @@ export function createTable() {
return Table.__wrap(ret); return Table.__wrap(ret);
} }
let cachegetUint32Memory = null;
function getUint32Memory() {
if (cachegetUint32Memory === null || cachegetUint32Memory.buffer !== wasm.memory.buffer) {
cachegetUint32Memory = new Uint32Array(wasm.memory.buffer);
}
return cachegetUint32Memory;
}
function passArray32ToWasm(arg) {
const ptr = wasm.__wbindgen_malloc(arg.length * 4);
getUint32Memory().set(arg, ptr / 4);
WASM_VECTOR_LEN = arg.length;
return ptr;
}
/** /**
* @param {number} id * @param {number} id
* @returns {Numbering} * @returns {Numbering}
@ -912,6 +926,18 @@ export class Table {
const ret = wasm.table_add_row(ptr, ptr0); const ret = wasm.table_add_row(ptr, ptr0);
return Table.__wrap(ret); return Table.__wrap(ret);
} }
/**
* @param {Uint32Array} grid
* @returns {Table}
*/
set_grid(grid) {
if (this.ptr == 0) throw new Error('Attempt to use a moved value');
const ptr = this.ptr;
this.ptr = 0;
_assertNum(ptr);
const ret = wasm.table_set_grid(ptr, passArray32ToWasm(grid), WASM_VECTOR_LEN);
return Table.__wrap(ret);
}
} }
/** /**
*/ */

View File

@ -40,6 +40,7 @@ export function createInsert(): number;
export function __wbg_table_free(a: number): void; export function __wbg_table_free(a: number): void;
export function createTable(): number; export function createTable(): number;
export function table_add_row(a: number, b: number): number; export function table_add_row(a: number, b: number): number;
export function table_set_grid(a: number, b: number, c: number): number;
export function __wbg_numbering_free(a: number): void; export function __wbg_numbering_free(a: number): void;
export function createNumbering(a: number): number; export function createNumbering(a: number): number;
export function numbering_add_level(a: number, b: number): number; export function numbering_add_level(a: number, b: number): number;

Binary file not shown.

View File

@ -23,4 +23,9 @@ impl Table {
self.0.rows.push(row.take()); self.0.rows.push(row.take());
self self
} }
pub fn set_grid(mut self, grid: Vec<usize>) -> Table {
self.0.grid = grid;
self
}
} }