Skip to content

Commit a0ade96

Browse files
feat: font weight support
1 parent bdb4acf commit a0ade96

File tree

11 files changed

+106
-71
lines changed

11 files changed

+106
-71
lines changed

deps/breeze-ui.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ package("breeze-glfw")
33
set_urls("https://github.com/breeze-shell/glfw.git")
44
add_versions("2026.03.07+1", "a79c32a7d9ef4cd8a15b5f8ccbcdf9510c48da03")
55

6-
local BREEZE_UI_VER = "2026.03.29"
7-
local BREEZE_UI_HASH = "9be293083d9c501425b0da696d52caa807bea53f"
6+
local BREEZE_UI_VER = "2026.03.29+1"
7+
local BREEZE_UI_HASH = "9ced7b5735ad6cd18eb49d5cfebf88ea8bc9dab2"
88
local USE_LOCAL_BREEZE_UI = os.getenv("CI") ~= "true"
99
local BREEZE_UI_LOCAL_PATH = "../breeze-ui"
1010

src/shell/config.cc

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include "rfl/DefaultIfMissing.hpp"
1212
#include "rfl/json.hpp"
1313

14+
#include "breeze_ui/font.h"
1415
#include "utils.h"
1516
#include "windows.h"
1617
#include "wtr/watcher.hpp"
@@ -155,11 +156,10 @@ std::filesystem::path config::default_mono_font() {
155156
"consola.ttf";
156157
}
157158
void config::apply_fonts_to_nvg(NVGcontext *nvg) {
158-
nvgCreateFont(nvg, "main", font_path_main.string().c_str());
159-
nvgCreateFont(nvg, "fallback", font_path_fallback.string().c_str());
160-
nvgCreateFont(nvg, "monospace", font_path_monospace.string().c_str());
161-
nvgAddFallbackFont(nvg, "main", "fallback");
162-
nvgAddFallbackFont(nvg, "monospace", "main");
159+
ui::register_default_windows_font_suite(
160+
nvg, {.main_regular = {.path = font_path_main},
161+
.fallback_regular = {.path = font_path_fallback},
162+
.monospace_regular = {.path = font_path_monospace}});
163163
}
164164
void config::animated_float_conf::apply_to(ui::animated_color &anim,
165165
float delay) {
@@ -168,4 +168,4 @@ void config::animated_float_conf::apply_to(ui::animated_color &anim,
168168
apply_to(anim.b, delay);
169169
apply_to(anim.a, delay);
170170
}
171-
} // namespace mb_shell
171+
} // namespace mb_shell

