ClockWidget | iOS 14 Clock Widget | Date Time Utils library
kandi X-RAY | ClockWidget Summary
kandi X-RAY | ClockWidget Summary
iOS 14 Clock Widget. Clock Face :
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of ClockWidget
ClockWidget Key Features
ClockWidget Examples and Code Snippets
Community Discussions
Trending Discussions on ClockWidget
QUESTION
I need to create a widget that is used to pick a time. QTimeEdit widget doesn't seem intuitive or a good design. So I decided to create a time picker similar to the time picker in smartphones.
I managed to create the clock and click that makes the pointer (something similar to the pointer in the image) move to the currently clicked position (note: it's not perfect, it still looks bad). I would like to have help with making the inner clock
Here is my code:
...ANSWER
Answered 2021-Mar-30 at 17:31Disclaimer: I will not explain the cause of the error but the code I provide I think should give a clear explanation of the errors.
The logic is to calculate the position of the centers of each small circle, and use the exinscribed rectangle to take it as a base to draw the text and check if the point where you click is close to the texts.
QUESTION
using Cairo ;
using Gtk ;
using GLib ;
public class ClockWidget : DrawingArea {
private Time time ;
private int minute_offset ;
private bool dragging ;
public signal void time_changed (int hour, int minute) ;
public ClockWidget () {
add_events (Gdk.EventMask.BUTTON_PRESS_MASK
| Gdk.EventMask.BUTTON_RELEASE_MASK
| Gdk.EventMask.POINTER_MOTION_MASK);
update () ;
Timeout.add (1000, update) ;
set_size_request (100, 100) ;
}
public override bool draw (Cairo.Context cr) {
int y = get_allocated_height () / 2 ;
int x = get_allocated_width () / 2 ;
var radius = double.min (get_allocated_width () / 2,
get_allocated_height () / 2) - 5 ;
// clock back
cr.arc (x, y, radius, 0, 2 * 3.14) ;
cr.set_source_rgb (1, 1, 1) ;
cr.fill_preserve () ;
cr.set_source_rgb (0, 0, 0) ;
cr.stroke () ;
// clock ticks
for (int i = 0; i < 12; i++) {
int inset ;
cr.save () ;
if (i % 3 == 0) {
inset = (int) (0.2 * radius) ;
} else {
inset = (int) (0.1 * radius) ;
cr.set_line_width (0.5 * cr.get_line_width ()) ;
}
cr.move_to (x + (radius - inset) * Math.cos (i * Math.PI / 6),
y + (radius - inset) * Math.sin (i * Math.PI / 6));
cr.line_to (x + radius * Math.cos (i * Math.PI / 6),
y + radius * Math.sin (i * Math.PI / 6));
cr.stroke ();
cr.restore ();
}
// clock hands
var hours = this.time.hour ;
var minutes = this.time.minute + this.minute_offset ;
var seconds = this.time.second ;
/* hour hand: the hour hand is rotated 30 degrees (pi/6r) per hour + 1/2 a degree (pi/360r) per minute */
cr.save () ;
cr.set_line_width (2.5 * cr.get_line_width ()) ;
cr.move_to (x, y) ;
cr.line_to (x + radius / 2 * Math.sin (Math.PI / 6 * hours
+ Math.PI / 360 * minutes),
y + radius / 2 * -Math.cos (Math.PI / 6 * hours
+ Math.PI / 360 * minutes));
cr.stroke ();
cr.restore ();
// minute hand:
// the minute hand is rotated 6 degrees (pi/30 r) per minute
cr.move_to (x, y);
cr.line_to (x + radius * 0.75 * Math.sin (Math.PI / 30 * minutes),
y + radius * 0.75 * -Math.cos (Math.PI / 30 * minutes));
cr.stroke ();
// seconds hand:
// operates identically to the minute hand
cr.save ();
cr.set_source_rgb (1, 0, 0); // red
cr.move_to (x, y);
cr.line_to (x + radius * 0.7 * Math.sin (Math.PI / 30 * seconds),
y + radius * 0.7 * -Math.cos (Math.PI / 30 * seconds));
cr.stroke ();
cr.restore ();
return false ;
}
public override bool button_press_event (Gdk.EventButton event) {
var minutes = this.time.minute + this.minute_offset;
// From
// http://mathworld.wolfram.com/Point-LineDistance2-Dimensional.html
var px = event.x - get_allocated_width () / 2;
var py = get_allocated_height () / 2 - event.y;
var lx = Math.sin (Math.PI / 30 * minutes);
var ly = Math.cos (Math.PI / 30 * minutes);
var u = lx * px + ly * py;
// on opposite side of origin
if (u < 0) {
return false;
}
var d2 = Math.pow (px - u * lx, 2) + Math.pow (py - u * ly, 2);
if (d2 < 25) { // 5 pixels away from the line
this.dragging = true;
print ("got minute hand\n");
}
return false;
}
public override bool button_release_event (Gdk.EventButton event) {
if (this.dragging) {
this.dragging = false;
emit_time_changed_signal ((int) event.x, (int) event.y);
}
return false;
}
public override bool motion_notify_event (Gdk.EventMotion event) {
if (this.dragging) {
emit_time_changed_signal ((int) event.x, (int) event.y);
}
return false;
}
private void emit_time_changed_signal (int x, int y) {
// decode the minute hand
// normalise the coordinates around the origin
x -= get_allocated_width () / 2;
y -= get_allocated_height () / 2;
// phi is a bearing from north clockwise, use the same geometry as
// we did to position the minute hand originally
var phi = Math.atan2 (x, -y);
if (phi < 0) {
phi += Math.PI * 2;
}
var hour = this.time.hour;
var minute = (int) (phi * 30 / Math.PI);
// update the offset
this.minute_offset = minute - this.time.minute;
redraw_canvas ();
time_changed (hour, minute);
}
private bool update () {
// update the time
this.time = Time.local (time_t ());
redraw_canvas ();
return true; // keep running this event
}
private void redraw_canvas () {
var window = get_window ();
if (null == window) {
return;
}
var region = window.get_clip_region ();
// redraw the cairo canvas completely by exposing it
window.invalidate_region (region, true);
window.process_updates (true);
}
static int main (string[] args) {
Gtk.init (ref args);
var window = new Window ();
var clock = new ClockWidget ();
window.add (clock);
window.destroy.connect (Gtk.main_quit);
window.show_all ();
Gtk.main ();
return 0;
}
}
...ANSWER
Answered 2021-Mar-14 at 12:45You need to link against libm
which is the library which provides the pow()
function, which you’re using.
Typically this is achieved by passing -lm
in your linker flags. I can’t give a more concrete answer because you haven’t said what build system you’re using.
QUESTION
I have a program running fine on one device (laptop) but when trying to run the same code on another device (workstation), I have an error which does not occur on my laptop.
Setting colors in the .kv file works fine on my laptop but running on my workstation I have this error:
...ANSWER
Answered 2020-Aug-19 at 19:20Try adding:
QUESTION
I am new to flutter and decided to build a simple timer app, that counts the number of seconds that have gone by since it's start and it ends up showing the wrong time. The timer starts off with 0, then increments to 1 and, from there on out it seems as if it is increasing exponentially.
main.dart
...ANSWER
Answered 2020-Feb-20 at 13:13You are currently defining new Timer
s every second. Each of these timers is incrementing the number of seconds.
You want to define your Timer
only once and outside of the build
method.
- Create a Timer in
initState
- Update state every second
- Display the seconds in the
build
method - Cancel the
Timer
indispose
Here's an example:
QUESTION
I'm developing a multiple page Kivy app that I want to have a clock widget in several pages. I was able to implement it on every page as an individual instance but i wanted to change it to a reusable widget but it's not updating during the intervals
This is the .kv file implementation
...ANSWER
Answered 2020-Jan-26 at 06:05The problem is that the ClockWidget created in the build method is different from the ClockWidget created as a child of BoxLayout in the .kv, in your case only the Clock only calls the update_clock method of the first.
On the other hand I see it unnecessary to create a new StringProperty in ClockWidget since it is a Label and has the property "text", and another strange thing is that a Label has another Label as a child.
Considering the above, the solution is:
QUESTION
I apologize if the answer to this question is simple, but I'm just beginning to learn UWP and really can't figure out a solution on my own.
I have a UserControl
called ClockWidget
included in a Canvas
in my main page. When running the application, the control (containing only a TextBlock
) has the correct size, but the text does not seem to be rendered.
MainPage.xaml
...ANSWER
Answered 2019-Oct-30 at 15:50So, as it had to, it boiled down to an incredibly stupid mistake. Inside my ClockWidget.xaml.cs
code-behind, I overwrote the default constructor, but accidentally deleted the InitializeComponent()
call. So obviously, the components were never initialized...
Thank you all for your help and support!
QUESTION
I am building an app that will need to show a timer inside a Text(), with duration of 60 seconds, when the screen opens, the timer starts from 0 to 60 seconds automatically inside a Text().
I tried to use Time Builder lib but I have no ideia how to get the time (minutes and seconds) running to put inside the Text().
...ANSWER
Answered 2019-May-07 at 00:04From 0 to 60 upon a button click.
QUESTION
I am attempting to determine the size of a SWT view so I can layout the widgets correctly in a plugin. I am running on Eclipse Neon with Java 8.
The code I am using follows:
...ANSWER
Answered 2018-Jul-13 at 13:40Sizes haven't been determined when createPartControl
is called.
There will be a Resize event when the size is set.
Use getClientArea()
on the main Composite
to get the size of the view area.
QUESTION
I am trying to rotate a JLabel 90 degrees that shows the current time 90 degrees. After doing some research, most people have recommended using Graphics2D and AffineTransform. This almost works, but when the minute in the time is updated, the new digit appears to merge with the old digit.
This does not happen for the seconds. Does anybody have any idea how to fix this issue or have an alternate solution?
Driver class:
...ANSWER
Answered 2018-May-12 at 22:22A few things jump out at me:
- I wouldn't use a
JLabel
for this purpose, it's a complicate component, starting with aJPanel
and simply painting the text would be simpler. In my testing it was very hard to get the sizing hints to work correctly when the graphics context was rotated. - You're not managing the component's "new" sizing hints, this could be an issue when coupled with more complex layouts, as the width of the component should now be the height and visa-versa
- I'd recommend the key bindings API over
KeyListener
- Swing is NOT thread safe, updating the UI from outside the context of the UI could produce any number of issues; instead of using a
Thread
, you should be using a SwingTimer
, and since you probably really only want to update the seconds, running it at a much slower speed. See Concurrency in Swing and How to Use Swing Timers for more details - And
Calendar
andDate
are effectively deprecated. See Standard Calendar for more details
For example...
QUESTION
I have an ng-repeater which successfully gets the values from the controller through an angular class. However I have a double value which I'm trying to assign to the styling of the div. Is it possible to assign a returned ng-repeat value to the style property of the div?
...ANSWER
Answered 2018-Mar-23 at 10:00try this:
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install ClockWidget
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page