nixos-configs/modules/ags/gtk4/widget/styled-box.ts

35 lines
882 B
TypeScript
Raw Normal View History

2024-12-31 23:54:29 -05:00
import { astalify, Gtk } from 'astal/gtk4';
import { property, register } from 'astal';
@register({ GTypeName: 'StyledBox' })
class StyledBoxClass extends Gtk.Box {
declare private _css: string | undefined;
declare private _provider: Gtk.CssProvider | undefined;
@property(String)
get css(): string | undefined {
return this._css;
}
set css(value: string) {
if (!this._provider) {
this._provider = new Gtk.CssProvider();
this.get_style_context().add_provider(
this._provider,
Gtk.STYLE_PROVIDER_PRIORITY_USER,
);
}
this._css = value;
this._provider.load_from_string(value);
}
}
export type StyledBox = StyledBoxClass;
export const StyledBox = astalify<
StyledBoxClass,
Gtk.Box.ConstructorProps & { css: string }
>(StyledBoxClass);