vanilladocs
vanillapunch.com
API / ui/autolayout/layoutsymbol

ui/autolayout/layoutsymbol

솔버 안의 심볼. (원본 ui/autolayout/layoutsymbol.js 의 LayoutSymbol)

  • tableau 의 행과 열을 가리킨다. 번호는 전역으로 하나씩 늘려 붙이고, 같음과 해시는 번호로 가린다.
  • 원본과 다른 것:
  • 원본은 객체라 Map 의 키가 객체 동일성이다. 러스트 판은 번호와 종류를 담은 Copy 값이고 번호로 가린다.
  • 무효 심볼은 번호 0 하나를 같이 쓴다. (원본은 invalid() 마다 번호를 새로 붙인다. 무효 심볼은 키로 쓰이지 않아 결과는 같다)
  • 원본 setType 은 쓰는 곳이 없고 Copy 값에서는 뜻이 달라져서 옮기지 않았다.
  • LayoutSymbolMap 은 러스트 판에 더한 것이다. 원본이 행과 셀에 쓰는 Map 처럼 넣은 차례를 지킨다. (지웠다 다시 넣으면 맨 뒤로 가고, 있는 키의 값을 바꾸면 자리를 지킨다) 솔버가 셀과 행을 도는 차례가 어느 심볼을 고를지 정하므로 원본과 같은 차례로 돈다.

A symbol inside the solver. (LayoutSymbol of the original ui/autolayout/layoutsymbol.js)

  • Points to rows and columns of the tableau. Numbers are assigned globally, increasing by one, and equality and hashing go by number.
  • Differences from the original:
  • The original is an object, so Map keys use object identity. The Rust version is a Copy value holding a number and a kind, and is told apart by number.
  • Invalid symbols share the single number 0. (the original assigns a new number on every invalid(). Invalid symbols are not used as keys, so the result is the same)
  • The original setType is unused and would mean something different on a Copy value, so it was not ported.
  • LayoutSymbolMap is an addition in the Rust version. It keeps insertion order like the Maps the original uses for rows and cells. (removing and reinserting moves a key to the end, changing the value of an existing key keeps its place) The order in which the solver walks cells and rows decides which symbol is chosen, so it walks in the same order as the original.

LayoutSymbolstruct traits Clone, Copy, Debug, PartialEq, Eq, Hash

소스source

솔버 안의 심볼.

  • 솔버 안에서 쓰는 값이다. 사용자 코드는 보통 LayoutVariable 과 LayoutSolver 만 쓴다.

A symbol inside the solver.

  • A value used inside the solver. User code usually uses only LayoutVariable and LayoutSolver.
예제Example번호로 가리는 심볼Symbols told apart by number
use vanilla::ui::autolayout::layoutsymbol::LayoutSymbol;
use vanilla::ui::autolayout::layoutsymboltype::LayoutSymbolType;

let first = LayoutSymbol::new(LayoutSymbolType::External);
let second = LayoutSymbol::new(LayoutSymbolType::External);
assert_ne!(first, second);
assert_eq!(first, first.clone());
assert!(LayoutSymbol::invalid().is_invalid());
assert_eq!(LayoutSymbol::invalid().get_id(), 0);
생성자constructorpub fn new(symbol_type: LayoutSymbolType) -> LayoutSymbol#0.4.0 부터since 0.4.0소스source

생성. (새 번호를 붙인다)

Constructor. (assigns a new number)

symbol_typeLayoutSymbolType
심볼 종류.Symbol kind.

반환ReturnsLayoutSymbol 새 번호(1 부터 하나씩 늘어난다)를 붙인 심볼.A symbol with a new number (increasing by one from 1).

정적staticpub fn invalid() -> LayoutSymbol#0.4.0 부터since 0.4.0소스source

무효 심볼.

Invalid symbol.

반환ReturnsLayoutSymbol 번호 0, 종류 Invalid 인 심볼. (늘 같은 값)A symbol with number 0 and kind Invalid. (always the same value)

메서드methodpub fn get_id(&self) -> u64#0.4.0 부터since 0.4.0소스source

번호 반환.

Returns the number.

반환Returnsu64 번호. (무효 심볼은 0)Number. (0 for the invalid symbol)

메서드methodpub fn get_type(&self) -> LayoutSymbolType#0.4.0 부터since 0.4.0소스source

종류 반환.

Returns the kind.

반환ReturnsLayoutSymbolType 종류.Kind.

메서드methodpub fn is_invalid(&self) -> bool#0.4.0 부터since 0.4.0소스source

무효 심볼인지.

Whether it is the invalid symbol.

반환Returnsbool 종류가 Invalid 면 true.true if the kind is Invalid.

LayoutSymbolMapstruct traits Clone, Debug, Default

소스source

넣은 차례를 지키는 심볼 키 맵. (원본 Map<LayoutSymbol, V> 자리)

  • 칸 목록(Vec)에 넣은 차례대로 두고, 번호에서 칸 번호를 찾는 해시 맵으로 바로 찾는다.
  • 지우면 칸을 비워 두고, 빈 칸이 많아지면 차례를 지킨 채 당겨 채운다.

