Skip to content

Commit

Permalink
EntryView
Browse files Browse the repository at this point in the history
  • Loading branch information
eagleoflqj committed Dec 14, 2024
1 parent 58a176a commit 6173b09
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 3 deletions.
2 changes: 1 addition & 1 deletion cache/README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
This directory caches tarball of build dependencies
(downloaded from [prebuilder](https://github.com/fcitx-contrib/fcitx5-ios-prebuilder/releases)),
(downloaded from [prebuilder](https://github.com/fcitx-contrib/fcitx5-prebuilder/releases/ios)),
which will be extracted to `build/sysroot/usr`.
2 changes: 1 addition & 1 deletion src/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ void setConfig(const char *uri_, const char *value) {
if (subPath.empty()) {
addon->setConfig(config);
} else {
addon->setSubConfig(subPath, fcitx::RawConfig());
addon->setSubConfig(subPath, config);
}
} else {
FCITX_ERROR() << "Failed to get addon";
Expand Down
35 changes: 35 additions & 0 deletions src/config/EntryView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import SwiftUI

struct EntryView: OptionViewProtocol {
let label: String
let data: [String: Any]
@Binding var value: Any

private func getChild(_ children: [[String: Any]], _ i: Int) -> [String: Any] {
var child = children[i]
child["Value"] = (value as! [String: Any])[child["Option"] as! String]
return child
}

var body: some View {
let children = data["Children"] as! [[String: Any]]
VStack {
ForEach(children.indices, id: \.self) { i in
let child = getChild(children, i)
let optionViewType = toOptionViewType(child)
AnyView(
optionViewType.init(
label: child["Description"] as! String,
data: child,
value: Binding<Any>(
get: { child["Value"] },
set: {
var v = value as! [String: Any]
v[child["Option"] as! String] = $0
value = v
}
)))
}
}
}
}
2 changes: 1 addition & 1 deletion src/config/ListView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ struct ListSubView: OptionViewProtocol {
ForEach(list.indices, id: \.self) { i in
AnyView(
optionViewType.init(
label: "", data: [:],
label: "", data: data, // List|Entries need this.
value: Binding<Any>(
get: { list[i] },
set: {
Expand Down
3 changes: 3 additions & 0 deletions src/config/option.swift
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@ func toOptionViewType(_ data: [String: Any]) -> any OptionViewProtocol.Type {
if type.starts(with: "List|") {
return ListView.self
}
if type.starts(with: "Entries") {
return EntryView.self
}
if data["Children"] != nil {
return GroupView.self
}
Expand Down

0 comments on commit 6173b09

Please sign in to comment.