49 lines
1.5 KiB
Java
49 lines
1.5 KiB
Java
package io.gitlab.jfronny.inceptum.gtk.control;
|
|
|
|
import io.gitlab.jfronny.commons.LazySupplier;
|
|
import io.gitlab.jfronny.inceptum.gtk.GtkMain;
|
|
import io.gitlab.jfronny.inceptum.gtk.util.I18n;
|
|
import org.gnome.gtk.*;
|
|
import org.jetbrains.annotations.PropertyKey;
|
|
|
|
import java.io.InputStream;
|
|
import java.util.function.Supplier;
|
|
|
|
public class ILabel extends Label {
|
|
private static Supplier<CssProvider> provider = new LazySupplier<>(() -> {
|
|
CssProvider provider = new CssProvider();
|
|
try (InputStream is = GtkMain.class.getClassLoader().getResourceAsStream("inceptum.css")) {
|
|
provider.loadFromData(is.readAllBytes());
|
|
} catch (Throwable t) {
|
|
throw new RuntimeException(t);
|
|
}
|
|
return provider;
|
|
});
|
|
|
|
public static void theme(Label label, Mode mode) {
|
|
switch (mode) {
|
|
case HEADING -> label.addCssClass("heading");
|
|
case SUBTITLE -> {
|
|
label.addCssClass("jf-subtitle");
|
|
label.styleContext.addProvider(provider.get(), Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION);
|
|
}
|
|
case NORMAL -> {}
|
|
}
|
|
}
|
|
|
|
public ILabel(@PropertyKey(resourceBundle = I18n.BUNDLE) String str, Object... args) {
|
|
this(str, Mode.NORMAL, args);
|
|
}
|
|
|
|
public ILabel(@PropertyKey(resourceBundle = I18n.BUNDLE) String str, Mode mode, Object... args) {
|
|
super(I18n.get(str, args));
|
|
theme(this, mode);
|
|
}
|
|
|
|
public enum Mode {
|
|
NORMAL,
|
|
HEADING,
|
|
SUBTITLE
|
|
}
|
|
}
|