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

fix: ui-background not setting the region rect and not hiding display:none #195

Merged
merged 1 commit into from
Jan 25, 2024
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
88 changes: 87 additions & 1 deletion rust/decentraland-godot-lib/src/dcl/js/js_modules/fetch.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,92 @@
// }

// declare function fetch(url: string, init?: RequestInit): Promise<Response>
class Headers {
constructor(init = {}) {
this.headers = {};

if (init instanceof Headers) {
init.forEach((value, name) => {
this.append(name, value);
});
} else if (Array.isArray(init)) {
init.forEach(([name, value]) => {
this.append(name, value);
});
} else if (init && typeof init === 'object') {
Object.keys(init).forEach(name => {
this.append(name, init[name]);
});
}
}

append(name, value) {
name = name.toLowerCase();
if (!this.headers[name]) {
this.headers[name] = [];
}
this.headers[name].push(value);
}

delete(name) {
name = name.toLowerCase();
delete this.headers[name];
}

entries() {
const result = [];
this.forEach((value, name) => {
result.push([name, value]);
});
return result;
}

forEach(callback) {
for (const name in this.headers) {
if (this.headers.hasOwnProperty(name)) {
const values = this.headers[name];
name.split(',').forEach(callback.bind(null, values, name));
}
}
}

get(name) {
name = name.toLowerCase();
return this.headers[name] ? this.headers[name][0] : null;
}

getSetCookie() {
const setCookieHeaders = this.getAll('Set-Cookie');
return setCookieHeaders.map(header => header.split(';')[0]);
}

has(name) {
name = name.toLowerCase();
return !!this.headers[name];
}

keys() {
return Object.keys(this.headers);
}

set(name, value) {
name = name.toLowerCase();
this.headers[name] = [value];
}

values() {
const result = [];
this.forEach(value => {
result.push(value);
});
return result;
}

getAll(name) {
name = name.toLowerCase();
return this.headers[name] || [];
}
}

async function restrictedFetch(url, init) {
const canUseFetch = true // TODO: this should be exposed from Deno.env
Expand Down Expand Up @@ -72,7 +157,8 @@ async function fetch(url, init) {
reqMethod, url, reqHeaders, hasBody, body ?? '', reqRedirect, reqTimeout
)
const reqId = response._internal_req_id
console.log({ reqTimeout })

response.headers = new Headers(response.headers)
// TODO: the headers object should be read-only

Object.assign(response, {
Expand Down
34 changes: 21 additions & 13 deletions rust/decentraland-godot-lib/src/godot_classes/dcl_ui_background.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,19 +181,27 @@ impl DclUiBackground {
godot::engine::nine_patch_rect::AxisStretchMode::AXIS_STRETCH_MODE_STRETCH,
);

// TODO: BackgroundTextureMode::Stretch

// let image_size = godot_texture.get_size();
// if self.current_value.uvs.len() == 8 {
// /// default=\[0,0,0,1,1,0,1,0\]: starting from bottom-left vertex clock-wise
// let uvs = self.current_value.uvs.clone().as_slice();
// let [x1, y1, x2, y2, x3, y3, x4, y4] = [uvs[0], uvs[1], uvs[2], uvs[3], uvs[4], uvs[5], uvs[6], uvs[7]];

// let mut rect = Rect2 {
// position: Vector2 { x: 0.0, y: 0.0 },
// size: Vector2 { x: 0.0, y: 0.0 },
// };
// }
if self.current_value.uvs.len() == 8 {
let uvs = self.current_value.uvs.as_slice();
let image_size = godot_texture.get_size();

// default=\[0,0,0,1,1,0,1,0\]: starting from bottom-left vertex clock-wise
let sx = uvs[0].min(uvs[4]).clamp(0.0, 1.0);
let sw = uvs[0].max(uvs[4]).clamp(0.0, 1.0);

let sy = (1.0 - uvs[3].min(uvs[1])).clamp(0.0, 1.0);
let sh = (1.0 - uvs[3].max(uvs[1])).clamp(0.0, 1.0);

let sx = sx * image_size.x;
let sw = sw * image_size.x - sx;
let sy = sy * image_size.y;
let sh = sh * image_size.y - sy;

self.base.set_region_rect(Rect2 {
position: Vector2 { x: sx, y: sy },
size: Vector2 { x: sw, y: sh },
});
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,8 @@ fn update_layout(scene: &mut Scene, ui_canvas_information: &PbUiCanvasInformatio
x: layout.size.width,
y: layout.size.height,
});
let is_hidden = taffy.style(*key_node).unwrap().display == taffy::style::Display::None;
control.set_visible(!is_hidden);
}
}

Expand Down
Loading