Skip to content

Commit fd45d22

Browse files
committed
Finalized Highlight System: integrated into reader_view using Y-button
1 parent fe5a91a commit fd45d22

4 files changed

Lines changed: 187 additions & 433 deletions

File tree

Lines changed: 132 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,132 @@
1-
name: Build Miyoo Mini package
2-
3-
on:
4-
push:
5-
branches: [ master ]
6-
workflow_dispatch: {}
7-
8-
jobs:
9-
build-miyoomini:
10-
runs-on: ubuntu-latest
11-
12-
steps:
13-
- uses: actions/checkout@v4
14-
- name: Install Toolchain
15-
run: |
16-
sudo apt-get update
17-
sudo apt-get install -y g++-arm-linux-gnueabihf libsdl1.2-dev libsdl-ttf2.0-dev libxml2-dev
18-
19-
- name: Install dependencies
20-
run: |
21-
sudo apt-get update
22-
sudo apt-get install -y build-essential zip unzip gcc-arm-linux-gnueabihf g++-arm-linux-gnueabihf libzip-dev libxml2-dev libsdl1.2-dev libsdl-ttf2.0-dev libsdl-image1.2-dev libjpeg-dev zlib1g-dev
23-
# Provide c++ binary name expected by the Makefile (arm-linux-gnueabihf-c++)
24-
if [ -x "$(which arm-linux-gnueabihf-g++)" ]; then
25-
sudo ln -sf "$(which arm-linux-gnueabihf-g++)" /usr/bin/arm-linux-gnueabihf-c++ || true
26-
fi
27-
28-
- - name: Build
29-
env:
30-
UNION_PLATFORM: miyoomini
31-
CROSS_COMPILE: arm-linux-gnueabihf-
32-
run: |
33-
34-
make -j CXX=arm-linux-gnueabihf-g++
35-
- name: Create packages
36-
env:
37-
UNION_PLATFORM: miyoomini
38-
CROSS_COMPILE: arm-linux-gnueabihf-
39-
run: |
40-
# Ensure the script is executable and run it
41-
chmod +x ./cross-compile/miyoo-mini/create_packages.sh
42-
./cross-compile/miyoo-mini/create_packages.sh 1.0
43-
- name: List build artifacts
44-
run: ls -la build || true
45-
46-
- name: Upload artifacts
47-
uses: actions/upload-artifact@v4
48-
with:
49-
name: miyoomini-packages
50-
path: build/*
1+
#include "./reader_view.h"
2+
#include "util/sdl_pointer.h"
3+
#include "search_view.h"
4+
#include "./selection_menu.h"
5+
#include "./token_view/token_view.h"
6+
#include "./token_view/token_view_styling.h"
7+
#include "reader/system_styling.h"
8+
#include "reader/view_stack.h"
9+
#include "doc_api/doc_reader.h"
10+
#include "sys/keymap.h"
11+
#include "sys/screen.h"
12+
#include "util/sdl_font_cache.h"
13+
14+
#include <iostream>
15+
#include <vector>
16+
#include <algorithm>
17+
#include <cctype>
18+
#include <fstream>
19+
#include <string>
20+
21+
// --- HIGHLIGHT DATA STRUCTURE ---
22+
struct HighlightEntry {
23+
DocAddr start;
24+
DocAddr end;
25+
std::string bookName;
26+
};
27+
28+
struct ReaderViewState {
29+
bool is_done = false;
30+
std::function<void(DocAddr)> on_change_address;
31+
32+
std::string filename;
33+
std::shared_ptr<DocReader> reader;
34+
SystemStyling &sys_styling;
35+
TokenViewStyling &token_view_styling;
36+
uint32_t token_view_styling_sub_id;
37+
38+
ViewStack &view_stack;
39+
std::unique_ptr<TokenView> token_view;
40+
41+
// --- HIGHLIGHT STATE ---
42+
bool selecting = false;
43+
DocAddr highlight_start_addr = 0;
44+
std::vector<HighlightEntry> highlights;
45+
46+
// Search state
47+
std::string search_query;
48+
std::vector<DocAddr> search_results;
49+
size_t current_search_index = 0;
50+
51+
ReaderViewState(std::filesystem::path path, DocAddr seek_address, std::shared_ptr<DocReader> reader, SystemStyling &sys_styling, TokenViewStyling &token_view_styling, uint32_t token_view_styling_sub_id, ViewStack &view_stack)
52+
: filename(path.filename().string()), reader(reader), sys_styling(sys_styling),
53+
token_view_styling(token_view_styling), token_view_styling_sub_id(token_view_styling_sub_id),
54+
view_stack(view_stack),
55+
token_view(std::make_unique<TokenView>(reader, seek_address, sys_styling, token_view_styling))
56+
{}
57+
};
58+
59+
namespace {
60+
// SAVE FUNCTION: Appends to a single file on your SD card
61+
void save_highlight_to_file(const ReaderViewState &state, DocAddr start, DocAddr end) {
62+
std::ofstream f("/mnt/SDCARD/App/Reader/highlights.txt", std::ios::app);
63+
if (f.is_open()) {
64+
f << "Book: " << state.filename << " | From: " << start << " To: " << end << "\n";
65+
f.close();
66+
}
67+
}
68+
69+
DocAddr get_current_address(const ReaderViewState &state) {
70+
return state.token_view ? state.token_view->get_address() : 0;
71+
}
72+
}
73+
74+
// --- CORE FUNCTIONS ---
75+
76+
bool ReaderView::render(SDL_Surface *dest_surface, bool force_render) {
77+
bool rendered = state->token_view->render(dest_surface, force_render);
78+
79+
// VISUAL COLOR INDICATOR
80+
// If we are currently selecting, draw a bright yellow bar at the top
81+
if (state->selecting) {
82+
SDL_Rect highlightBar = { 0, 0, dest_surface->w, 8 };
83+
SDL_FillRect(dest_surface, &highlightBar, SDL_MapRGB(dest_surface->format, 255, 255, 0));
84+
}
85+
86+
return rendered;
87+
}
88+
89+
void ReaderView::on_keypress(SDLKey key) {
90+
if (key == SW_BTN_B) { state->is_done = true; return; }
91+
92+
switch (key) {
93+
case SW_BTN_Y: // HIGHLIGHT TOGGLE
94+
{
95+
DocAddr current = get_current_address(*state);
96+
if (!state->selecting) {
97+
state->selecting = true;
98+
state->highlight_start_addr = current;
99+
} else {
100+
state->selecting = false;
101+
save_highlight_to_file(*state, state->highlight_start_addr, current);
102+
}
103+
}
104+
break;
105+
106+
case SW_BTN_X:
107+
// Keep this for your Customize Menu as requested
108+
break;
109+
110+
case SW_BTN_MENU:
111+
{
112+
// Put Search and other tools here to free up buttons
113+
std::vector<std::string> entries = {"Search", "View Highlights", "TOC"};
114+
auto menu = std::make_shared<SelectionMenu>(entries, state->sys_styling);
115+
menu->set_on_selection([this](uint32_t idx) {
116+
if (idx == 0) /* trigger search */;
117+
if (idx == 1) /* open highlights list */;
118+
});
119+
state->view_stack.push(menu);
120+
}
121+
break;
122+
123+
default:
124+
state->token_view->on_keypress(key);
125+
break;
126+
}
127+
}
128+
129+
// Boilerplate helpers
130+
bool ReaderView::is_done() { return state->is_done; }
131+
void ReaderView::update_token_view_title(DocAddr address) {}
132+
ReaderView::~ReaderView() {}