A symbol key map that keeps insertion order. (in place of the original Map<LayoutSymbol, V>)

  • Keeps entries in a slot list (Vec) in insertion order, and finds them directly with a hash map from number to slot index.
  • Removing leaves the slot empty, and when empty slots pile up, they are compacted while keeping the order.
예제Example넣은 차례를 지키는 맵A map that keeps insertion order
use vanilla::ui::autolayout::layoutsymbol::{LayoutSymbol, LayoutSymbolMap};
use vanilla::ui::autolayout::layoutsymboltype::LayoutSymbolType;

let first = LayoutSymbol::new(LayoutSymbolType::Slack);
let second = LayoutSymbol::new(LayoutSymbolType::Error);
let mut map = LayoutSymbolMap::new();
map.insert(first, 1.0);
map.insert(second, 2.0);
map.insert(first, 10.0);
let values: Vec<f64> = map.iter().map(|(_, value)| *value).collect();
assert_eq!(values, vec![10.0, 2.0]);

assert_eq!(map.remove(&first), Some(10.0));
map.insert(first, 3.0);
let values: Vec<f64> = map.iter().map(|(_, value)| *value).collect();
assert_eq!(values, vec![2.0, 3.0]);
assert_eq!(map.len(), 2);
assert_eq!(map.get(&LayoutSymbol::invalid()), None);
생성자constructorpub fn new() -> LayoutSymbolMap<V>#0.4.0 부터since 0.4.0소스source

생성.

Constructor.

반환ReturnsLayoutSymbolMap<V> 빈 맵.Empty map.

메서드methodpub fn len(&self) -> usize#0.4.0 부터since 0.4.0소스source

들어 있는 수.

Number of entries.

반환Returnsusize 들어 있는 키 수. (지운 칸은 세지 않는다)Number of keys held. (removed slots are not counted)

메서드methodpub fn is_empty(&self) -> bool#0.4.0 부터since 0.4.0소스source

비었는지.

Whether it is empty.

반환Returnsbool 키가 하나도 없으면 true.true if there are no keys.

메서드methodpub fn contains_key(&self, symbol: &LayoutSymbol) -> bool#0.4.0 부터since 0.4.0소스source

키가 있는지.

Whether the key exists.

symbol&LayoutSymbol
찾을 키.Key to look for.

반환Returnsbool 키가 있으면 true.true if the key exists.

메서드methodpub fn get(&self, symbol: &LayoutSymbol) -> Option<&V>#0.4.0 부터since 0.4.0소스source

값 찾기.

Finds a value.

symbol&LayoutSymbol
찾을 키.Key to look for.

반환ReturnsOption<&V> 값의 참조. 키가 없으면 None.Reference to the value. None if the key does not exist.

메서드methodpub fn get_mut(&mut self, symbol: &LayoutSymbol) -> Option<&mut V>#0.4.0 부터since 0.4.0소스source

값 찾기. (바꿀 수 있게)

Finds a value. (mutably)

symbol&LayoutSymbol
찾을 키.Key to look for.

반환ReturnsOption<&mut V> 바꿀 수 있는 값의 참조. 키가 없으면 None.Mutable reference to the value. None if the key does not exist.

메서드methodpub fn insert(&mut self, symbol: LayoutSymbol, value: V)#0.4.0 부터since 0.4.0소스source

넣기. (있는 키는 자리를 지킨 채 값만 바꾸고, 새 키는 맨 뒤에 붙인다)

Inserts. (an existing key keeps its place and only its value changes, a new key is appended at the end)

symbolLayoutSymbol
키.Key.
valueV
넣을 값.Value to set.
메서드methodpub fn remove(&mut self, symbol: &LayoutSymbol) -> Option<V>#0.4.0 부터since 0.4.0소스source

지우기. (지운 값을 돌려준다)

Removes. (returns the removed value)

symbol&LayoutSymbol
지울 키.Key to remove.

반환ReturnsOption<V> 지운 값. 키가 없으면 None.The removed value. None if the key does not exist.

메서드methodpub fn clear(&mut self)#0.4.0 부터since 0.4.0소스source

모두 지우기.

Clears all.

메서드methodpub fn iter(&self) -> impl Iterator<Item = (LayoutSymbol, &V)>#0.4.0 부터since 0.4.0소스source

넣은 차례로 돌기.

Iterates in insertion order.

반환Returnsimpl Iterator<Item = (LayoutSymbol, &V)> (키, 값의 참조) 를 넣은 차례로 내는 반복자.Iterator yielding (key, value reference) in insertion order.

메서드methodpub fn iter_mut(&mut self) -> impl Iterator<Item = (LayoutSymbol, &mut V)>#0.4.0 부터since 0.4.0소스source

넣은 차례로 돌기. (값을 바꿀 수 있게)

Iterates in insertion order. (mutably)

반환Returnsimpl Iterator<Item = (LayoutSymbol, &mut V)> (키, 바꿀 수 있는 값의 참조) 를 넣은 차례로 내는 반복자.Iterator yielding (key, mutable value reference) in insertion order.