-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Expand file tree
/
Copy pathNESMenuView.swift
More file actions
57 lines (52 loc) · 1.9 KB
/
NESMenuView.swift
File metadata and controls
57 lines (52 loc) · 1.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import ComposableArchitecture
import SwiftUI
import Foundation
import SharedUIComponents
import XcodeInspector
import Logger
struct NESMenuView: View {
let store: StoreOf<NESSuggestionPanelFeature>
@State private var menuController: NESMenuController
init(store: StoreOf<NESSuggestionPanelFeature>) {
self.store = store
self._menuController = State(
initialValue: NESMenuController(
fontSize: store.lineFontSize,
fontSizeScale: store.fontSizeScale,
store: store
)
)
}
var body: some View {
WithPerceptionTracking {
let lineHeight = store.lineHeight
let fontSizeScale = store.fontSizeScale
let fontSize = store.lineFontSize
if store.isPanelDisplayed && !store.isPanelOutOfFrame && store.nesContent != nil {
NESMenuButtonView(
menuController: menuController,
fontSize: fontSize
)
.id("nes-menu-button")
.frame(width: lineHeight, height: calcMenuHeight(by: lineHeight))
.padding(.horizontal, 3 * fontSizeScale)
.padding(.leading, 1 * fontSizeScale)
.padding(.vertical, 3 * fontSizeScale)
.background(
RoundedRectangle(cornerRadius: 6)
.fill(Color("LightBluePrimary"))
)
.opacity(store.menuViewOpacity)
.onChange(of: store.lineFontSize) {
menuController.fontSize = $0
}
.onChange(of: store.fontSizeScale) {
menuController.fontSizeScale = $0
}
}
}
}
private func calcMenuHeight(by lineHeight: Double) -> Double {
return (lineHeight * 2 / 3 * 100).rounded() / 100
}
}