Squashed 'libraries/ZWidget/' changes from cecd34301d..924b8e0e78

924b8e0e78 Fix scroll size issue
f0344ed99b Add option to hide scrollbar when no scrolling is to be had
f7b01d6625 Remove stray sdl
214d098353 Theme role improvements
82d0431ca5 Textedit highlight now follows theme
373ab3f4ca Added hex Colorf alias
5ea6d5a62a Reduced duplicate code
a92e045b18 Simplified theme
d076c9991c Expanded example
e4556c97df Named colors
6d9300c742 Fix COM thread error
6499e5c523 Add null pointer checks
f9d5724210 Fix x11 backend locking up Implement raw mouse input support (XInput 2.0) Fix x11 DPI scaling
4a86fb5056 XInitThreads must be called when using vulkan
8095090774 Add DPI scale to X11 backend
02fb328172 Mute a bunch of warnings
f13c745a63 Fix typo
5689bf5edd Merge in changes from SurrealEngine Use C++20 Make SDL2 optional

git-subtree-dir: libraries/ZWidget
git-subtree-split: 924b8e0e786093708c0d73419a347f8e6ffe55d6
This commit is contained in:
Marcus Minhorst 2025-08-26 22:05:52 -04:00
commit 87689ccb5f
27 changed files with 880 additions and 524 deletions

View file

@ -17,6 +17,21 @@ public:
return { r * s, g * s, b * s, a * s };
}
static Colorf fromRgba(uint32_t rgba)
{
return fromRgba8(
0xff & rgba>>24,
0xff & rgba>>16,
0xff & rgba>>8,
0xff & rgba
);
}
static Colorf fromRgb(uint32_t rgb)
{
return fromRgba(rgb<<8 | 0xff);
}
uint32_t toBgra8() const
{
uint32_t cr = (int)(std::max(std::min(r * 255.0f, 255.0f), 0.0f));

View file

@ -212,7 +212,7 @@ private:
Colorf cursor_color;
std::string::size_type sel_start = 0, sel_end = 0;
Colorf sel_foreground, sel_background = Colorf::fromRgba8(153, 201, 239);
Colorf sel_foreground, sel_background;
std::string text;
std::vector<SpanObject> objects;

View file

@ -55,7 +55,23 @@ public:
class WidgetTheme
{
struct SimpleTheme {
const Colorf bgMain; // background
const Colorf fgMain; //
const Colorf bgLight; // headers / inputs
const Colorf fgLight; //
const Colorf bgAction; // interactive elements
const Colorf fgAction; //
const Colorf bgHover; // hover / highlight
const Colorf fgHover; //
const Colorf bgActive; // click
const Colorf fgActive; //
const Colorf border; // around elements
const Colorf divider; // between elements
};
public:
WidgetTheme() {}
WidgetTheme(const struct SimpleTheme &theme);
virtual ~WidgetTheme() = default;
WidgetStyle* RegisterStyle(std::unique_ptr<WidgetStyle> widgetStyle, const std::string& widgetClass);

View file

@ -83,6 +83,11 @@ private:
SpanLayout layout;
Rect box;
bool invalidated = true;
Line(const TextEdit *self)
{
layout.SetSelectionColors(self->selectionFG, self->selectionBG);
}
};
struct ivec2
@ -96,9 +101,10 @@ private:
bool operator!=(const ivec2& b) const { return x != b.x || y != b.y; }
};
Colorf selectionBG, selectionFG;
Scrollbar* vert_scrollbar;
Timer* timer = nullptr;
std::vector<Line> lines = { Line() };
std::vector<Line> lines = { Line{this} };
ivec2 cursor_pos = { 0, 0 };
int max_length = -1;
bool mouse_selecting = false;