mirror of
https://github.com/FelixKratz/SketchyBar
synced 2025-02-17 04:58:28 +00:00
fix some remaining problems with the new slider component
This commit is contained in:
parent
24395f943a
commit
5a59ebb2da
4 changed files with 24 additions and 14 deletions
|
@ -667,6 +667,7 @@ static void bar_item_clear_pointers(struct bar_item* bar_item) {
|
|||
text_clear_pointers(&bar_item->icon);
|
||||
text_clear_pointers(&bar_item->label);
|
||||
background_clear_pointers(&bar_item->background);
|
||||
slider_clear_pointers(&bar_item->slider);
|
||||
}
|
||||
|
||||
void bar_item_inherit_from_item(struct bar_item* bar_item, struct bar_item* ancestor) {
|
||||
|
@ -689,6 +690,12 @@ void bar_item_inherit_from_item(struct bar_item* bar_item, struct bar_item* ance
|
|||
text_set_string(&bar_item->icon, string_copy(ancestor->icon.string), true);
|
||||
text_set_string(&bar_item->label, string_copy(ancestor->label.string), true);
|
||||
|
||||
text_set_font(&bar_item->slider.knob,
|
||||
string_copy(ancestor->slider.knob.font_name), true);
|
||||
|
||||
text_set_string(&bar_item->slider.knob,
|
||||
string_copy(ancestor->slider.knob.string), true);
|
||||
|
||||
if (ancestor->script)
|
||||
bar_item_set_script(bar_item, string_copy(ancestor->script));
|
||||
if (ancestor->click_script)
|
||||
|
|
|
@ -159,11 +159,7 @@ EVENT_CALLBACK(EVENT_HANDLER_MOUSE_DRAGGED) {
|
|||
wid,
|
||||
adid );
|
||||
|
||||
if (!bar_item || bar_item->type == BAR_COMPONENT_GROUP) {
|
||||
bar_item = bar_manager_get_item_by_point(&g_bar_manager, point, adid);
|
||||
}
|
||||
|
||||
if (!bar_item->has_slider) {
|
||||
if (!bar_item || !bar_item->has_slider) {
|
||||
CFRelease(context);
|
||||
return EVENT_SUCCESS;
|
||||
}
|
||||
|
|
24
src/slider.c
24
src/slider.c
|
@ -23,6 +23,7 @@ static bool slider_set_foreground_color(struct slider* slider, uint32_t color) {
|
|||
void slider_init(struct slider* slider) {
|
||||
slider->percentage = 0;
|
||||
slider->prev_drag_percentage = NO_DRAG;
|
||||
slider->background.bounds.size.width = 100;
|
||||
|
||||
slider->foreground_color = 0xff0000ff;
|
||||
text_init(&slider->knob);
|
||||
|
@ -32,6 +33,12 @@ void slider_init(struct slider* slider) {
|
|||
background_set_color(&slider->foreground, slider->foreground_color);
|
||||
}
|
||||
|
||||
void slider_clear_pointers(struct slider* slider) {
|
||||
background_clear_pointers(&slider->background);
|
||||
background_clear_pointers(&slider->foreground);
|
||||
text_clear_pointers(&slider->knob);
|
||||
}
|
||||
|
||||
void slider_setup(struct slider* slider, uint32_t width) {
|
||||
slider->background.bounds.size.width = width;
|
||||
background_set_enabled(&slider->background, true);
|
||||
|
@ -39,10 +46,7 @@ void slider_setup(struct slider* slider, uint32_t width) {
|
|||
}
|
||||
|
||||
uint32_t slider_get_length(struct slider* slider) {
|
||||
int32_t knob_width = slider->knob.bounds.size.width
|
||||
+ slider->knob.bounds.origin.x;
|
||||
|
||||
return max(slider->background.bounds.size.width, knob_width);
|
||||
return slider->background.bounds.size.width;
|
||||
}
|
||||
|
||||
void slider_calculate_bounds(struct slider* slider, uint32_t x, uint32_t y) {
|
||||
|
@ -59,11 +63,13 @@ void slider_calculate_bounds(struct slider* slider, uint32_t x, uint32_t y) {
|
|||
* ((float)slider->percentage)/100.f,
|
||||
slider->background.bounds.size.height);
|
||||
|
||||
text_calculate_bounds(&slider->knob,
|
||||
x + ((float)slider->percentage)/100.f
|
||||
* slider->background.bounds.size.width
|
||||
- slider->knob.bounds.size.width / 2.,
|
||||
y );
|
||||
uint32_t knob_offset = max(min(((float)slider->percentage)/100.f
|
||||
* slider->background.bounds.size.width,
|
||||
slider->background.bounds.size.width
|
||||
- (slider->knob.bounds.size.width / 2.f + 1.f)
|
||||
- slider->knob.bounds.size.width / 2.), 0.f);
|
||||
|
||||
text_calculate_bounds(&slider->knob, x + knob_offset, y);
|
||||
}
|
||||
|
||||
void slider_draw(struct slider* slider, CGContextRef context) {
|
||||
|
|
|
@ -17,6 +17,7 @@ struct slider {
|
|||
};
|
||||
|
||||
void slider_init(struct slider* slider);
|
||||
void slider_clear_pointers(struct slider* slider);
|
||||
void slider_setup(struct slider* slider, uint32_t width);
|
||||
void slider_calculate_bounds(struct slider* slider, uint32_t x, uint32_t y);
|
||||
void slider_draw(struct slider* slider, CGContextRef context);
|
||||
|
|
Loading…
Add table
Reference in a new issue