mirror of
https://github.com/emilk/egui.git
synced 2026-08-29 04:40:03 -04:00
Add web location info to egui_web/epi (#1258)
This adds all parts of the web "location" (URL) to frame.info().web_info, included a HashMap of the query parameters, percent-decoded and ready to go. This lets you easily pass key-value pairs to your eframe web app.
This commit is contained in:
@@ -361,10 +361,62 @@ impl Frame {
|
||||
/// Information about the web environment (if applicable).
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct WebInfo {
|
||||
/// e.g. "#fragment" part of "www.example.com/index.html#fragment".
|
||||
/// Information about the URL.
|
||||
pub location: Location,
|
||||
}
|
||||
|
||||
/// Information about the URL.
|
||||
///
|
||||
/// Everything has been percent decoded (`%20` -> ` ` etc).
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct Location {
|
||||
/// The full URL (`location.href`) without the hash.
|
||||
///
|
||||
/// Example: "http://www.example.com:80/index.html?foo=bar".
|
||||
pub url: String,
|
||||
|
||||
/// `location.protocol`
|
||||
///
|
||||
/// Example: "http:".
|
||||
pub protocol: String,
|
||||
|
||||
/// `location.host`
|
||||
///
|
||||
/// Example: "example.com:80".
|
||||
pub host: String,
|
||||
|
||||
/// `location.hostname`
|
||||
///
|
||||
/// Example: "example.com".
|
||||
pub hostname: String,
|
||||
|
||||
/// `location.port`
|
||||
///
|
||||
/// Example: "80".
|
||||
pub port: String,
|
||||
|
||||
/// The "#fragment" part of "www.example.com/index.html?query#fragment".
|
||||
///
|
||||
/// Note that the leading `#` is included in the string.
|
||||
/// Also known as "hash-link" or "anchor".
|
||||
pub web_location_hash: String,
|
||||
pub hash: String,
|
||||
|
||||
/// The "query" part of "www.example.com/index.html?query#fragment".
|
||||
///
|
||||
/// Note that the leading `?` is NOT included in the string.
|
||||
///
|
||||
/// Use [`Self::web_query_map]` to get the parsed version of it.
|
||||
pub query: String,
|
||||
|
||||
/// The parsed "query" part of "www.example.com/index.html?query#fragment".
|
||||
///
|
||||
/// "foo=42&bar%20" is parsed as `{"foo": "42", "bar ": ""}`
|
||||
pub query_map: std::collections::BTreeMap<String, String>,
|
||||
|
||||
/// `location.origin`
|
||||
///
|
||||
/// Example: "http://www.example.com:80"
|
||||
pub origin: String,
|
||||
}
|
||||
|
||||
/// Information about the integration passed to the use app each frame.
|
||||
|
||||
Reference in New Issue
Block a user