src/shell/script/binding_qjs.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,12 +78,15 @@ template<> struct js_bind<mb_shell::js::breeze_ui::js_text_widget> {
7878
.base<mb_shell::js::breeze_ui::js_widget>()
7979
.property<&mb_shell::js::breeze_ui::js_text_widget::get_text, &mb_shell::js::breeze_ui::js_text_widget::set_text>("text")
8080
.property<&mb_shell::js::breeze_ui::js_text_widget::get_font_size, &mb_shell::js::breeze_ui::js_text_widget::set_font_size>("font_size")
81+
.property<&mb_shell::js::breeze_ui::js_text_widget::get_font_weight, &mb_shell::js::breeze_ui::js_text_widget::set_font_weight>("font_weight")
8182
.property<&mb_shell::js::breeze_ui::js_text_widget::get_max_width, &mb_shell::js::breeze_ui::js_text_widget::set_max_width>("max_width")
8283
.property<&mb_shell::js::breeze_ui::js_text_widget::get_color, &mb_shell::js::breeze_ui::js_text_widget::set_color>("color")
8384
.fun<&mb_shell::js::breeze_ui::js_text_widget::get_text>("get_text")
8485
.fun<&mb_shell::js::breeze_ui::js_text_widget::set_text>("set_text")
8586
.fun<&mb_shell::js::breeze_ui::js_text_widget::get_font_size>("get_font_size")
8687
.fun<&mb_shell::js::breeze_ui::js_text_widget::set_font_size>("set_font_size")
88+
.fun<&mb_shell::js::breeze_ui::js_text_widget::get_font_weight>("get_font_weight")
89+
.fun<&mb_shell::js::breeze_ui::js_text_widget::set_font_weight>("set_font_weight")
8790
.fun<&mb_shell::js::breeze_ui::js_text_widget::get_max_width>("get_max_width")
8891
.fun<&mb_shell::js::breeze_ui::js_text_widget::set_max_width>("set_max_width")
8992
.fun<&mb_shell::js::breeze_ui::js_text_widget::get_color>("get_color")
@@ -100,6 +103,7 @@ template<> struct js_bind<mb_shell::js::breeze_ui::js_textbox_widget> {
100103
.property<&mb_shell::js::breeze_ui::js_textbox_widget::get_text, &mb_shell::js::breeze_ui::js_textbox_widget::set_text>("text")
101104
.property<&mb_shell::js::breeze_ui::js_textbox_widget::get_placeholder, &mb_shell::js::breeze_ui::js_textbox_widget::set_placeholder>("placeholder")
102105
.property<&mb_shell::js::breeze_ui::js_textbox_widget::get_font_size, &mb_shell::js::breeze_ui::js_textbox_widget::set_font_size>("font_size")
106+
.property<&mb_shell::js::breeze_ui::js_textbox_widget::get_font_weight, &mb_shell::js::breeze_ui::js_textbox_widget::set_font_weight>("font_weight")
103107
.property<&mb_shell::js::breeze_ui::js_textbox_widget::get_padding_x, &mb_shell::js::breeze_ui::js_textbox_widget::set_padding_x>("padding_x")
104108
.property<&mb_shell::js::breeze_ui::js_textbox_widget::get_padding_y, &mb_shell::js::breeze_ui::js_textbox_widget::set_padding_y>("padding_y")
105109
.property<&mb_shell::js::breeze_ui::js_textbox_widget::get_border_radius, &mb_shell::js::breeze_ui::js_textbox_widget::set_border_radius>("border_radius")
@@ -131,6 +135,8 @@ template<> struct js_bind<mb_shell::js::breeze_ui::js_textbox_widget> {
131135
.fun<&mb_shell::js::breeze_ui::js_textbox_widget::set_placeholder>("set_placeholder")
132136
.fun<&mb_shell::js::breeze_ui::js_textbox_widget::get_font_size>("get_font_size")
133137
.fun<&mb_shell::js::breeze_ui::js_textbox_widget::set_font_size>("set_font_size")
138+
.fun<&mb_shell::js::breeze_ui::js_textbox_widget::get_font_weight>("get_font_weight")
139+
.fun<&mb_shell::js::breeze_ui::js_textbox_widget::set_font_weight>("set_font_weight")
134140
.fun<&mb_shell::js::breeze_ui::js_textbox_widget::get_padding_x>("get_padding_x")
135141
.fun<&mb_shell::js::breeze_ui::js_textbox_widget::set_padding_x>("set_padding_x")
136142
.fun<&mb_shell::js::breeze_ui::js_textbox_widget::get_padding_y>("get_padding_y")

src/shell/script/binding_types.d.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ export class js_text_widget extends js_widget {
5757
set text(value: string);
5858
get font_size(): number;
5959
set font_size(value: number);
60+
get font_weight(): number;
61+
set font_weight(value: number);
6062
get max_width(): number;
6163
set max_width(value: number);
6264
get color(): [number, number, number, number] | undefined;
@@ -71,6 +73,8 @@ export class js_textbox_widget extends js_widget {
7173
set placeholder(value: string);
7274
get font_size(): number;
7375
set font_size(value: number);
76+
get font_weight(): number;
77+
set font_weight(value: number);
7478
get padding_x(): number;
7579
set padding_x(value: number);
7680
get padding_y(): number;

src/shell/script/binding_types_breeze_ui.cc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ breeze_ui::js_widget::children() const {
117117

118118
IMPL_SIMPLE_PROP(breeze_ui::js_text_widget, ui::text_widget, text, std::string);
119119
IMPL_SIMPLE_PROP(breeze_ui::js_text_widget, ui::text_widget, font_size, int);
120+
IMPL_SIMPLE_PROP(breeze_ui::js_text_widget, ui::text_widget, font_weight, int);
120121
IMPL_SIMPLE_PROP(breeze_ui::js_text_widget, ui::text_widget, max_width, float);
121122
IMPL_COLOR_PROP(breeze_ui::js_text_widget, ui::text_widget, color);
122123
IMPL_SIMPLE_PROP(breeze_ui::js_textbox_widget, ui::textbox_widget, text,
@@ -125,6 +126,8 @@ IMPL_SIMPLE_PROP(breeze_ui::js_textbox_widget, ui::textbox_widget, placeholder,
125126
std::string);
126127
IMPL_SIMPLE_PROP(breeze_ui::js_textbox_widget, ui::textbox_widget, font_size,
127128
int);
129+
IMPL_SIMPLE_PROP(breeze_ui::js_textbox_widget, ui::textbox_widget, font_weight,
130+
int);
128131
IMPL_SIMPLE_PROP(breeze_ui::js_textbox_widget, ui::textbox_widget, padding_x,
129132
float);
130133
IMPL_SIMPLE_PROP(breeze_ui::js_textbox_widget, ui::textbox_widget, padding_y,

src/shell/script/binding_types_breeze_ui.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ struct breeze_ui {
6767
void set_text(std::string text);
6868
int get_font_size() const;
6969
void set_font_size(int size);
70+
int get_font_weight() const;
71+
void set_font_weight(int weight);
7072
float get_max_width() const;
7173
void set_max_width(float w);
7274
std::optional<std::tuple<float, float, float, float>> get_color() const;
@@ -82,6 +84,7 @@ struct breeze_ui {
8284
DEFINE_PROP(std::string, text)
8385
DEFINE_PROP(std::string, placeholder)
8486
DEFINE_PROP(int, font_size)
87+
DEFINE_PROP(int, font_weight)
8588
DEFINE_PROP(float, padding_x)
8689
DEFINE_PROP(float, padding_y)
8790
DEFINE_PROP(float, border_radius)

src/shell/script/script.js

Lines changed: 7 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,22 @@
1-
import { breeze } from "mshell";
2-
import { memo } from "react";
3-
1+
import { breeze } from "mshell";
2+
import { memo } from "react";
3+
44
export const Text = memo((({
55
children,
6-
fontSize = 14,
7-
maxWidth = -1,
8-
color,
9-
opacity
6+
fontSize = 14,
7+
maxWidth = -1,
8+
color,
9+
opacity,
10+
fontWeight = 400
1011
}: {
1112
children: string | number | Array<string | number>;
1213
fontSize?: number;
1314
maxWidth?: number;
1415
color?: string | number[];
1516
opacity?: number;
17+
fontWeight?: number;
1618
}) => {
17-
if (!color) color = breeze.is_light_theme() ? '#000000ff' : '#ffffffff'
19+
if (!color) color = breeze.is_light_theme() ? '#000000ff' : '#ffffffff'
1820
if (color instanceof Array)
1921
color = `#${color.slice(0, 4).map(c => c.toString(16).padStart(2, '0')).join('')}`;
2022
if (opacity !== undefined) {
@@ -30,6 +32,7 @@ export const Text = memo((({
3032
fontSize={fontSize}
3133
maxWidth={maxWidth}
3234
color={color}
33-
/>
34-
);
35-
}));
35+
fontWeight={fontWeight}
36+
/>
37+
);
38+
}));

src/shell/script/ts/src/config_page/pages/TestPage.tsx

Lines changed: 57 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,10 @@ const TestPage = memo(() => {
1212
const [focusState, setFocusState] = useState("none");
1313

1414
return (
15-
<flex gap={20}>
16-
<Text fontSize={24}>{t("test.title")}</Text>
17-
<flex gap={10}>
15+
<flex maxHeight={500} enableScrolling>
16+
<flex gap={20}>
17+
<Text fontSize={24}>{t("test.title")}</Text>
18+
{/* <flex gap={10}>
1819
<Button onClick={() => shell.breeze.crash_cpu_exception()}>
1920
<Text fontSize={16}>{t("test.cpu_exception_crash")}</Text>
2021
</Button>
@@ -28,50 +29,61 @@ const TestPage = memo(() => {
2829
>
2930
<Text fontSize={16}>{t("test.js_exception_crash")}</Text>
3031
</Button>
31-
</flex>
32+
</flex> */}
3233

33-
<flex gap={10}>
34-
<Text fontSize={16}>Textbox Test</Text>
35-
<textbox
36-
value={singleLineValue}
37-
placeholder="单行输入框"
38-
width={420}
39-
height={34}
40-
fontSize={14}
41-
onChange={setSingleLineValue}
42-
onFocus={() => setFocusState("single")}
43-
onBlur={() => setFocusState("none")}
44-
/>
45-
<textbox
46-
value={multiLineValue}
47-
placeholder="多行输入框"
48-
width={420}
49-
height={120}
50-
fontSize={14}
51-
backgroundColor="#000000ff"
52-
textColor="#ffffff"
53-
caretColor="#ff00ff"
54-
multiline
55-
onChange={setMultiLineValue}
56-
onFocus={() => setFocusState("multi")}
57-
onBlur={() => setFocusState("none")}
58-
/>
59-
<Text fontSize={13}>Focused: {focusState}</Text>
60-
<Text fontSize={13}>Single line value: {singleLineValue}</Text>
61-
</flex>
34+
<flex gap={10}>
35+
<Text fontSize={16}>Textbox Test</Text>
36+
<textbox
37+
value={singleLineValue}
38+
placeholder="单行输入框"
39+
width={420}
40+
height={34}
41+
fontSize={14}
42+
onChange={setSingleLineValue}
43+
onFocus={() => setFocusState("single")}
44+
onBlur={() => setFocusState("none")}
45+
/>
46+
<textbox
47+
value={multiLineValue}
48+
placeholder="多行输入框"
49+
width={420}
50+
height={120}
51+
fontSize={14}
52+
backgroundColor="#000000ff"
53+
textColor="#ffffff"
54+
caretColor="#ff00ff"
55+
multiline
56+
onChange={setMultiLineValue}
57+
onFocus={() => setFocusState("multi")}
58+
onBlur={() => setFocusState("none")}
59+
/>
60+
<Text fontSize={13} fontWeight={900}>Focused: {focusState}</Text>
61+
<Text fontSize={13}>Single line value: {singleLineValue}</Text>
62+
</flex>
6263

63-
<flex
64-
autoSize={false}
65-
width={100}
66-
height={200}
67-
alignItems="center"
68-
justifyContent="center"
69-
backgroundColor="#0000ff"
70-
>
71-
<flex backgroundColor="#ff0000">
72-
<Text fontSize={16} color="#ffffff">
73-
Hello,你好
74-
</Text>
64+
<flex>
65+
{
66+
[100, 200, 300, 400, 500, 600, 700, 800, 900].map(w => (
67+
<Text key={w} fontSize={16} fontWeight={w}>
68+
fw-{w} 你好世界
69+
</Text>
70+
))
71+
}
72+
</flex>
73+
74+
<flex
75+
autoSize={false}
76+
width={100}
77+
height={200}
78+
alignItems="center"
79+
justifyContent="center"
80+
backgroundColor="#0000ff"
81+
>
82+
<flex backgroundColor="#ff0000">
83+
<Text fontSize={16} color="#ffffff">
84+
Hello,你好
85+
</Text>
86+
</flex>
7587
</flex>
7688
</flex>
7789
</flex>

src/shell/script/ts/src/jsx.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ declare module 'react' {
4343
text: {
4444
text?: string[] | string;
4545
fontSize?: number;
46+
fontWeight?: number;
4647
color?: string;
4748
key?: string | number;
4849
animatedVars?: string[];
@@ -59,6 +60,7 @@ declare module 'react' {
5960
value?: string;
6061
placeholder?: string;
6162
fontSize?: number;
63+
fontWeight?: number;
6264
paddingX?: number;
6365
paddingY?: number;
6466
borderRadius?: number;

0 commit comments

Comments
 (0)