Fix sensors

Signed-off-by: Vasiliy Doylov <nekodevelopper@gmail.com>
This commit is contained in:
Vasiliy Doylov 2025-03-02 13:45:28 +03:00
parent 2e158e3c97
commit a130ca830b
Signed by: NekoCWD
GPG key ID: B7BE22D44474A582
3 changed files with 74 additions and 48 deletions

View file

@ -1,5 +1,7 @@
class TheCatTools.GUI.BoubleBar : Gtk.DrawingArea, Gtk.Orientable {
public float value { get; set; default = 0; }
public double value { get; set; default = 0; }
public Gtk.Adjustment adjustment { get; set; default = new Gtk.Adjustment (0, -90, 90, 0, 0, 0); }
public Gtk.Orientation orientation { get; set; }
construct {
set_draw_func (draw);
@ -7,54 +9,55 @@ class TheCatTools.GUI.BoubleBar : Gtk.DrawingArea, Gtk.Orientable {
add_css_class ("bubble-bar");
notify["orientation"].connect (orientation_changed);
orientation_changed ();
vexpand = true;
}
void orientation_changed () {
message ("Request orientation");
var orientation = orientation == Gtk.Orientation.HORIZONTAL;
width_request = -1;
width_request = orientation ? -1 : 60;
height_request = orientation ? 60 : -1;
}
void set_color_rgba (Cairo.Context cr, Gdk.RGBA color) {
cr.set_source_rgba (color.red, color.green, color.blue, color.alpha);
}
double get_adjusted_value () {
var res = value;
if (res > 90)
res = 180 - res;
if (res < -90)
res = -180 + res;
return res.clamp (adjustment.lower, adjustment.upper);
}
void draw_meow (Cairo.Context cr, int width, int height) {
var gap = 2;
var radius = width / 2 - gap / 2;
var val = get_adjusted_value ();
var position = radius + (height - 2 * radius) * (val - adjustment.lower) / (adjustment.upper - adjustment.lower);
set_color_rgba (cr, get_color ());
cr.arc (radius, position, radius, 0, Math.PI * 2);
cr.fill ();
cr.move_to (0, 0);
cr.line_to (width, height);
cr.set_line_width (3);
cr.stroke ();
cr.move_to (10, 10);
cr.show_text ("Meow");
}
void draw (Gtk.DrawingArea self, Cairo.Context cr, int width, int height) {
message ("Draw %dx%d", width, height);
if (orientation == Gtk.Orientation.HORIZONTAL) {
width_request = 60;
cr.rotate (Math.PI / 2);
cr.translate (0, -width);
draw_meow (cr, height, width);
} else {
height_request = 60;
draw_meow (cr, width, height);
}
}
void draw (Gtk.DrawingArea drawing_area, Cairo.Context cr, int width, int height) {
message ("Draw %dx%d", width, height);
var fg_c = get_color ();
var line_width = height / 120;
var gap = line_width;;
var radius = width / 2 - gap;
var value = (value * -1) + 90;
if (value > 180)
value = 360 - value;
if (value < 0)
value *= -1;
var position = radius + (height - radius * 2) * value / 180;
message ("%f = %f", value, position);
// Bubble
cr.set_source_rgba (fg_c.red, fg_c.green, fg_c.blue, fg_c.alpha);
cr.arc (width / 2, position, radius, 0, 2 * Math.PI);
cr.fill ();
cr.set_source_rgba (fg_c.red, fg_c.green, fg_c.blue, fg_c.alpha);
// Lines
var bc = get_style_context ().get_color ();
cr.set_source_rgba (fg_c.red, fg_c.green, fg_c.blue, fg_c.alpha);
cr.set_line_width (line_width);
cr.move_to (gap, position);
cr.rel_line_to (radius * 2, 0);
cr.stroke ();
cr.set_source_rgba (fg_c.red, fg_c.green, fg_c.blue, fg_c.alpha);
// -O-
cr.move_to (0, height / 2);
cr.rel_line_to (gap, 0);
cr.rel_move_to (radius * 2, 0);
cr.rel_line_to (gap, 0);
// Up line
cr.move_to (0, height / 2 - radius - gap);
cr.rel_line_to (width, 0);
// Down line
cr.move_to (0, height / 2 + radius + gap);
cr.rel_line_to (width, 0);
cr.stroke ();
}
}

View file

@ -1,5 +1,5 @@
.bubble-bar {
color: var(--accent-color);
color: var(--accent-bg-color);
background-color: var(--view-bg-color);
border-radius: 20px;
}

View file

@ -22,9 +22,32 @@ template $TheCatToolsWindow: Adw.ApplicationWindow {
orientation: vertical;
Adw.Clamp {
CenterBox {
Grid {
orientation: horizontal;
column-spacing: 24;
[start]
$TheCatToolsGUIBoubleBar bar {}
$TheCatToolsGUIBoubleBar hbar {
orientation: horizontal;
layout {
column: 2;
row: 1;
}
halign: fill;
hexpand: true;
valign: end;
vexpand: false;
}
[start]
$TheCatToolsGUIBoubleBar vbar {
orientation: vertical;
layout {
column: 1;
row: 1;
}
}
}
}
};