ui/uiscale
UI 배율. (vanilla.js 의 ui/uiscale.js, UIScale)
- 뷰의 고정된 쪽(세로형은 세로, 가로형은 가로)은 늘 같은 길이라, 작은 화면(포털의 PC iframe 등)에서는 뷰 한 단위가 화면에서 1 CSS 픽셀보다 한참 작아져 글자가 읽히지 않는다. 그때 화면 위의 UI 층만 키울 배율을 셈한다. (게임의 그림은 그대로)
- 한 단위가 minimum_css_scale CSS 픽셀보다 작으면 그만큼 키운다. (1 ~ maximum_scale)
- 낮은 화면은 키운 UI 층의 높이가 minimum_layer_height 보다 낮아지게는 키우지 않는다. (0 이면 보지 않음)
- 세로 화면(가로가 세로의 portrait_ratio 배 이하)은 상한 없이 한 단위가 minimum_css_scale CSS 픽셀이 되게 키운다.
- 원본과 다른 것:
- 한 단위의 CSS 픽셀(ViewManager::get_css_pixel_scale)을 인자로 받는다. (원본은 options.cssPixelScale 이 없으면 엔진에서 읽는다)
- options 객체는 UIScaleOptions 구조체다.
- 사용: let ui_scale = UIScale::read(view_width, view_height, view_manager.get_css_pixel_scale(), &UIScaleOptions::default());
UI scale. (vanilla.js ui/uiscale.js, UIScale)
- The fixed side of the view (height for portrait, width for landscape) always has the same length, so on a small screen (a portal's PC iframe, etc.) one view unit becomes much smaller than 1 CSS pixel on screen and text becomes unreadable. In that case it computes a scale that enlarges only the UI layer on screen. (the game's graphics stay as they are)
- If one unit is smaller than minimum_css_scale CSS pixels, it enlarges by that much. (1 ~ maximum_scale)
- On a short screen, it does not enlarge so far that the enlarged UI layer's height falls below minimum_layer_height. (0 means not checked)
- On a portrait screen (width at most portrait_ratio times the height), it enlarges without an upper limit so that one unit becomes minimum_css_scale CSS pixels.
- Differences from the original:
- It takes the CSS pixels of one unit (ViewManager::get_css_pixel_scale) as an argument. (the original reads it from the engine if options.cssPixelScale is absent)
- The options object is the UIScaleOptions struct.
- Usage: let ui_scale = UIScale::read(view_width, view_height, view_manager.get_css_pixel_scale(), &UIScaleOptions::default());
UIScaleOptionsstruct traits Clone, Copy, Debug, PartialEq, Default
UI 배율 설정. (원본 options = { minimumCssScale = 0.8, maximumScale = 1.8, minimumLayerHeight = 0, portraitRatio = 1.1 })
UI scale settings. (original options = { minimumCssScale = 0.8, maximumScale = 1.8, minimumLayerHeight = 0, portraitRatio = 1.1 })
use vanilla::{UIScale, UIScaleOptions};
let options = UIScaleOptions {
minimum_layer_height: 900.0,
..UIScaleOptions::default()
};
assert_eq!(options.maximum_scale, 1.8);
let ui_scale = UIScale::read(1920.0, 1080.0, 0.4, &options);
assert!((ui_scale - 1.2).abs() < 0.0001);한 단위가 이 CSS 픽셀보다 작으면 키운다.
Enlarges if one unit is smaller than this many CSS pixels.
반환Returnsf64
키우는 상한. (세로 화면은 받지 않는다)
Upper limit of enlargement. (portrait screens are not bound by it)
반환Returnsf64
키운 UI 층이 지키는 가장 낮은 높이. (0 이면 보지 않는다)
Lowest height the enlarged UI layer keeps. (0 means not checked)
반환Returnsf64
가로가 세로의 이 배 이하면 세로 화면.
Portrait screen if the width is at most this many times the height.
반환Returnsf64
UIScalestruct
UI 배율.
UI scale.
use vanilla::{Engine, EngineConfiguration, NodeTree, UIScale, UIScaleOptions, Vector2};
let engine = Engine::new(EngineConfiguration::new());
let mut node_tree = NodeTree::new();
let root_id = node_tree.get_root_id();
let layer_id = node_tree.create_child(root_id, "UILayer");
let view_manager = engine.get_view_manager();
let view_size = view_manager.get_view_size();
let ui_scale = UIScale::read(view_size.x, view_size.y, view_manager.get_css_pixel_scale(), &UIScaleOptions::default());
node_tree[layer_id].set_local_scale(Vector2::create(ui_scale, ui_scale));
assert!(ui_scale >= 1.0);pub fn read(view_width: f64, view_height: f64, css_pixel_scale: f64, options: &UIScaleOptions) -> f64#UI 배율 읽기. (view_width, view_height 는 UI 층이 덮는 영역, css_pixel_scale 은 뷰 한 단위의 CSS 픽셀)
Reads the UI scale. (view_width, view_height are the area the UI layer covers, css_pixel_scale is the CSS pixels of one view unit)
- view_widthf64
- UI 층이 덮는 영역의 너비. (뷰 단위)Width of the area the UI layer covers. (view units)
- view_heightf64
- UI 층이 덮는 영역의 높이. (뷰 단위)Height of the area the UI layer covers. (view units)
- css_pixel_scalef64
- 뷰 한 단위가 화면에서 차지하는 CSS 픽셀. (ViewManager::get_css_pixel_scale, 0 보다 크지 않으면 셈하지 않는다)CSS pixels one view unit takes on screen. (ViewManager::get_css_pixel_scale, not computed if not greater than 0)
- options&UIScaleOptions
- 배율 설정.Scale settings.
반환Returnsf64 UI 층에 곱할 배율. (1 이상, css_pixel_scale 이 0 보다 크지 않으면 1, 세로 화면은 maximum_scale 을 넘을 수 있다)Scale to multiply the UI layer by. (1 or more, 1 if css_pixel_scale is not greater than 0, may exceed maximum_scale on a portrait screen)
짝Counterpart: vanilla.js UIScale.read
use vanilla::{UIScale, UIScaleOptions};
let options = UIScaleOptions::default();
assert_eq!(UIScale::read(1920.0, 1080.0, 1.0, &options), 1.0);
assert!((UIScale::read(1920.0, 1080.0, 0.5, &options) - 1.6).abs() < 0.0001);
assert!((UIScale::read(1920.0, 1080.0, 0.2, &options) - 1.8).abs() < 0.0001);
assert!((UIScale::read(1080.0, 1920.0, 0.2, &options) - 4.0).abs() < 0.0001);
assert_eq!(UIScale::read(1920.0, 1080.0, 0.0, &options), 1.0);세로 화면인지. (가로가 세로의 portrait_ratio 배 이하)
Whether it is a portrait screen. (width at most portrait_ratio times the height)
- view_widthf64
- 영역의 너비. (뷰 단위)Width of the area. (view units)
- view_heightf64
- 영역의 높이. (뷰 단위)Height of the area. (view units)
- portrait_ratiof64
- 세로 화면으로 보는 가로 / 세로 비의 상한. (기본 설정은 1.1)Upper limit of the width / height ratio seen as a portrait screen. (1.1 in the default settings)
반환Returnsbool 가로가 세로의 portrait_ratio 배 이하면 true.true if the width is at most portrait_ratio times the height.
짝Counterpart: vanilla.js UIScale.isPortrait