Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion engines/fcitx5-hallelujah
6 changes: 3 additions & 3 deletions patches/hallelujah.patch
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 02daeea..bcc8397 100644
index 7ffcf34..a57a061 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -12,8 +12,6 @@ option(ENABLE_TEST "Build Test" On)
option(BUILD_DATA "Build data" On)

find_package(Gettext REQUIRED)
-find_package(Fcitx5Core 5.0.0 REQUIRED)
-find_package(Fcitx5Core 5.1.9 REQUIRED)
-find_package(Fcitx5Module REQUIRED COMPONENTS Spell TestFrontend)
find_package(PkgConfig REQUIRED)

Expand Down Expand Up @@ -75,7 +75,7 @@ index dcbd627..6b0f00d 100644
+ \"
+)
diff --git a/src/hallelujah.h b/src/hallelujah.h
index 115ad79..c35bd7e 100644
index ace78e7..2a371b8 100644
--- a/src/hallelujah.h
+++ b/src/hallelujah.h
@@ -71,7 +71,6 @@ private:
Expand Down
2 changes: 2 additions & 0 deletions uipanel/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ add_library(KeyboardUI STATIC
keyboardui.swift
Key.swift
Keyboard.swift
Candidate.swift
CandidateBar.swift
)
set_target_properties(KeyboardUI PROPERTIES Swift_MODULE_NAME KeyboardUI)
target_compile_options(KeyboardUI PUBLIC "$<$<COMPILE_LANGUAGE:Swift>:-cxx-interoperability-mode=default>")
Expand Down
34 changes: 34 additions & 0 deletions uipanel/Candidate.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import UIKit

class CandidateView: UICollectionViewCell {
static let identifier = "CandidateView"

let wordLabel: UILabel = {
let label = UILabel()
label.textAlignment = .center
label.font = UIFont.systemFont(ofSize: 18)
label.translatesAutoresizingMaskIntoConstraints = false
return label
}()

override init(frame: CGRect) {
super.init(frame: frame)
contentView.addSubview(wordLabel)
setupConstraints()
}

required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}

private func setupConstraints() {
NSLayoutConstraint.activate([
wordLabel.centerXAnchor.constraint(equalTo: contentView.centerXAnchor),
wordLabel.centerYAnchor.constraint(equalTo: contentView.centerYAnchor),
])
}

func configure(with word: String) {
wordLabel.text = word
}
}
92 changes: 92 additions & 0 deletions uipanel/CandidateBar.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
import UIKit

class CandidateCollectionView: UIView {

var words = [String]()

private var collectionView: UICollectionView!

override init(frame: CGRect) {
super.init(frame: frame)
setupCollectionView()
setupConstraints()
}

required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}

private func setupCollectionView() {
let layout = UICollectionViewFlowLayout()
layout.scrollDirection = .horizontal

collectionView = UICollectionView(frame: .zero, collectionViewLayout: layout)
collectionView.translatesAutoresizingMaskIntoConstraints = false
collectionView.backgroundColor = UIColor.clear
collectionView.delegate = self
collectionView.dataSource = self
collectionView.register(
CandidateView.self, forCellWithReuseIdentifier: CandidateView.identifier)

addSubview(collectionView)
}

private func setupConstraints() {
NSLayoutConstraint.activate([
collectionView.leadingAnchor.constraint(equalTo: leadingAnchor),
collectionView.trailingAnchor.constraint(equalTo: trailingAnchor),
collectionView.topAnchor.constraint(equalTo: topAnchor),
collectionView.bottomAnchor.constraint(equalTo: bottomAnchor),
collectionView.heightAnchor.constraint(equalToConstant: 35),
])
}

func updateCandidates(_ candidates: [String]) {
words = candidates
collectionView.reloadData()
}
}

extension CandidateCollectionView: UICollectionViewDataSource {
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int)
-> Int
{
return words.count
}

func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath)
-> UICollectionViewCell
{
guard
let cell = collectionView.dequeueReusableCell(
withReuseIdentifier: CandidateView.identifier, for: indexPath) as? CandidateView
else {
return UICollectionViewCell()
}
cell.configure(with: words[indexPath.item])
return cell
}
}

extension CandidateCollectionView: UICollectionViewDelegate {
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
}
}

extension CandidateCollectionView: UICollectionViewDelegateFlowLayout {
func collectionView(
_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout,
sizeForItemAt indexPath: IndexPath
) -> CGSize {
let word = words[indexPath.item]
let width = word.size(withAttributes: [.font: UIFont.systemFont(ofSize: 18)]).width + 20
return CGSize(width: width, height: 35)
}

func collectionView(
_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout,
minimumLineSpacingForSectionAt section: Int
) -> CGFloat {
return 10
}
}
10 changes: 10 additions & 0 deletions uipanel/keyboardui.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,14 @@ import OSLog
import UIKit

let logger = Logger(subsystem: "org.fcitx.Fcitx5", category: "FcitxLog")
let candidateCollectionView = CandidateCollectionView()

private func setupMainLayout(_ client: FcitxProtocol) {
let mainStackView = client.getView()

candidateCollectionView.translatesAutoresizingMaskIntoConstraints = false
mainStackView.addArrangedSubview(candidateCollectionView)

let keyboardView = Keyboard(client)
keyboardView.translatesAutoresizingMaskIntoConstraints = false
mainStackView.addArrangedSubview(keyboardView)
Expand All @@ -21,3 +25,9 @@ public func showKeyboardAsync(_ clientPtr: UnsafeMutableRawPointer) {
setupMainLayout(client)
}
}

public func setCandidatesAsync(_ candidates: [String]) {
DispatchQueue.main.async {
candidateCollectionView.updateCandidates(candidates)
}
}
8 changes: 5 additions & 3 deletions uipanel/uipanel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,17 @@ void UIPanel::update(UserInterfaceComponent component,
case UserInterfaceComponent::InputPanel: {
const InputPanel &inputPanel = inputContext->inputPanel();
int size = 0;
auto candidates = swift::Array<swift::String>::init();
if (const auto &list = inputPanel.candidateList()) {
size = list->size();
for (int i = 0; i < size; i++) {
const auto &candidate = list->candidate(i);
FCITX_INFO()
<< instance_->outputFilter(inputContext, candidate.text())
.toString();
candidates.append(
instance_->outputFilter(inputContext, candidate.text())
.toString());
}
}
KeyboardUI::setCandidatesAsync(candidates);
break;
}
case UserInterfaceComponent::StatusArea:
Expand Down