mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-12-06 05:53:08 -05:00
Merge main into feat/scripts-scriptui-palettes
This commit is contained in:
commit
f48c493551
443 files changed
+37499
-3099
No files matched your search
@@ -143,6 +143,9 @@ pub struct UiNode {
|
||||
pub min: f64,
|
||||
pub max: f64,
|
||||
pub items: Vec<String>,
|
||||
/// How many times the script replaced a list's items (removed or added some), which tells a
|
||||
/// list from one that holds the same texts again.
|
||||
pub items_revision: u64,
|
||||
pub selection: Option<usize>,
|
||||
/// How many times a list's items were added or removed, which a palette's waiting change of
|
||||
/// the list is checked against.
|
||||
@@ -159,6 +162,8 @@ pub struct UiNode {
|
||||
min_size: [Option<f32>; 2],
|
||||
max_size: [Option<f32>; 2],
|
||||
bounds: Option<UiRect>,
|
||||
/// The characters an edit field or static text reserves room for in its width.
|
||||
characters: Option<f32>,
|
||||
}
|
||||
|
||||
impl UiNode {
|
||||
@@ -205,7 +210,7 @@ impl ScriptUiDialog {
|
||||
/// whose text is `control`.
|
||||
pub fn find(&self, control: &str) -> Option<usize> {
|
||||
let by = |name: bool| {
|
||||
let hit = |n: &UiNode| if name { n.name == control } else { n.name.is_empty() && n.text == control };
|
||||
let hit = |n: &UiNode| if name { !control.is_empty() && n.name == control } else { n.name.is_empty() && n.text == control };
|
||||
self.nodes.iter().enumerate().skip(1).find(|(_, n)| hit(n)).map(|(i, _)| i)
|
||||
};
|
||||
by(true).or_else(|| by(false))
|
||||
@@ -522,6 +527,7 @@ pub fn parse(d: &Data) -> Result<ScriptUiDialog, HostError> {
|
||||
min,
|
||||
max,
|
||||
items,
|
||||
items_revision: number(field(f, "itemsRevision")).map_or(0, |n| n as u64),
|
||||
selection,
|
||||
revision: number(field(f, "revision")).unwrap_or(0.0),
|
||||
multiline: flag("multiline"),
|
||||
@@ -536,6 +542,8 @@ pub fn parse(d: &Data) -> Result<ScriptUiDialog, HostError> {
|
||||
min_size,
|
||||
max_size,
|
||||
bounds,
|
||||
// At most as many characters as the longest text holds.
|
||||
characters: number(field(f, "characters")).filter(|c| *c > 0.0).map(|c| (c as f32).min(MAX_TEXT_BYTES as f32)),
|
||||
});
|
||||
}
|
||||
let target = |name: &str| number(field(top, name)).map(|k| k as usize).filter(|k| nodes.get(*k).is_some_and(|n| n.kind == UiKind::Button));
|
||||
@@ -551,12 +559,16 @@ fn own_size(n: &UiNode) -> [f32; 2] {
|
||||
let widest = |lines: &mut dyn Iterator<Item = &str>| lines.map(chars).fold(0.0, f32::max);
|
||||
let lines = |s: &str| s.lines().count().max(1) as f32;
|
||||
let longest_item = n.items.iter().map(|t| chars(t)).fold(0.0, f32::max);
|
||||
// `characters` reserves room for that many characters, however long the text is now.
|
||||
let reserved = n.characters.unwrap_or(0.0);
|
||||
match n.kind {
|
||||
UiKind::StaticText => [widest(&mut n.text.lines()) * CHAR + 4.0, lines(&n.text) * LINE + 4.0],
|
||||
UiKind::StaticText => [widest(&mut n.text.lines()).max(reserved) * CHAR + 4.0, lines(&n.text) * LINE + 4.0],
|
||||
UiKind::Button => [(chars(&n.text) * CHAR + 24.0).max(80.0), 24.0],
|
||||
UiKind::CheckBox | UiKind::RadioButton => [chars(&n.text) * CHAR + 24.0, 20.0],
|
||||
UiKind::EditText if n.multiline => [(widest(&mut n.text.lines()) * CHAR + 12.0).max(160.0), lines(&n.text).max(3.0) * LINE + 10.0],
|
||||
UiKind::EditText => [(chars(&n.text) * CHAR + 12.0).max(80.0), 24.0],
|
||||
UiKind::EditText if n.multiline => {
|
||||
[(widest(&mut n.text.lines()).max(reserved) * CHAR + 12.0).max(160.0), lines(&n.text).max(3.0) * LINE + 10.0]
|
||||
}
|
||||
UiKind::EditText => [(chars(&n.text).max(reserved) * CHAR + 12.0).max(80.0), 24.0],
|
||||
UiKind::DropDownList => [(longest_item * CHAR + 40.0).max(100.0), 24.0],
|
||||
UiKind::ListBox => [(longest_item * CHAR + 24.0).max(120.0), (n.items.len() as f32).clamp(3.0, 10.0) * 18.0 + 6.0],
|
||||
UiKind::Slider => [160.0, 20.0],
|
||||
|
||||
Reference in new issue
Block a user