Pulp 1.88.0
Cross-platform audio plugin framework
Loading...
Searching...
No Matches
appearance_tracker.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <pulp/view/theme.hpp>
4#include <functional>
5#include <string>
6#include <memory>
7
8namespace pulp::view {
9
11enum class Appearance { light, dark };
12
17enum class ThemeMode { system, light, dark };
18
25public:
28
31
34 bool poll();
35
38 void on_appearance_changed(std::function<void(Appearance)> callback);
39
41 void lock(Appearance appearance);
42
44 void unlock();
45
47 bool is_locked() const { return locked_; }
48
50 Appearance locked_appearance() const { return locked_appearance_; }
51
52private:
53 Appearance last_known_ = Appearance::dark;
54 bool locked_ = false;
55 Appearance locked_appearance_ = Appearance::dark;
56 std::function<void(Appearance)> callback_;
57
59 static Appearance detect_system_appearance();
60};
61
65public:
67
69 void set_theme_pair(Theme light_theme, Theme dark_theme);
70
72 const Theme& active_theme() const;
73
75 void lock_theme(Theme theme);
76
78 void lock_appearance(Appearance appearance);
79
81 void unlock();
82
88 ThemeMode mode() const;
89
91 bool is_locked() const { return theme_locked_ || tracker_.is_locked(); }
92
94 AppearanceTracker& tracker() { return tracker_; }
95 const AppearanceTracker& tracker() const { return tracker_; }
96
98 bool poll();
99
101 void on_theme_changed(std::function<void(const Theme&)> callback);
102
103private:
104 AppearanceTracker tracker_;
105 Theme light_theme_;
106 Theme dark_theme_;
107 Theme locked_theme_;
108 bool theme_locked_ = false;
109 std::function<void(const Theme&)> theme_callback_;
110};
111
112} // namespace pulp::view
Tracks OS-level appearance (light/dark mode) and auto-switches themes.
Definition appearance_tracker.hpp:24
bool is_locked() const
Check if appearance is locked.
Definition appearance_tracker.hpp:47
void unlock()
Unlock and resume tracking OS appearance.
void lock(Appearance appearance)
Lock to a specific appearance, ignoring OS changes.
void on_appearance_changed(std::function< void(Appearance)> callback)
Register a callback for appearance changes.
Appearance current_appearance() const
Get current system appearance.
Appearance locked_appearance() const
Get the locked appearance (only valid when is_locked() is true).
Definition appearance_tracker.hpp:50
bool poll()
Poll for appearance changes.
void set_mode(ThemeMode m)
User-facing theme preference.
const AppearanceTracker & tracker() const
Definition appearance_tracker.hpp:95
bool poll()
Poll for changes. Returns true if the active theme changed.
AppearanceTracker & tracker()
Access the underlying tracker for direct appearance queries.
Definition appearance_tracker.hpp:94
bool is_locked() const
Check if a specific theme is locked.
Definition appearance_tracker.hpp:91
ThemeMode mode() const
const Theme & active_theme() const
Get the active theme based on current appearance (or locked theme).
void unlock()
Unlock and resume automatic theme switching.
void on_theme_changed(std::function< void(const Theme &)> callback)
Register a callback for when the active theme changes.
void lock_theme(Theme theme)
Lock to a specific theme, ignoring appearance tracking.
void set_theme_pair(Theme light_theme, Theme dark_theme)
Set the theme pair for automatic appearance-based switching.
void lock_appearance(Appearance appearance)
Lock to an appearance (light/dark) but still use the theme pair.
Hover-cursor tracking for platform window hosts.
Definition fwd.hpp:27
ThemeMode
User-facing theme preference.
Definition appearance_tracker.hpp:17
@ system
Definition appearance_tracker.hpp:17
Appearance
System appearance mode.
Definition appearance_tracker.hpp:11
@ light
Definition appearance_tracker.hpp:11
@ dark
Definition appearance_tracker.hpp:11
@ m
Definition input_events.hpp:40
Definition theme.hpp:32