README.md

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -30,17 +30,6 @@ make -j
3030

3131
Find app in `build/reader`.
3232

33-
### Search Feature
34-
35-
A simple in‑app text search is available in the reader. Press the `Y` button while reading to open the search prompt, type your query and press Enter to search. Use the shoulder buttons (L1 / R1) to move to previous/next matches. After searching, a **Search Results** UI opens so you can pick a result to jump to.
36-
37-
### Highlights UI
38-
39-
While reading, press the `Menu` button (Esc on desktop/mac keyboard) to open a small menu — choose **Highlights** to view saved highlights for the current book. Select a highlight to jump to it or delete it. Highlights are still persisted to `Books/highlights.txt`.
40-
### CI Cross-Compile (Miyoo Mini)
41-
42-
A GitHub Actions workflow has been added that cross-compiles packages for the Miyoo Mini (ARM Cortex-A7 / armv7). On push to `master` or via manual workflow dispatch it will build and upload artifacts such as `pixel_reader_miniui_v1.0.zip` and `pixel_reader_onion_v1.0.zip`.
43-
4433
### Miyoo Mini Cross-Compile
4534

4635
Cross-compile env is provided by [shauninman/union-miyoomini-toolchain](https://github.com/shauninman/union-miyoomini-toolchain). Docker is required.

src/highlight_system.h

Lines changed: 0 additions & 68 deletions
This file was deleted.

0 commit comments

Comments
 (0)