Compare commits

...

1 Commits

Author SHA1 Message Date
Christian Kaiser d277b98521 Add a font weight dropdown to the font selector 2025-08-03 02:42:11 -03:00
3 changed files with 46 additions and 0 deletions

View File

@ -790,6 +790,17 @@ empty_fonts = No system fonts were found
antialias = Antialias
hinting = Hinting
ligatures = Ligatures
font_weight = Font Weight
font_weight_100 = 100 - Thin
font_weight_200 = 200 - Extra Light
font_weight_300 = 300 - Light
font_weight_400 = 400 - Normal
font_weight_500 = 500 - Medium
font_weight_600 = 600 - Semi Bold
font_weight_700 = 700 - Bold
font_weight_800 = 800 - Extra Bold
font_weight_900 = 900 - Black
font_weight_1000 = 1000 - Extra Black
[frame_combo]
all_frames = All frames

View File

@ -2,6 +2,18 @@
<!-- Copyright (C) 2025 by Igara Studio S.A. -->
<gui>
<vbox id="font_style">
<combobox id="weight" tooltip="@.font_weight" expansive="true">
<listitem value="100" text="@.font_weight_100" />
<listitem value="200" text="@.font_weight_200" />
<listitem value="300" text="@.font_weight_300" />
<listitem value="400" text="@.font_weight_400" />
<listitem value="500" text="@.font_weight_500" />
<listitem value="600" text="@.font_weight_600" />
<listitem value="700" text="@.font_weight_700" />
<listitem value="800" text="@.font_weight_800" />
<listitem value="900" text="@.font_weight_900" />
<listitem value="1000" text="@.font_weight_1000" />
</combobox>
<check id="antialias" text="@.antialias" />
<check id="hinting" text="@.hinting" />
<separator horizontal="true" />

View File

@ -461,6 +461,17 @@ void FontEntry::onStyleItemClick(ButtonSet::Item* item)
content.antialias()->setSelected(m_info.antialias());
content.ligatures()->setSelected(m_info.ligatures());
content.hinting()->setSelected(m_info.hinting() == text::FontHinting::Normal);
content.weight()->setValue(std::to_string(static_cast<int>(m_info.style().weight())));
// HACK: I was unable to click on the items that were outside the bounds of the popupwindow,
// so this restricts the size of the internal combobox window to the popupwindow bounds.
// TODO: There has to be a better way.
content.weight()->OpenListBox.connect([&] {
gfx::Size maxSize = content.sizeHint();
maxSize.h -= content.weight()->sizeHint().h;
content.weight()->getWindowWidget()->setMaxSize(maxSize);
content.weight()->getWindowWidget()->remapWindow();
});
auto flagsChange = [this, &content]() {
FontInfo::Flags flags = FontInfo::Flags::None;
@ -480,9 +491,21 @@ void FontEntry::onStyleItemClick(ButtonSet::Item* item)
From::Hinting);
};
auto weightChange = [this, &content]() {
auto weight = static_cast<text::FontStyle::Weight>(
std::atoi(content.weight()->getValue().c_str()));
text::FontStyle style(weight, m_info.style().width(), m_info.style().slant());
setInfo(FontInfo(m_info, m_info.size(), style, m_info.flags(), m_info.hinting()),
From::Style);
m_style.getItem(0)->setSelected(m_info.style().weight() >=
text::FontStyle::Weight::SemiBold);
};
content.antialias()->Click.connect(flagsChange);
content.ligatures()->Click.connect(flagsChange);
content.hinting()->Click.connect(hintingChange);
content.weight()->Change.connect(weightChange);
popup.addChild(&content);
popup.remapWindow();